gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 17:50:23 25 4
gpt4 key购买 nike

我正在使用 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,但无法实现。预先感谢您的帮助。

最佳答案

尝试在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.

添加函数文档:

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"

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

First you need to deploy you project

sls downloadDocumentation --outputFileName=swagger.json

关于aws-lambda - 如何使用无服务器的 serverless-aws-documentation 插件生成带有标签的 swagger 文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45482657/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com