npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

serverless-plugin-swagger-export

v0.5.5

Published

Swagger Export plugin for Serverless

Readme

Swagger Export Plugin for Serverless

Kenneth Falck [email protected] 2016

This is a plugin that exports a Swagger JSON API definition file based on your Serverless project structure.

Note: Serverless v0.4.0 or higher is required.

Installation

First install the plugin into your Serverless project:

    npm install --save serverless-plugin-swagger-export

Then edit your s-project.json, locate the plugins: [] section, and add the plugin as follows:

    plugins: [
        "serverless-plugin-swagger-export"
    ]

Usage

To autogenerate a Swagger JSON API definition, use this command:

    sls swagger export [-b <basePath>]

where supplying basePath will set a default basePath tag in Swagger. This is useful if you are using different stages in Serverless, as you can set the stage name as the basePath in your CI/CD tool. NOTE: You can still set basePath inside s-project.json, and this will take precedence over the command line option - see below for customising exported API documentation.

Customizing exported API documentation

You can add a JSON element called "swaggerExport" in various Serverless project files to add documentation and other info to the exported Swagger JSON.

In s-project.json, you can override top level Swagger JSON elements like this:

    "name": "MyServerlessProject",
    "version": "1.0.0",
    "swaggerExport": {
      "info": {
        "title": "Overridden title",
        "description": "Overridden description"
      },
      "host": "example.com"
    }

Any elements you specify under swaggerExport will replace the defaults.

In s-function.json, you can add Swagger documentation to each endpoint like this:

    "path": "myapi",
    "method": "GET",
    "type": "AWS",
    "authorizationType": "none",
    "apiKeyRequired": true,
    "swaggerExport": {
      "tags": ["My Swagger Tag"],
      "summary": "Swagger summary",
      "description": "Swagger description",
      "parameters": [],
      "responses": {}
    }

Excluding endpoints from Swagger

if you wish an endpoint to be excluded (for instance, OPTIONS endpoints, or functions with no endpoints at all), simply set the only swagger tag as 'exclude':

    "path": "myapi",
    "method": "OPTIONS",
    "type": "AWS",
    "authorizationType": "none",
    "apiKeyRequired": true,
    "swaggerExport": {
      "exclude": true,
    }

Please see Swagger documentation for more details on all the fields.

Generating object definitions from Sequelize models

If your project uses Sequelize to define data models, they can be automatically exported in the Swagger JSON. To enable this, you need to have one Node.js module that exports all the models using the names that you want to use in Swagger. Then add this to s-project.json:

"swaggerExport": {
  "definitions": {
    "$sequelizeImport": "path/to/module"
  }
}

Now you can add Swagger responses that use $refs like this:

"200": {
  "description": "Successful operation",
  "schema": {
    "$ref": "#/definitions/MyDataModel"
  }
}

Assuming MyDataModel is found in your module, it will be added to the definitions element in the exported Swagger JSON.