I am trying to write a Swagger config for the AWS API Gateway deployment, and came up with this for a sample (mostly copied from the documentation):
{
"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'"
}
}
}
}
}
}
}
}
But the problem is that
aws apigateway import-rest-api --body 'file://deploy/api.json' --region eu-west-1
Outputs the following:
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]
That part is taken directly from the documentation, so this is really confusing to me. Any ideas what to do? Documentation seems lacking in many ways, so it is hard to solve many problems with it.
Have you tried defining version
and vendor
as parameters to the method?
{
"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 requires method request parameters to be defined before being referenced
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With