Generate swagger json definition for AWS API Gateway

时间:2016-04-04 17:42:37

标签: amazon-web-services swagger aws-api-gateway swagger-editor troposphere

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?

0 个答案:

没有答案