scottie1984 / swagger-ui-express

Adds middleware to your express app to serve the Swagger UI bound to your Swagger document. This acts as living documentation for your API hosted from within your app.
MIT License
1.43k stars 228 forks source link

Request body doesn't work #283

Closed Dharanikanna closed 2 years ago

Dharanikanna commented 2 years ago

I'm trying to send email and password data's using request body instead of params method, but I'm not able to see request body in the swagger-ui "swagger-ui-express": "^4.3.0".

I have the same issue. But in my case openapi: '3.0.0'

Screenshot for reference

image

Swagger-jsdoc output

{ openapi: '3.0.0', info: { title: 'Node API', version: '1.0.0' }, paths: { '/user/register': { post: [Object] }, '/healthcare/heroku': { get: [Object] }, '/healthcare/getall': { get: [Object] }, '/healthcare/id': { get: [Object] } }, components: { schema: { users: [Object] } }, tags: [] }

Code for reference


//user login routes
router.post('/login',user.login)

/**
 * @swagger
 *  components:
 *      schema:
 *          users:
 *              type: object
 *              properties:
 *                  email:
 *                      type: string
 *                  password:
 *                      type: string 
 */

/**
 * @swagger
 * /user/login:
 *   post:
 *     summary: Login
 *     description: Login User
 *     requestBody:
 *       required:true
 *       content:
 *         application/json:
 *           schema:
 *             $ref: '#components/schema/users'
 *     responses:
 *       201:
 *         description: User Logged in successfuly
 *         schema:
 *           type: "string"
 *       "400":
 *         description: "Invalid username/password supplied"
 */
scottie1984 commented 2 years ago

You can test your swagger document here https://editor.swagger.io/ to make sure it is valid.

If you are still having problems I suggest raising it directly with https://github.com/swagger-api/swagger-ui