

# x-amazon-apigateway-gateway-responses.responseTemplates 对象
<a name="api-gateway-swagger-extensions-gateway-responses.responseTemplates"></a>

对于给定的网关响应，将 [GatewayResponse](https://docs.aws.amazon.com/apigateway/latest/api/API_GatewayResponse.html) 映射模板定义为采用键/值对的字符串到字符串映射。对于每个键/值对，“键”指内容类型。例如“application/json”，而“值”指简单变量替换的字符串化映射模板。`GatewayResponse` 映射模板不由 [Velocity 模板语言 (VTL)](https://velocity.apache.org/engine/devel/vtl-reference.html) 引擎处理。


| 属性名称 | 类型 | 说明 | 
| --- | --- | --- | 
| content-type | string |  `GatewayResponse` 正文映射模板，仅支持简单变量替换以自定义网关响应正文。  | 

## x-amazon-apigateway-gateway-responses.responseTemplates 示例
<a name="api-gateway-swagger-extensions-gateway-responses.responseTemplates-example"></a>

 下面的 OpenAPI 扩展示例显示了一个 [GatewayResponse](https://docs.aws.amazon.com/apigateway/latest/api/API_GatewayResponse.html) 映射模板，用于将 API Gateway 生成的错误响应自定义为特定于应用程序的格式。

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

 下面的 OpenAPI 扩展示例显示了一个 [GatewayResponse](https://docs.aws.amazon.com/apigateway/latest/api/API_GatewayResponse.html) 映射模板，用于使用静态错误消息覆盖 API Gateway 生成的错误响应。

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