如何使用Serverless-AWS-Documentation插件生成带有标签的Swagger文档。

3
我正在使用serverless-aws-documentation插件自动生成swagger-doc。按照提供的步骤执行:https://github.com/9cookies/serverless-aws-documentation。在documentation键下,我定义了标签,但是在生成的swagger文档中未生成。以下是示例处理程序:
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个回答

1
尝试在serverless.yml中添加serverless-aws-documentation插件。
plugins:
  - serverless-aws-documentation

在自定义部分添加信息和模型文档:
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文档json-schema文档

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

0

2
它起作用了吗?我仍然无法在Swagger文件中获取标签... - Itay Katz

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接