Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid mapping expression parameter specified

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.

like image 314
RomaValcer Avatar asked Mar 07 '18 18:03

RomaValcer


1 Answers

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

like image 161
TravisAGengler Avatar answered Oct 23 '22 19:10

TravisAGengler