SwaggerHub 模拟响应 returns 201 尽管 POST 请求中缺少字段

SwaggerHub mock response returns 201 despite missing fields in POST request

我正在尝试根据以下定义在 SwaggerHub 上模拟一个 POST 请求:

    post:
      summary: "Creates order"
      description: ""
      consumes:
      - application/json
      parameters:
      - name: "order"
        in: body
        description: "New order"
        schema:
          $ref: "#/definitions/Order"
      responses:
        201:
          description: "Order succesfully created."
        400:
          description: "Order can't be created"

模型定义为:

definitions:
  Order:
    type: object
    properties:
      id:
        type: string
        format: uuid
        example: d290f1ee-6c54-4b01-90e6-d701748f0851
      marketPair:
        type: integer
        format: "int64"
        example: "BTC_TRY"
      amount:
        type: number
        format: "int64"
        example: "1.3"
      price:
        type: integer
        format: "int32"
        example: "467"
      operationType:
        type: string
        description: "Type of operation"
        enum: 
        - "buy"
        - "sell"
        example: "buy"
      orderType:
        type: string
        description: "Order Type"
        enum:
        - "limit"
        - "market"
        - "stop"
        default: "limit"
        example: "limit"
    xml:
      name: "Order"

每次我尝试 POST 错误 JSON 缺少字段,甚至根本没有 JSON 时,我仍然收到 201 代码,这绝对不应该'不是 201.

我的配置中是否缺少某些内容,或者 SwaggerHub 需要进行哪些更改才能识别我的规范并开始检查负载是否符合此端点的规范要求?

模拟不以任何方式验证输入。它只是 returns 为操作定义的最低 HTTP 状态代码——在您的示例中,状态 201。

来自SwaggerHub documentation

Note that the mock does not support business logic, that is, it cannot send specific responses based on the input.

...

The mock generates static responses for each API operation based on its responses and the response media types defined in the spec.

If an operation has multiple response codes, the mock returns the response with the lowest status code. For example, if an operation has responses 201, 202 and 400, the mock returns the 201 response.

您可能想向 SwaggerHub 开发人员提交功能请求。