尽管POST请求中缺少字段,但SwaggerHub模拟响应返回201

时间:2018-05-28 15:15:21

标签: mocking swagger swaggerhub

我正在尝试根据以下定义在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"

每次我尝试使用缺少的字段发布错误的JSON,或者甚至根本没有JSON,我仍然会收到201代码,绝对不应该是201。

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

1 个答案:

答案 0 :(得分:1)

模拟不会检查输入中的必填字段,它只返回为操作定义的最低HTTP状态代码 - 在您的示例中,状态为201。

来自SwaggerHub documentation

  

请注意,mock不支持业务逻辑,也就是说,它无法根据输入发送特定的响应。

     

...

     

模拟根据其响应和规范中定义的响应媒体类型为每个API操作生成静态响应。

     

如果操作有多个响应代码,则mock返回状态代码最低的响应。例如,如果操作具有响应201,202和400,则模拟返回201响应。

您可能希望使用SwaggerHub开发者提交功能请求。

相关问题