x-amazon-apigateway-gateway-responses.responseTemplates 对象 - Amazon API Gateway

x-amazon-apigateway-gateway-responses.responseTemplates 对象

对于给定的网关响应,将 GatewayResponse 映射模板定义为采用键/值对的字符串到字符串映射。对于每个键/值对,“键”指内容类型。例如“application/json”,而“值”指简单变量替换的字符串化映射模板。GatewayResponse 映射模板不由 Velocity 模板语言 (VTL) 引擎处理。

属性
属性名称 类型 说明
content-type string

GatewayResponse 正文映射模板,仅支持简单变量替换以自定义网关响应正文。

x-amazon-apigateway-gateway-responses.responseTemplates 示例

下面的 OpenAPI 扩展示例显示了一个 GatewayResponse 映射模板,用于将 API Gateway 生成的错误响应自定义为特定于应用程序的格式。

"responseTemplates": { "application/json": "{ \"message\": $context.error.messageString, \"type\":$context.error.responseType, \"statusCode\": '488' }" }

下面的 OpenAPI 扩展示例显示了一个 GatewayResponse 映射模板,用于使用静态错误消息覆盖 API Gateway 生成的错误响应。

"responseTemplates": { "application/json": "{ \"message\": 'API-specific errors' }" }