how to generate swagger document with tags using serverless-aws-documentation plugin for serverless

Viewed 2724

I am using serverless-aws-documentation plugin to auto-generate swagger-doc. Followed all the steps provided at : https://github.com/9cookies/serverless-aws-documentation. Under documentation key I am defining tags but it is not getting generated in the output swagger doc. Following is the sample handler :

functions:
  get_tickets:
    handler: handler.ticket_handler.get_tickets
    events:
      - http:
          path: tickets
          method: get
          cors: true
          documentation:
            tags:
              - private
              - admin
            summary: "Get list of ticket"
            description: "This ticket will provide you list of tickets"

I want to segrigate APIs depending on the tags, but not able to achieve it. Thanks in advance for the help.

2 Answers

Try to add the serverless-aws-documentation plugin in the serverless.yml

plugins:
  - serverless-aws-documentation

Add the infor and models documentation in the custom section:

custom:
  myStage: ${opt:stage, self:provider.stage}
  profiles:
    dev: road-we-go
    prod: road-we-
  documentation:
    info:
      version: "1.0.0"
      name: "Example API"
      description: "Example API description"
      termsOfService: "https://example.com/terms-of-service"
      contact:
        name: "Example API"
        url: "https://example.com"
        email: "dev@example.com"
      licence:
        name: "Licensing"
        url: "https://example.com/licensing"
    models:
      -
        name: "StoreAudioSuccess"
        description: "Model for store audio"
        contentType: "application/json"
        schema: ${file(swagger/audios/storeResponse. 

Add the function documentation:

If you want to add the custom models like RequestStore and StoreAudioSuccess check the serverless-aws-documentation documentation and the json-schema docs

functions:
  Update:
    handler: src/functions/update.handler
    timeout: 30
    memory: 128
    events:
      - http:
         method: put
         private: true
         cors: true
         path: api/v1/update
         documentation:
           summary: "Update "
           description: "Update a record"
           tags:
             - "Users"
           requestModels:
              "application/json": "RequestStore"
           methodResponses:
             -
              statusCode: "200"
              responseModels:
                 "application/json": "StoreUserSuccess"

To download the swagger documentation you need to run this command:

First you need to deploy you project

sls downloadDocumentation --outputFileName=swagger.json
Related