swagger-express-middleware
swagger-express-middleware copied to clipboard
Example fields being used as default values
When using a json based swagger document, example
values are being used a default
values when default
is not defined. The expectation is that example
values would be ignored.
For example:
"paths": {
"/companies": {
"post": {
"description": "Create a Company",
"parameters": [
{
"name": "company",
"in": "body",
"description": "A Company",
"required": true,
"schema": {
"$ref": "#/definitions/company"
}
}
],
"responses": {
"201": {
"description": "Created",
"schema": {
"$ref": "#/definitions/company"
}
},
"406": {
"description": "Not Acceptable"
}
}
}
}
},
"definitions": {
"company": {
"type": "object",
"properties": {
"id": {
"description": "unique identifier of a company",
"example": "01234567-89ab-cdef-0123-456789abcdef",
"format": "uuid",
"maxLength": 37,
"readOnly": true,
"type": "string"
},
"name": {
"description": "name of company",
"example": "acme",
"maxLength": 255,
"readOnly": false,
"type": "string"
},
"code": {
"description": "unique code of company",
"maxLength": 255,
"type": "string"
},
"created_at": {
"description": "when company was created",
"example": "2001-01-01T12:00:00Z",
"format": "date-time",
"readOnly": true,
"type": "string"
},
"updated_at": {
"description": "when company was updated",
"example": "2001-01-01T12:00:00Z",
"format": "date-time",
"readOnly": true,
"type": "string"
}
},
"required": [
"name",
"code"
]
}
}
When sending a POST request to the /companies
endpoint where the code
value is defined, but the name
field is empty. The result is the value acme
being used as if it were a default value.
Hi. This behavior is by design, as documented here. The mock middleware will use the default
if one exists, or the example
otherwise.
Thanks for the reply. We are not using the mock()
middleware, however. Would you expect this from the validateRequest()
or the parseRequest()
middleware?
oh... now that's not by design. It definitely shouldn't be doing that.
:)
Thanks
This is still an issue, and a very bad bug?
https://github.com/APIDevTools/swagger-express-middleware/pull/99
Waiting on this.