swagger-ui doesn't seem to handle array schema
I noticed something else that doesn't work as expected in swagger-ui. I have this data structure:
"definitions": {
"User": {
"type": "object",
"properties": {
"id": {
"type": "string",
"format": "object-id"
},
"username": {
"type": "string",
"minLength": 3,
"maxLength": 32
}
}
},
"Users": {
"type": "array",
"items": {
"$ref": "User"
}
},
...
Note the array of Users. When I use that model to define a typed array response swagger-ui just displays an empty object: {}
"responses": {
"200": {
"description": "An array of users",
"schema": {
"$ref": "Users"
}
},
What happens if your responses looks as follows?
"responses": {
"200": {
"description": "An array of users",
"schema": {
"$ref": "#/definitions/Users"
}
},
Same thing. It's not that it can't find the schema. It finds the other object schema and displays them correctly. It just doesn't know what to do with an array type schema.
@paulhill I have run into this several times. I am still trying to find why it causes a problem, but have been rat-holing elsewhere. It only seems to occur when you have a model whose type is an array (wrapped in an object it works).
Try the following and see if it works:
"responses": {
"200": {
"description": "An array of users",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/User"
}
}
}
}
That was the only way I was able to get around it.
not yet implemented in swagger-js
I've updated swagger-ui to correctly display json-schema arrays
https://github.com/swagger-api/swagger-ui/pull/765
@paulhill your PR had some issues, but this should be able to follow progress here:
https://github.com/swagger-api/swagger-js/issues/147