无法获取生成的快递代码(从OpenAPI)来捕获查询参数中的错误

时间:2020-09-01 15:31:23

标签: node.js express swagger openapi

我正在尝试从isa-group / oas-tools获取生成的代码(express.js),以检查输入网址,但是我没有运气。 (或者我是否正在滥用该工具?!)似乎忽略了查询参数中的错误。例如,发送此网址不会出错:

http:// localhost:8080 / acQyreXchange / acQyr-sample / 1.0.0 / gamer / 123?limit = -3&xyz = a

我希望它抱怨“极限”超出范围(-3 <0),而“ xyz”是未知参数。我收到一条有关错误数据的错误消息(这是我期望的),但没有输入内容。这是响应:

[
    •   {
        o   message: "Wrong data in the response. ",
        o   error: 
        [
           {
               code: "INVALID_TYPE",
               params: 
                [
                   "array",
                   "object"
                ],
               message: "Expected type array but found type object",
               path: "#/"
            }
        ],
    o   content: 
        {
           message: "This is the mockup controller for getGamer"
        }
    •   }
]

调试日志显示:

2020-09-01T14:49:11.670Z info: Requested method-url pair: get - /acQyreXchange/acQyr-sample/1.0.0/gamer/123?limit=-3&xyz=a
2020-09-01T14:49:11.671Z debug: OASValidator  -res.locals.requestedSpecPath: /gamer/{gamerId}
2020-09-01T14:49:11.673Z info: Valid parameter on request
2020-09-01T14:49:11.675Z debug: Processing at checkResponse:
...

api文档显示:

  '/gamer/{gamerId}':
    get:
      tags:
        - admins
      summary: 'given a gamerId, returns a gamer'
      operationId: getGamer
      description: Returns a gamer
      parameters:
        - in: path
          name: gamerId
          description: pass the gamerId for looking up the gamer
          required: true
          schema:
            type: string
        - in: query
          name: skip
          description: number of records to skip for pagination
          schema:
            type: integer
            format: int32
            minimum: 0
        - in: query
          name: limit
          description: maximum number of records to return
          schema:
            type: integer
            format: int32
            minimum: 0
            maximum: 50
      responses:
        '200':
          description: search results matching criteria
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Gamer'
        '400':
          description: bad input parameter

我尝试了以下选项: 严格:正确(也尝试过错误) 验证者:true(也尝试过false) customErrorHandling:true(也尝试过false)

1 个答案:

答案 0 :(得分:0)

代码所有者说,他已尽快修复此问题。