Serverless 1.0 plugin to add documentation and models to the serverless generated API Gateway





GitHub Stars



Last Commit

8mos ago






Size (min+gzip)




Type Definitions





serverless Build Status codecov MIT licensed

Serverless AWS Documentation

This is a Serverless v1 plugin that adds support for AWS API Gateway documentation and models (e.g. to export a Swagger JSON file with input/output definitions and full text documentation for API documentation).

Important notice

This plugin is no longer maintained and therefore archived. If you want to continue this project feel free to fork it and publish it under a new name. Unfortunately we can't transfer ownership of this project.

What is AWS API Gateway documentation?

Amazon introduced a new documentation feature for it's API Gateway on AWS at the end of 2016. With this you can add manually written documentation to all parts of API Gateway such as resources, requests, responses or single path or query parameters. When exporting Swagger from API Gateway these documentation is added to the other information to create a more human understandable documentation.

In addition to this documentation this plugin also adds support to add models to API Gateway and use it with the serverless functions. Models are JSON Schemas that define the structure of request or response bodies. This includes property structure, their types and their validation. More about this you'll find here:


This plugin only works for Serverless 1.0 and up. For a plugin that supports 0.5 look at this plugin.

To install this plugin, add serverless-aws-documentation to your package.json:

npm install serverless-aws-documentation --save-dev

Next, add the serverless-aws-documentation plugin in to serverless.yml file: If you don't already have a plugins section, create one that looks like this:

  - serverless-aws-documentation

To verify that the plugin was added successfully, run this in your command line:


The plugin should show up in the "Plugins" section of the output as "ServerlessAWSDocumentation"

Example serverless.yml

You can find a fully functioning serverless project with examples of documentation in the ./example/ directory. See the in there for more details.


There are two places you need to touch in the serverless.yml: custom variables to define your general documentation descriptions and models, and the http events in your functions section to add these models to your requests and responses and add description to function relevant parts.

Define descriptions for your documentation

For manual full text descriptions for the parts of your API you need to describe it's structure. In the general part you can describe your API in general, authorizers, models and resources. If you want to find out more about models, you can skip to the next section.

Gotcha with 'version' and 'title' on the API

Currently (August 2017) you'll have trouble with the title and version fields for you API description. If you define them as below, they'll be correctly created in API Gateway (you can see it in the web console) but when you export the Swagger document from API Gateway, your title and version will be ignored and replaced with something like:

version: "2017-08-23T07:59:29Z"
title: dev-your-api-serverless

Your general documentation has to be nested in the custom variables section and looks like this:

        version: "2" # see note above about this being ignored
        title: "Name of your API" # see note above about this being ignored
        description: "This is the best API ever"
        termsOfService: ""
          name: "John Smith"
          url: ""
          email: ""
          name: "Licensing"
          url: ""
          name: "Data Creation"
          description: "Services to create things"
          name: "Some other tag"
          description: "A tag for other things"
        name: "MyCustomAuthorizer"
        description: "This is an error"
        path: "some/path"
        description: "This is the description for some/path"
        path: "some/other/path"
        description: "This is the description for some/other/path"

Your documentation has to be nested in the documentation custom variable. You describe your documentation parts with the description and summary (or title for the API itself) properties. The summary is some sort of title and the description is for further explanation. You can see the expected format in the Swagger v2 specification for the info object.

On the upper level, under the documentation/api section, you describe your API in the info object. In there you also can manually describe the version (needs to be a string). If you don't define the version, the version that API Gateway needs will automatically be generated. This auto version is a hash of the documentation you defined, so if you don't change your documentation, the documentation in API Gateway won't be touched.

Underneath you can define tags, authorizers, resources and models which are all lists of descriptions. In addition to the description and the summary, Authorizers need the name of the authorizer, resources need the path of the described resource and models need the name of the model. Tags provides the description for tags that are used on METHODs (HTTP events), more info here.

Define the models

Models have additional information you have to define. Besides the model name, the description and the summary, you need to define the content type for this model in addition to the schema that describes the model:

  • contentType: the content type of the described request/response (like "application/json" or "application/xml"). This is mandatory.
  • schema: The JSON Schema that describes the model. In the examples below external files are imported, but you can also define the schema inline using YAML format.

