swagger-ui-aws-apigateway

1.0.1 • Public • Published

Swagger UI AWS API Gateway

This module is branched from swagger-ui-express. It allows you to serve auto-generated swagger-ui generated API docs from the AWS API Gateway. It uses Lambda functions to generate the API docs based on a swagger.json or swagger.yaml file. The result is living documentation for your API hosted on your AWS API Gateway.

Swagger version is pulled from npm module swagger-ui-dist. Please use a lock file or specify the version of swagger-ui-dist you want to ensure it is consistent across environments.

You may be also interested in:

  • swagger tools: Various tools, including swagger editor, swagger code gen etc.

Usage

Install using npm:

$ npm install swagger-ui-aws-apigateway

Configure your API Gateway:

  • Create a resource of type "proxy resource"
  • Create a method ANY
  • Create a lambda function of type "LAMBDA_PROXY"

In your AWS lambda function, include this package as follows:

const swaggerUi = require('swagger-ui-aws-apigateway');
const fs = require('fs');
 
// read your yaml file and initialize
const swaggerDocument = fs.readFileSync('./interface/service_interface.yaml');
var swaggerHandler = swaggerUi.setup(swaggerDocument);
 
// call the swagger api doc in your handler
 
exports.handler = (event, context, callback) => {
 
   if (event.path.includes("/api-docs")) {
        console.log("Got request to the api docs.");
        swaggerHandler(event, context, callback);
        return;
    }
 
    // ... your other code ...
 
}

Restrictions

Currently the path in the url must be named "api-docs".

Requirements

  • Node v0.10.32 or above

Dependents (0)

Package Sidebar

Install

npm i swagger-ui-aws-apigateway

Weekly Downloads

4

Version

1.0.1

License

MIT

Unpacked Size

13.8 kB

Total Files

4

Last publish

Collaborators

  • klauslochmann