0

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));

and i am defining the below definitions in './routes/product.route.ts' file which has to be shown in the swagger UI but still the problem persists and all i can able to see is "no operations defined in spec".

/**
 * @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
 */

1 Answers1

0

it worked...! Due to an unnoticeable naming convention near apis:'./routes/products.route.ts'

Thanks!

  • In addition: the path inside the apis field needs to be relative to root. more info is here specified: [no-operations-defined-in-spec](https://stackoverflow.com/questions/56781385/no-operations-defined-in-spec-i-get-this-error-even-though-the-swagger-is-set) – shehryar Mar 09 '22 at 17:59