기본 요청 확인이 설정된 샘플 API의 OpenAPI 정의 - Amazon API Gateway

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

기본 요청 확인이 설정된 샘플 API의 OpenAPI 정의

다음 OpenAPI 정의는 요청 확인이 활성화된 샘플 API를 정의합니다. PetStore API는 API의 하위 집합입니다. POST 메서드를 노출시켜 pets 모음에 pet을 추가하고, GET 메서드를 노출시켜 지정된 유형으로 pet을 쿼리합니다.

x-amazon-apigateway-request-validators 맵에 API 수준의 두 가지 요청 검사기가 선언되어 있습니다. params-only 검사기는 해당 API에서 활성화되어 있고 GET 메서드에 의해 상속됩니다. API Gateway는 이 검사기를 사용하여 필수 쿼리 파라미터(q1)가 수신 요청에 포함되었으며 공백이 아님을 확인할 수 있습니다. all 검사기는 POST 메서드에서 활성화됩니다. 이 검사기는 필수 헤더 파라미터(h1)가 설정되었으며 공백이 아님을 확인합니다. 또한 이는 페이로드 형식이 지정된 RequestBodyModel을 준수하는지 확인합니다. 일치하는 콘텐츠 유형이 없는 경우 요청 확인이 수행되지 않습니다. 모델을 사용하여 본문을 확인할 때 일치하는 콘텐츠 유형이 없으면 요청 확인이 수행되지 않습니다. 콘텐츠 유형에 관계없이 동일한 모델을 사용하려면 $default을(를) 키로 지정합니다.

이 모델에서는 입력 JSON 객체가 name, typeprice 속성을 포함해야 합니다. name 속성은 임의의 문자열이 될 수 있으며, type은 지정된 열거 필드(["dog", "cat", "fish"]) 중 하나여야 하고, price는 25~500 사이여야 합니다. id 파라미터는 필요하지 않습니다.

OpenAPI 2.0
{ "swagger": "2.0", "info": { "title": "ReqValidators Sample", "version": "1.0.0" }, "schemes": [ "https" ], "basePath": "/v1", "produces": [ "application/json" ], "x-amazon-apigateway-request-validators" : { "all" : { "validateRequestBody" : true, "validateRequestParameters" : true }, "params-only" : { "validateRequestBody" : false, "validateRequestParameters" : true } }, "x-amazon-apigateway-request-validator" : "params-only", "paths": { "/validation": { "post": { "x-amazon-apigateway-request-validator" : "all", "parameters": [ { "in": "header", "name": "h1", "required": true }, { "in": "body", "name": "RequestBodyModel", "required": true, "schema": { "$ref": "#/definitions/RequestBodyModel" } } ], "responses": { "200": { "schema": { "type": "array", "items": { "$ref": "#/definitions/Error" } }, "headers" : { "test-method-response-header" : { "type" : "string" } } } }, "security" : [{ "api_key" : [] }], "x-amazon-apigateway-auth" : { "type" : "none" }, "x-amazon-apigateway-integration" : { "type" : "http", "uri" : "http://petstore-demo-endpoint.execute-api.com/petstore/pets", "httpMethod" : "POST", "requestParameters": { "integration.request.header.custom_h1": "method.request.header.h1" }, "responses" : { "2\\d{2}" : { "statusCode" : "200" }, "default" : { "statusCode" : "400", "responseParameters" : { "method.response.header.test-method-response-header" : "'static value'" }, "responseTemplates" : { "application/json" : "json 400 response template", "application/xml" : "xml 400 response template" } } } } }, "get": { "parameters": [ { "name": "q1", "in": "query", "required": true } ], "responses": { "200": { "schema": { "type": "array", "items": { "$ref": "#/definitions/Error" } }, "headers" : { "test-method-response-header" : { "type" : "string" } } } }, "security" : [{ "api_key" : [] }], "x-amazon-apigateway-auth" : { "type" : "none" }, "x-amazon-apigateway-integration" : { "type" : "http", "uri" : "http://petstore-demo-endpoint.execute-api.com/petstore/pets", "httpMethod" : "GET", "requestParameters": { "integration.request.querystring.type": "method.request.querystring.q1" }, "responses" : { "2\\d{2}" : { "statusCode" : "200" }, "default" : { "statusCode" : "400", "responseParameters" : { "method.response.header.test-method-response-header" : "'static value'" }, "responseTemplates" : { "application/json" : "json 400 response template", "application/xml" : "xml 400 response template" } } } } } } }, "definitions": { "RequestBodyModel": { "type": "object", "properties": { "id": { "type": "integer" }, "type": { "type": "string", "enum": ["dog", "cat", "fish"] }, "name": { "type": "string" }, "price": { "type": "number", "minimum": 25, "maximum": 500 } }, "required": ["type", "name", "price"] }, "Error": { "type": "object", "properties": { } } } }