Nir Adler
Piece by Piece

Follow

Piece by Piece

Follow
Export Swagger documentation file from AWS ApiGateway

Export Swagger documentation file from AWS ApiGateway

Nir Adler's photo
Nir Adler
·Apr 23, 2019·
Play this article

When developing a serverless function over AWS lambda and APIGateway, it is very useful to export the documentation as a swagger file, and create API documentation to your API.

to make the process smooth I created an npm module apigateway-export-tool that does exactly that.

npx apigateway-export-tool list
npx apigateway-export-tool docs -i [api-id] --stageName [stage]

I'm using the aws-sdk module to export the API documentation by api-id and stage-name.

you can also use the module with NodeJS like this:

const { getExportAndSave,setAwsConfig } = require("apigateway-export-tool");
setAwsConfig({ region: "us-east-1" });

(async function() {
  const params = {
    exportType, // String ("oas30", "swagger")
    restApiId, // String
    stageName, // String
    parameters: {
      extensions // String ("postman", "integrations", "integrations", "authorizers")
    }
  };
  const filePath = "./";
  const file = await getExportAndSave(params, filePath); //save the file in path.
  const file = await getExportAndSave(params); // just returning the file.
})();

after exporting the swagger file go over to https://editor.swagger.io/ and import the file, then you can interact with your API documentation.

in my next post, I will show you my next project to combine the swagger UI with the swagger exporter.

 
Share this