【发布时间】:2018-04-04 03:09:57
【问题描述】:
我正在尝试为 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'"
}
}
}
}
}
}
}
}
但问题是
aws apigateway import-rest-api --body 'file://deploy/api.json' --region eu-west-1
输出以下内容:
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]
那部分直接取自documentation,所以这真的让我很困惑。有什么想法该怎么做?文档似乎在很多方面都缺乏,因此很难用它来解决很多问题。
【问题讨论】:
-
如果对解决问题有帮助请标记答案
标签: aws-api-gateway