Added swagger UI on my express app but POST req body is not editable
Hi Below is swagger code for API endpoint for post request. I can see the BODY in swagger UI but when I click on try it now I cannot edit request body.
Below is my code
/*** @swagger* /foods:* post:* summary: Creates a food item* consumes: application/json* parameters:* - in: body* type: object* properties:* ITEM_ID:* type: string* ITEM_NAME:* type: string* ITEM_UNIT:* type: string* COMPANY_ID:* type: string* responses:* 201:* description: Created* 400:* description: Bad Request* 500:* description: Internal Server Error*/app.post('/foods',[check('ITEM_ID').not().isEmpty().trim(), check('ITEM_NAME').not().isEmpty().trim(), check('ITEM_UNIT').not().isEmpty().trim(), check('COMPANY_ID').not().isEmpty().trim()], async (req,res) => { let connection; const errors = validationResult(req); if(!errors.isEmpty()){ return res.status(400).json({errors: errors.array()}); } else{ try { connection = await pool.getConnection(); var itemID = req.body.ITEM_ID; var itemName = req.body.ITEM_NAME; var itemUnit = req.body.ITEM_UNIT; var companyID = req.body.COMPANY_ID; var sql = `INSERT INTO foods (ITEM_ID, ITEM_NAME, ITEM_UNIT, COMPANY_ID) VALUES ('${itemID}', '${itemName}', '${itemUnit}','${companyID}')`; var rows = await connection.query(sql); res.status(201).json(req.body) } catch(err){ res.status(400).send(err.message); } finally{ if(connection){ return connection.release(); } } }});
Below is my swagger init code where I set the URL and other settings. Is there way I can make the req body editable. My POST api works fine with postman.
const options = { swaggerDefinition: { info: { title: 'API', description:'Sample DB CRUD Operations API', version: '1.0.0', }, host: '<host>:3000', basePath:'/' }, apis: ['./server.js'], // files containing annotations as above }; const specs = swaggerJsDoc(options);app.use('/docs', swaggerUi.serve, swaggerUi.setup(specs));