gpt4 book ai didi

aws-api-gateway - 指定的映射表达式参数无效

转载 作者:行者123 更新时间:2023-12-04 18:21:18 28 4
gpt4 key购买 nike

我正在尝试为 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 ,所以这对我来说真的很困惑。任何想法该怎么做?文档似乎在很多方面都缺乏,因此很难用它解决很多问题。

最佳答案

您是否尝试过定义 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'"
}
}
}
}
}
}
}
}

API Gateway 要求方法请求参数为 defined before being referenced

关于aws-api-gateway - 指定的映射表达式参数无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49158921/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com