【问题标题】:Unknown response type for the 204 code status204 代码状态的未知响应类型
【发布时间】:2017-10-06 09:13:42
【问题描述】:

我需要描述我的应用程序的路由,因此我使用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

我在 swagger UI 上收到此错误:

Unknown response type

在 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');
   }
 });
};

我该如何解决这个问题?

【问题讨论】:

标签: swagger


【解决方案1】:

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

参考:Empty Response Body

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    • 2012-03-09
    • 1970-01-01
    相关资源
    最近更新 更多