3

for an nodejs-project I am using swagger-ui-express and swagger-jsdocs for the Swagger API. When I try to call an POST-Endpoint of my application with Swagger then there is no data sent with. What could be the problem? My whole relevant code is following:

const swaggerOptionsJSDocs = {
swaggerDefinition: {
    openapi: '3.0.1', //tried with 3.0.0 as well
    info: {
        title: "Testproject",
        description: "Middleware for bla bla ",
        contact: {
            name: "John Doo"
        }
    }
},
apis: ["index.js"]
};




const swaggerDocs = swaggerJsDoc(swaggerOptionsJSDocs);

app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocs));

**
 * @swagger
 * /user/upload:
 *  post:
 *      description: Receives a zipped and base64 encoded user
 *      consumes: 
 *         - application/json
 *      parameters:
 *          - in: body
 *            name: fullRequest // name here doesn't matter 
 *            description: ...
 *            schema:
 *              type: object
 *              required:
 *                  - user
 *              properties:
 *                  user:
 *                      type: string
 *                  jobId:
 *                      type: string
 *                  responseUrl:
 *                      type: string
 *                  inaugurationDate:
 *                      type: string
 *      responses:
 *          '201':
 *              description: user received and uploaded successfully
 *          '400':
 *              description: user data is missing or invalid
 *          '500':
 *              description: Internal server error
 *      
 *  
 *           
 */
app.post('/user/upload', function(req, res) {
  ....
}

Swagger is performing get request but when it comes to send data, the d-flag is empty. Does anyhone have an idea?

Best regards

Buzz
  • 315
  • 6
  • 18
  • Your endpoint annotation version is 2.0 and you have declared openapi 3.0.1, check the proper syntax https://swagger.io/docs/specification/about/ of openapi version 3.0.1 – turivishal Jul 13 '20 at 18:57
  • Thank you very much. That was the solution of course. – Buzz Jul 13 '20 at 21:50

2 Answers2

1

Parameters 'in:body' is not valid. In Open API 3, you have to pass the requestBody as a separate chunk.

Also, you have to use @openapi to use Open API.

Refer here, to see examples of requestBody object.

**
 * @openapi
...
 *      requestBody:
 *            description: ...
 *            schema:
 *              type: object
 *              required:
 *                  - user
 *              properties:
 *                  user:
 *                      type: string
 *                  jobId:
 *                      type: string
 *                  responseUrl:
 *                      type: string
 *                  inaugurationDate:
 *                      type: string
....
Uttam
  • 576
  • 5
  • 17
0

I had the same issue, please try to replace

openapi: '3.0.1', //tried with 3.0.0 as well

with

swagger: '2.0',
Or Assayag
  • 5,662
  • 13
  • 57
  • 93