如何在 Nodejs 应用程序的 swagger 中对端点进行分组

问题描述 投票:0回答:1

在 NodeJS 中,分组 API 对我来说是不可能的。看到的各种方法并没有像预期的那么简单;因为端点仍然保持默认的 swagger 分组。下面的方法使事情成功了。

node.js api swagger documentation
1个回答
0
投票

对于 NodeJS,预计在您的 swagger.js 或 swagger.ts 文件中, 你有以下内容;

swagger.js 文件

   swagger: "2.0",
    info: {
        title: 'My API',
        description: 'My API docs',
    },
    host: 'localhost:9000/api/v1',
    schemes: ['http', 'https'],
    tags: [
        {
          name: 'Patient Management',
          description: "Patient Management"
        },
        {
            name: 'Doctor Management',
            description: "Doctor Management"
        },
        ...
        ...
    ]
}

然后在你的控制器文件中,你应该有以下内容;

获取医生控制器

const GetDoctorsController = (req:Request, res:Response) => {
    // #swagger.tags = ['Doctor Management']
    try{
    }catch(error){
    }
}

运行 api 的脚本并在浏览器上运行链接

© www.soinside.com 2019 - 2024. All rights reserved.