Export Swagger documentation file from AWS ApiGateway

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

to make the process easily accessed i created npm module apigateway-export-tool that does exactly that.

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

im 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 documentations.

in my next post i will show you my next project to combine the swagger ui with the swagger exporter.

Nir Adler

Nir Adler