validator-badge
validator-badge copied to clipboard
Validator throws exception on non-string default values for model properties
This will cause an error in the validator http://online.swagger.io/validator/debug?url=
{
"properties" : {
"success" : {
"type" : "boolean",
"default" : false
}
}
}
But this is ok:
{
"properties" : {
"success" : {
"type" : "boolean",
"default" : true
}
}
}
And so is this:
{
"properties" : {
"success" : {
"type" : "boolean",
"default" : "false"
}
}
}
Seems to be working now
If you want to check out my json file its here: http://dev.app.opentimeapp.com/docs/data/1.0.1.json
The problem is generic with non-string default values for model properties. This is definitely a bug.
We're now better handling the exception but the arrays are not yet supported.
http://online.swagger.io/validator/debug?url=http://dev.app.opentimeapp.com/docs/data/1.0.1.json
Here is the culprit. In /connection/withList
:
{
"parameters": [
{
"in": "query",
"name": "list",
"required": true,
"type": "array",
"default": [
2,
3
],
"description": "The user id for the other user"
}
]
}
It doesn't like the default
array. I'm actually not sure how you would set the default value for an array (you're also missing the inner type) but this seems to work fine:
{
"parameters": [
{
"in": "query",
"name": "list",
"required": true,
"type": "array",
"items": {
"type": "integer",
"format": "int32"
},
"description": "The user id for the other user"
}
]
}
This is something that belongs in swagger-core
@webron how does one represent a default value of type array in the spec?
@fehguy - https://github.com/swagger-api/swagger-spec/issues/343
I believe it should indeed be [1, 2]
. 'default' is an 'Any' property that should be the same type as the type
itself. We have similar bug in the pet store sample.
same with minimum and maximum.. fix should be for all.
+1 to fix it
@JathinSanghvi please provide a test case and we'll get this fixed.
@GET
@Path("/petstore/{storeid}/pet/{petid}")
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public Physician getPet(@ApiParam @DefaultValue(value="0") @Min(0) @PathParam("storeid") int enterpriseid,
@ApiParam @Min(value=1000000000) @PathParam("petid") int npi,
@ApiParam @DefaultValue(value="false") @QueryParam("refresh") boolean refresh);
The above jaxrs 2.0 resource method will generate swagger.json
"paths": {
"/petstore/{storeid}/pet/{petid}": {
"get": {
"produces":
[
"application/json",
"application/xml"
],
"parameters":
[
{
"name": "storeid",
"in": "path",
"required": true,
"type": "integer",
"default": 0
"minimum": 0.0,
"format": "int32"
},
{
"name": "petid",
"in": "path",
"required": true,
"type": "integer",
"minimum": 1.0E9,
"format": "int32"
},
{
"name": "refresh",
"in": "query",
"required": false,
"type": "boolean",
"default": false
}
],
There will be few schema validaiton errors.. from http://editor.swagger.io/#/
- default cannot be integer.. needs to be string
- mimnum cannot be integer.. needs to be string (swagger-jaxrs is generating minimum as 0.0 even though type is an integer.. that also needs a fix)
- minimum cannot be 1.0E9, .. needs to be string (swagger-jaxrs is generating minimum as 1.0E9 even though type is an integer.. should not be formatted.. as it fails validation)
- default cannot be false .. needs to be string