如何使用serverless-aws-documentation插件为无服务器生成带标签的swagger文档

时间:2017-08-03 11:17:54

标签: aws-lambda swagger serverless-framework

我正在使用serverless-aws-documentation插件来自动生成swagger-doc。遵循:reference variable in angular template提供的所有步骤。在文档键下我定义了标签,但它没有在输出swagger doc中生成。以下是样本处理程序:

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"

我希望根据标记来分割API,但无法实现它。在此先感谢您的帮助。

2 个答案:

答案 0 :(得分:1)

您使用的是哪个版本?

根据他们最新的文档https://github.com/9cookies/serverless-aws-documentation,您需要提供如下标记,即双引号内。

documentation:
    tags:
      - "private"
      - "admin"

答案 1 :(得分:1)

尝试在serverless.yml中添加serverless-aws-documentation插件

plugins:
  - serverless-aws-documentation

在自定义部分中添加infor和模型文档:

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. 

添加功能文档:

  

如果您要添加RequestStoreStoreAudioSuccess之类的自定义模型,请选中serverless-aws-documentation documentationjson-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"

要下载swagger文档,您需要运行以下命令:

  

首先,您需要部署项目

sls downloadDocumentation --outputFileName=swagger.json