node.js - Swagger won't generate right json to post from yaml -


i using swagger , want use post api. while shows parameters correctly, won't produce right command of curl send data server.

p.s: back-end in node.js , express , parses yaml docs via swagger-jsdoc.

here yaml:

/**  * @swagger  * /register:  *   post:  *     tags:  *       - report  *     description: returns info panel api  *     consumes:  *       - application/x-www-form-urlencoded  *     produces:  *       - application/json  *     parameters:  *     -  name: email  *        in: body  *        description: email  *        required: true  *        type: string  *     -  name: password  *        in: body  *        description: password  *        required: true  *        type: string  *     -  name: fullname  *        in: body  *        description: full name  *        required: true  *        type: string  *     responses:  *       200:  *         description: info panel api  *       401:  *         description: if user didn't authenticate  */ 

and generated curl command:

curl -x post --header 'content-type: application/x-www-form-urlencoded' --header 'accept: application/json' -d 'max mcgrey' 'http://localhost:5200/register' 

and response:

{   "status": "fail",   "message": "validation failed, check inputs.",   "errors": [     {       "param": "fullname",       "msg": "full name required."     },     {       "param": "fullname",       "msg": "full name must between 1 , 50 characters long."     },     {       "param": "email",       "msg": "email required."     },     {       "param": "email",       "msg": "email required."     },     {       "param": "password",       "msg": "password required."     }   ] } 

the parameter syntax wrong. if operation supposed consume application/x-www-form-urlencoded, need use in: form parameters instead of in: body:

 *     consumes:  *       - application/x-www-form-urlencoded  *     ...  *     parameters:  *     -  name: email  *        in: form              <-----------  *        description: email  *        required: true  *        type: string  *     -  name: password  *        in: form              <-----------  *        description: password  *        required: true  *        type: string  *     -  name: fullname  *        in: form              <-----------  *        description: full name  *        required: true  *        type: string 

if supposed consume json, need single in: body parameter, , individual fields (email, password, etc.) should properties of body object:

 *     consumes:  *       - application/json  *     ...  *     parameters:  *     -  name: body  *        in: body  *        required: true  *        schema:  *          type: object  *          required: [email, password, fullname]  *          properties:  *            email:  *              type: string  *              format: email  *              description: email  *            password:  *              type: string  *              format: password  *              description: password  *            fullname:  *              type: string  *              description: full name 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -