响应验证失败:返回500状态

时间:2018-01-29 16:02:08

标签: node.js validation swagger

我正在使用nodejs和swagger为我的api。如果出现问题,我需要发送500状态。但是当我这样做时,我收到此错误Response validation failed: failed schema validation

这是api的代码(删除额外的东西)

function getAllBoards(req, res) {
    ...
    if (error)
        return res.status(500).json({ message: "Error" });
    return res.status(200).json(results);

这是我的招摇配置

  /get_all_boards:
    # our controller name
    x-swagger-router-controller: elasticsearch
    get:
      operationId: getAllBoards
      description: get the list of boards
      # define the type of response for Success "200" and Error
      responses:
        "200":
          description: Success
          schema:
            $ref: "#/definitions/GetBoardsListResponse"
        default:
          description: Error
          schema:
            $ref: "#/definitions/ErrorResponse"

错误响应方案

ErrorResponse:
    required:
      - message
    properties:
      message:
        type: string

请注意,如果我返回200状态,那么我不会收到任何错误,但当我发送500作为响应时,我会收到错误。

0 个答案:

没有答案
相关问题