Your models definition could look like this:

        name: "ErrorResponse"
        description: "This is an error"
        contentType: "application/json"
        schema: ${file(models/error.json)}
        name: "CreateRequest"
        description: "Model for creating something"
        contentType: "application/json"
        schema: ${file(models/create_request.json)}

Within the schema, you can reference and nest any of your models with the $ref keyword, its value should be something like {{model: YourModelName}}. For example:

        name: "Address"
        description: "This is an address"
        contentType: "application/json"
          type: "object"
              type: "string"
        name: "Customer"
        description: "This is a customer"
        contentType: "application/json"
          type: "object"
              type: "string"
              $ref: "{{model: Address}}"

Function specific documentation

When you want to describe the parts inside a RESOURCE you need to do this in the functions described in your serverless.yml. Inside the http event of your functions you need to add the documentation property which can hold the following parts:

  • The method description which is described directly inside the documentation property
  • requestBody: The body of your HTTP request
  • requestHeaders: A list of headers for your HTTP request (needs name of the header)
  • queryParams: A list of query parameters (needs name of the parameter)
  • pathParams: A list of path parameters (needs name of the parameter)
  • methodResponses: A list of method responses (needs the statusCode of the response)
  • tags: A list of tags apply to the METHOD, which is the HTTP event in serverless. Used in Swagger-UI

The methodResponses itself can have the following parts:

  • responseBody: The body of the HTTP request
  • responseHeaders: A list of headers for your HTTP response (needs name of the header)

With this your function definition could look like this:

  handler: handler.create
    - http:
        path: create
        method: post
          summary: "Create something"
          description: "Creates the thing you need"
            - "Data Creation"
            - "Some other tag"
            description: "Request body description"
              name: "x-header"
              description: "Header description"
              name: "Authorization"
              description: "Auth Header description"
              name: "sid"
              description: "Session ID"
              name: "theme"
              description: "Theme for for the website"
              name: "id"
              description: "ID of the thing you want to create"
            "application/json": "CreateRequest"
            "application/xml": "CreateRequestXml"
              statusCode: "200"
                description: "Response body description"
                  name: "x-superheader"
                  description: "this is a super header"
                "application/json": "CreateResponse"
              statusCode: "400"
                "application/json": "ErrorResponse"

To add your defined models to the function you also need the following properties.


In the requestModels property you can add models for the HTTP request of the function. You can have multiple models for different ContentTypes. Inside the requestModels property you define the content type as the key and the model name defined in the models section above as the value. Here's short example:

  "application/json": "CreateRequest"
  "application/xml": "CreateRequestXml"


In the methodResponses property you can define multiple response models for this function. The response models are described in the ResponseModels property which contains the models for the different content types. These response models are described like the requestModels above.

    statusCode: "200"
      "application/json": "CreateResponse"
      "application/xml": "CreateResponseXml"
    statusCode: "400"
      "application/json": "ErrorResponse"

In the full example above you also can see the definition of the requestModels and responseModels in a the context of the documentation.

Deploy the documentation

To deploy the models you described above you just need to use serverless deploy as you are used to.

If you've defined requestHeaders in your documentation this will add those request headers to the CloudFormation being deployed, if you haven't already defined those request parameters yourself. If you don't want this, add the option --doc-safe-mode when deploying. If you use that option you need to define the request parameters manually to have them included in the documentation, e.g.

      method.request.header.{header-name}: true|false

See the Serverless documentation for more information on resource naming, and the AWS documentation for more information on request parameters.

Download documentation from AWS API Gateway

To download the deployed documentation you just need to use serverless downloadDocumentation --outputFileName=filename.ext. For yml or yaml extensions application/yaml content will be downloaded from AWS. In any other case - application/json. Optional argument --extensions ['integrations', 'apigateway', 'authorizers', 'postman']. Defaults to 'integrations'.


When you think something is missing or found some bug, please add an issue to this repo. If you want to contribute code, just fork this repo and create a PR when you are finished. Pull Requests are only accepted when there are unit tests covering your code.



Rate & Review

Great Documentation0
Easy to Use0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Unwelcoming Community0