我有一个使用带有API网关扩展的 Swagger 2.0定义创建的API网关.
我覆盖了默认的API网关响应,例如:
x-amazon-apigateway-gateway-responses:
BAD_REQUEST_BODY:
statusCode: 400
responseTemplates:
application/json: |
{
"error": {
"code": 400,
"stage": "$context.stage",
"request": "$context.requestId",
"message": "$context.error.message"
}
}
Run Code Online (Sandbox Code Playgroud)
在$context上述有效载荷来自API网关变量.
我的API中的示例资源/方法如下所示(始终是LAMBDA_PROXY集成):
paths:
/test:
post:
parameters:
- in: body
name: Test
required: true
schema:
$ref: "#/definitions/Test"
responses:
201:
description: Created
400:
description: Bad Request
401:
description: Unauthorized
403:
description: Forbidden
x-amazon-apigateway-integration:
uri: >-
arn:aws:apigateway:${region}:lambda:path/2015-03-31/functions/${lambda}/invocations
type: aws_proxy
httpMethod: POST
credentials: "${credentials}"
passthroughBehavior: never
Run Code Online (Sandbox Code Playgroud)
使用相应的请求有效负载定义:
definitions:
Test:
type: …Run Code Online (Sandbox Code Playgroud)