【问题标题】:how to generate swagger document with tags using serverless-aws-documentation plugin for serverless如何使用无服务器的 serverless-aws-documentation 插件生成带有标签的 swagger 文档
【发布时间】:2017-08-03 11:17:53
【问题描述】:

我正在使用 serverless-aws-documentation 插件来自动生成 swagger-doc。遵循以下提供的所有步骤:https://github.com/9cookies/serverless-aws-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,但无法实现。提前感谢您的帮助。

【问题讨论】:

    标签: aws-lambda swagger serverless-framework


    【解决方案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 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
    

    【讨论】:

      【解决方案2】:

      您使用的是哪个版本?

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

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

      【讨论】:

      • 成功了吗?我仍然无法获取 Swagger 文件上的标签...
      猜你喜欢
      • 2016-02-05
      • 2023-02-13
      • 2018-04-28
      • 2021-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-15
      • 1970-01-01
      相关资源
      最近更新 更多