ave*_*mia 3 node.js swagger typescript azure-functions openapi
我在 azure 函数中定义了一个 api,我想以可以生成 openAPI 规范的方式对其进行注释。
我尝试过使用 tsoa,但它似乎与无服务器不兼容。目前,openAPI 规范是使用 swagger-jsdoc 生成的,但在注释中包含描述符是不可维护的。我想要类似于 .NET 端 swagger 的工作方式,其中我可以使用路由信息注释函数,并且库将生成 openAPI 规范。这对于打字稿存在吗?我还查看了 Azure 的 API 管理来生成规范,但这些函数目前不是函数应用程序的一部分(它们作为静态站点 api 的一部分部署),并且我不确定 api 管理是否能够处理打字稿类型。
这是我当前使用 swagger-jsdoc 定义规范的设置示例。
/**
* @swagger
* /api/user:
* get:
* tags:
* - user
* summary: Get the user by Id
* description: "Returns a single user"
* parameters:
* - in: "query"
* name: "id"
* description: "ID of the user to return"
* required: true
* schema:
* type: "string"
* responses:
* '200':
* description: OK
* content:
* application/json:
* schema:
* $ref: "#/components/schemas/User"
* post:
* tags:
* - user
* summary: POST a user to the database
* description: User that needs to be added to the database
* requestBody:
* description: User that needs to be added to the database
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/User'
* required: true
* responses:
* '200':
* description: OK
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/User'
*
* components:
* schemas:
* User:
* type: object
* properties:
* id:
* type: string
* name:
* type: string
*
* @param context The context
* @param req The request
*/
const props: HandlerProperties<User> = {
containerType: config.userContainer
};
export const httpTrigger: AzureFunction = async function (context: Context, req: HttpRequest): Promise<void> {
context.res = await handleRequest(toRequest<User>(req), props);
};
export default httpTrigger;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1562 次 |
| 最近记录: |