API 루트 수준에서 x-amazon-apigateway-gateway-responses
확장을 사용하여 OpenAPI에서 게이트웨이 응답을 사용자 지정할 수 있습니다. 다음 OpenAPI 정의는 MISSING_AUTHENTICATION_TOKEN
유형의 GatewayResponse를 사용자 지정하는 예를 보여줍니다.
"x-amazon-apigateway-gateway-responses": { "MISSING_AUTHENTICATION_TOKEN": { "statusCode": 404, "responseParameters": { "gatewayresponse.header.x-request-path": "method.input.params.petId", "gatewayresponse.header.x-request-query": "method.input.params.q", "gatewayresponse.header.Access-Control-Allow-Origin": "'a.b.c'", "gatewayresponse.header.x-request-header": "method.input.params.Accept" }, "responseTemplates": { "application/json": "{\n \"message\": $context.error.messageString,\n \"type\": \"$context.error.responseType\",\n \"stage\": \"$context.stage\",\n \"resourcePath\": \"$context.resourcePath\",\n \"stageVariables.a\": \"$stageVariables.a\",\n \"statusCode\": \"'404'\"\n}" } }
이 예제의 사용자 지정은 상태 코드를 기본값(403
)에서 404
로 변경합니다. 또한 application/json
미디어 유형에 대한 헤더 파라미터 네 개와 본문 매핑 템플릿 하나를 추가합니다.