7

As part of our continuous delivery pipeline I'm going to deploy AWS API Gateway APIs.

The easiest way to do this is using Amazon API Gateway Importer that can create or update Amazon API Gateway APIs from a Swagger representation.

AWS provides API Gateway Extensions to Swagger. With these extensions you can provide request/response templates in your Swagger definition. Below is an example json snippet with a API Gateway Extension to Swagger:

"x-amazon-apigateway-integration": {
      "responses": {
        "default": {
          "statusCode": "200",
          "responseParameters": {
            "method.response.header.Access-Control-Allow-Origin": "'*'"
          },
          "responseTemplates": {
            "application/json": "#set($inputRoot = $input.path('$'))\r\n[\r\n#foreach($elem in $inputRoot)\r\n    {\r\n      \"id\" : \"$elem.id\",\r\n      \"login\" : \"$elem.login\"\r\n    }#if($foreach.hasNext),#end\r\n        \r\n#end\r\n  ]\r\n"
          }
        }
      },
      "uri": "http://www.example.com/api/users",
      "httpMethod": "GET",
      "requestParameters": {
        "integration.request.querystring.page": "method.request.querystring.page",
        "integration.request.header.x-auth-token": "method.request.header.x-auth-token",
        "integration.request.querystring.size": "method.request.querystring.size"
      },
      "type": "http"
    }
  }

Editing Swagger definitions becomes error-prone since you need to inline AWS API Gateway templates.

The Swagger website lists a lot of tools for generating client/server stubs from Swagger definitions or for generating Swagger definitions from API code.

I'm looking for a tool similar to Troposphere. The idea is that I can define my API say in Python which then will generate a JSON or yaml file. The benefit is I can separate AWS API Gateway request/response templates and then pull them in to the resulting Swagger definition.

Does anyone know of any tool that can be useful?

medvedev1088
  • 3,645
  • 24
  • 42
  • 3
    API Gateway team - I don't know of any tools but I'm going to bring this back and discuss with the team. We might want to have something in the console to make this easier, just something that generates the extensions dynamically from a form or something. – jackko Apr 04 '16 at 21:55
  • @medvedev1088 have you found an alternative to raw editing of AWS API Gateway templates in Swagger definitions? – xtx Aug 23 '16 at 13:45
  • @xtx we use yaml instead of json. This makes editing API Gateway templates somewhat easier. Our templates are not big so it's bearable. Another alternative is to use a template engine such as Freemarker which will allow separating API Gateway templates and including them in the main Swagger template. – medvedev1088 Aug 24 '16 at 11:23

0 Answers0