I'm trying to mock a POST request at SwaggerHub based on the following definition:
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"
Model is defined as:
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"
Every time I'm trying to POST bad JSON with missing fields or even with no JSON in body at all I'm still receiving 201 code which absolutely shouldn't be 201.
Is there something missing in my configuration or what changes does it need for SwaggerHub to recognise my specification and start checking if the payload matches the specification requirements for this endpoint?
The mock does not validate inputs in any way. It simply returns the lowest HTTP status code from those defined for the operation – in your example, status 201.
From 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.
You might want to file a feature request with SwaggerHub devs.