如何使用节点 sdk 在代码中为 azure 函数生成 openAPI 规范?

How to generate openAPI spec in code for azure functions using the node sdk?

我在 azure 函数中定义了一个 api,我想以一种可以生成开放 API 规范的方式进行注释。

我试过使用 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;

根据我的调查,目前还没有plugin\way开箱即用的支持。还有。 我现在所做的是将我的 azure 函数应用程序与 azure 中的 APIM 以及从那里的 downloaded generated 模式链接起来。在我将手动更新模式并在部署过程中重新部署到 APIM 之后。