1

这个想法取自这里 stack-overflow

添加一个应该允许动态查询参数的参数后,它会给出错误。

查询示例:

/pets:
    get:
      description: |
        Returns all pets
      operationId: findPets
      parameters:
        - name: params
          in: query
          required: false
          schema:
            type: object
            # If the parameter values are of specific type, e.g. string:
            # additionalProperties:
            #   type: string
            # If the parameter values can be of different types
            # (e.g. string, number, boolean, ...)
            additionalProperties: true

          # `style: form` and `explode: true` is the default serialization method
          # for query parameters, so these keywords can be omitted
          style: form
          explode: true
      responses:
        '200':
          description: pet response
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Pet'
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'

执行查询,返回

{"message":"Cannot convert undefined or null to object"}

重现

  • 克隆此存储库
  • npm install
  • npm start
  • curl http://localhost:3000/v1/pets\?type\=dog\&limit\=10\&test\=query

预期行为 它必须允许所有查询字符串

4

1 回答 1

1

这是express-openapi-validator包中的错误。

它现在固定在v4.4.2

要测试功能,请参阅此示例项目

于 2020-11-06T05:31:22.623 回答