Slim
Slim

Reputation: 6187

Unknown response type for the 204 code status

I need to describe the routes of my application, thus I use swagger:

paths:
  /users:
    get:
      description: Returns all users
      responses:
        "204":
          description: No Content Found
          schema:
            $ref: "#/definitions/NoContentFound"
      
definitions:
 NoContentFound:
  required:
     - message
  properties:
     message:
       type: string

I got this error on swagger UI:

Unknown response type

On app.js:

const User = require('../server/models/user');
const sendJsonResponse = function sendJsonResponse(req, res, status, content) {
  res.status(status);
  res.json(content);
};
app.get('/users/:usersid', (req, res) => {
 User
 .query()
 .where('id', id)
 .then(users => {
   if(users.length === 0) {
      sendJsonResponse(req, res, 204, 'No users Found');
   }
 });
};

How can I fix that on swagger?

Upvotes: 6

Views: 16493

Answers (1)

P.A
P.A

Reputation: 821

Some responses, such as 204 No Content, have No Body. To indicate the response body is empty, do not specify content for the response:

Reference: Empty Response Body

Upvotes: 10

Related Questions