OpenAPI 정의를 사용하여 메서드에 API 키를 요구할 수 있습니다.
각 메서드에 대해 해당 메서드를 간접 호출할 때 API 키가 필요한 보안 요구 사항 객체를 생성합니다. 그런 다음 보안 정의에서 api_key
를 정의합니다. 메서드에서 API 키를 사용량 계획에 추가하려면 관련 사용량 계획에 대한 API 키를 사용하여 UsagePlanKey를 생성합니다.
다음 예시에서는 API를 생성하고 POST
및 GET
메서드에 API 키가 필요합니다.
{ "swagger" : "2.0", "info" : { "version" : "2024-03-14T20:20:12Z", "title" : "keys-api" }, "basePath" : "/v1", "schemes" : [ "https" ], "paths" : { "/pets" : { "get" : { "responses" : { }, "security" : [ { "api_key" : [ ] } ], "x-amazon-apigateway-integration" : { "type" : "http_proxy", "httpMethod" : "GET", "uri" : "http://petstore-demo-endpoint.execute-api.com/petstore/pets/", "passthroughBehavior" : "when_no_match" } }, "post" : { "responses" : { }, "security" : [ { "api_key" : [ ] } ], "x-amazon-apigateway-integration" : { "type" : "http_proxy", "httpMethod" : "GET", "uri" : "http://petstore-demo-endpoint.execute-api.com/petstore/pets/", "passthroughBehavior" : "when_no_match" } } } }, "securityDefinitions" : { "api_key" : { "type" : "apiKey", "name" : "x-api-key", "in" : "header" } } }