【问题标题】:No operations defined in spec! ---Unable to define definitions ---node.ts,swaggerUI规范中没有定义操作! ---无法定义定义---node.ts,swaggerUI
【发布时间】:2023-03-08 04:29:01
【问题描述】:

Below is code for setting up my swagger which is in main.ts file

const swaggerOptions={
    swaggerDefinition:{
        info:{
            title:'Data Api',
            version:'1.0.1',
            description:'ToDo API',

            host:'localhost:7000',
            basePath:'/'
        }
    },
    apis:['./routes/product.route.ts'][enter image description here][1]
};
const swaggerdocs=swaggerjsdoc(swaggerOptions);
app.get('/swagger.json',(req:Request,res:Response)=>{
    res.setHeader('Content-Type','application/json');
    res.send(swaggerdocs);
});

app.use('/api-docs',swaggeruiexpress.serve,swaggeruiexpress.setup(swaggerdocs));

我在 './routes/product.route.ts' 文件中定义了以下定义,这些定义必须在 swagger UI 中显示,但问题仍然存在,我能看到的只是“没有在规范”。

/**
 * @swagger
 * /getAllItems:
 *   get:
 *     summary: List all the Objects
 *     description: Returns a list of all the user names
 *     tags:
 *       - Values
 *     parameters:
 *      name: 
 *             type:string
 *         _id: 
 *              type:string
 *     produces:
 *       - application/json
 *     responses:
 *       200:
 *         description: Successful
 *          400:
 *          description: Bad Request..Try again later
 *          _id:
 *                 type: string
 *          name:
 *              type:string
 */

【问题讨论】:

    标签: node.js rest swagger swagger-ui openapi


    【解决方案1】:

    成功了……! 由于 apis:'./routes/products.route.ts' 附近的命名约定不明显

    谢谢!

    【讨论】:

    猜你喜欢
    • 2019-06-07
    • 1970-01-01
    • 1970-01-01
    • 2020-10-01
    • 1970-01-01
    • 2022-11-01
    • 2019-02-10
    • 1970-01-01
    • 2020-11-27
    相关资源
    最近更新 更多