swagger-ui icon indicating copy to clipboard operation
swagger-ui copied to clipboard

swagger-ui doesn't seem to handle array schema

Open paulhill opened this issue 12 years ago • 6 comments

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"
                        }
                    },

paulhill avatar Oct 09 '14 18:10 paulhill

What happens if your responses looks as follows?

"responses": {
                    "200": {
                        "description": "An array of users",
                        "schema": {
                            "$ref": "#/definitions/Users"
                        }
                    },

webron avatar Oct 09 '14 18:10 webron

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 avatar Oct 09 '14 18:10 paulhill

@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.

jeastman avatar Oct 09 '14 19:10 jeastman

not yet implemented in swagger-js

fehguy avatar Oct 09 '14 19:10 fehguy

I've updated swagger-ui to correctly display json-schema arrays

https://github.com/swagger-api/swagger-ui/pull/765

paulhill avatar Dec 06 '14 06:12 paulhill

@paulhill your PR had some issues, but this should be able to follow progress here:

https://github.com/swagger-api/swagger-js/issues/147

fehguy avatar Dec 30 '14 01:12 fehguy