【问题标题】:How is it possible to set the response Header Content-Type to application/xml in APIGateway/Swagger如何在 APIGateway/Swagger 中将响应 Header Content-Type 设置为 application/xml
【发布时间】:2020-04-01 15:33:50
【问题描述】:

如何配置 Swagger/APIGateway 以将响应 Header 属性 Content-Type 设置为“application/xml”,以便使用和生成 xml 的 APIGateway Lambda GET 端点?

目前响应的Header Content-Type值为“application/json”

我试图这样指定它:-

"/v1/XXXXXXX": {
  "get": {
    "produces": [
      "application/xml"
    ],
    "responses": {
      "200": {
        "description": "Meter reading data",
        "schema": { ........ }
      }
    },
    "x-amazon-apigateway-integration": {
      "responses": {
        "default": {
          "statusCode": "200",
          "responseParameters": {
            "method.response.header.Content-Type": "'application/xml'"
          }
        }
      }
    }

错误如下:-

Errors found during import: Unable to put integration response on 'GET' for resource at path '/v1/XXXXXXXXX': Invalid mapping expression specified: Validation Result: warnings : [], errors : [Invalid mapping expression parameter specified: method.response.header.Content-Type] 

非常感谢,

山姆

【问题讨论】:

    标签: swagger aws-api-gateway


    【解决方案1】:

    Content-Type 应添加为映射模板。 您将其设置在“responseParameters”下,这是不正确的。

    在任一下设置“应用程序/xml”:

    1. "x-amazon-apigateway-integration":"requestTemplates"
    2. "x-amazon-apigateway-integration":"responses": "responseTemplates"

    【讨论】:

      猜你喜欢
      • 2013-04-07
      • 2023-04-07
      • 1970-01-01
      • 1970-01-01
      • 2010-12-08
      • 1970-01-01
      • 2012-07-08
      • 2012-05-22
      • 1970-01-01
      相关资源
      最近更新 更多