指定的映射表达式参数无效

Rom*_*cer 5 aws-api-gateway

我正在尝试为AWS API Gateway部署编写Swagger配置,并为示例提供了此配置(主要从文档中复制):

{
  "swagger": "2.0",
  "info": {
    "description": "desc",
    "title": "TestAPI",
    "version": "1.0"
  },
  "schemes": [
    "https"
  ],
  "paths": {
    "/": {
      "get": {
        "consumes": [
          "application/json"
        ],
        "produces": [
          "application/json"
        ],
        "responses": {
          "200": {
            "description": "test",
            "headers": {
              "Content-type": {
                "type": "string"
              }
            }
          }
        },
        "x-amazon-apigateway-integration" : {
          "type" : "aws",
          "uri" : "[REDACTED]",
          "credentials" : "[REDACTED]",
          "httpMethod" : "POST",
          "requestTemplates" : {
            "application/json" : "#set ($root=$input.path('$')) { \"stage\": \"$root.name\", \"user-id\": \"$root.key\" }"
          },
          "requestParameters" : {
            "integration.request.querystring.stage" : "method.request.querystring.version",
            "integration.request.querystring.provider" : "method.request.querystring.vendor"
          },
          "responses" : {
            "2\\d{2}" : {
              "statusCode" : "200",
              "responseParameters" : {
                "method.response.header.requestId" : "integration.response.header.cid"
              },
              "responseTemplates" : {
                "application/json" : "#set ($root=$input.path('$')) { \"stage\": \"$root.name\", \"user-id\": \"$root.key\" }"
              }
            },
            "302" : {
              "statusCode" : "302",
              "responseParameters" : {
                "method.response.header.Location" : "integration.response.body.redirect.url"
              }
            },
            "default" : {
              "statusCode" : "400",
              "responseParameters" : {
                "method.response.header.test-method-response-header" : "'static value'"
              }
            }
          }
        }
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

但是问题是

aws apigateway import-rest-api --body 'file://deploy/api.json' --region eu-west-1 
Run Code Online (Sandbox Code Playgroud)

输出以下内容:

An error occurred (BadRequestException) when calling the ImportRestApi operation: Errors found during import:
    Unable to put integration on 'GET' for resource at path '/': Invalid mapping expression specified: Validation Result: warnings : [], errors : [Invalid mapping expression parameter specified: method.request.querystring.version]
Run Code Online (Sandbox Code Playgroud)

该部分直接取自文档,所以这确实让我感到困惑。有什么想法怎么办?似乎在许多方面都缺乏文档,因此很难解决许多问题。

Tra*_*ler 7

您是否尝试过将versionvendor作为方法的参数?

{
  "swagger": "2.0",
  "info": {
    "description": "desc",
    "title": "TestAPI",
    "version": "1.0"
  },
  "schemes": [
    "https"
  ],
  "paths": {
    "/": {
      "get": {
        "consumes": [
          "application/json"
        ],
        "produces": [
          "application/json"
        ],
        "parameters" : [
            {
                "name" : "version",
                "in" : "query",
                "required" : true,
                "type" : "string"
                "description" : "The version requested"
            },          
            {
                "name" : "vendor",
                "in" : "query",
                "required" : true,
                "type" : "string"
                "description" : "The vendor being queried"
            }
        ],
        "responses": {
          "200": {
            "description": "test",
            "headers": {
              "Content-type": {
                "type": "string"
              }
            }
          }
        },
        "x-amazon-apigateway-integration" : {
          "type" : "aws",
          "uri" : "[REDACTED]",
          "credentials" : "[REDACTED]",
          "httpMethod" : "POST",
          "requestTemplates" : {
            "application/json" : "#set ($root=$input.path('$')) { \"stage\": \"$root.name\", \"user-id\": \"$root.key\" }"
          },
          "requestParameters" : {
            "integration.request.querystring.stage" : "method.request.querystring.version",
            "integration.request.querystring.provider" : "method.request.querystring.vendor"
          },
          "responses" : {
            "2\\d{2}" : {
              "statusCode" : "200",
              "responseParameters" : {
                "method.response.header.requestId" : "integration.response.header.cid"
              },
              "responseTemplates" : {
                "application/json" : "#set ($root=$input.path('$')) { \"stage\": \"$root.name\", \"user-id\": \"$root.key\" }"
              }
            },
            "302" : {
              "statusCode" : "302",
              "responseParameters" : {
                "method.response.header.Location" : "integration.response.body.redirect.url"
              }
            },
            "default" : {
              "statusCode" : "400",
              "responseParameters" : {
                "method.response.header.test-method-response-header" : "'static value'"
              }
            }
          }
        }
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

API Gateway 需要在被引用之前定义方法请求参数