Swagger-ui: Response Body as Array of Primitives

Created on 29 Dec 2014  路  6Comments  路  Source: swagger-api/swagger-ui

Issue: Swagger UI is displaying the response body incorrectly
I Expect it to display the array of strings that definition describes
Instead it displays my definition object as the response body

Disclaimer: I am making an assumption here that swagger definition objects correlate to json-schema definitions. That may be the source of my issue here.

Background: The response body contains an array of the IDs of steps that are part of instructions, and the order of those IDs describe their sequence. More at Google Groups

My Definition
"InstructionSequence": {
    "title": "InstructionSequence",
    "description": "The sequence of steps that make up the Instructions",
    "type": "array",
    "items": {
        "type": "string"
    }
}
Path & Response
"/instructions/{ID}/sequence": {
    "get": {
//...
        "responses": {
            "200": {
                "description": "Instruction's Sequence",
                "schema": {
                    "$ref": "InstructionSequence",
                    "example": [
                        "stepID",
                        "stepID",
                        "stepID"
                    ]
                }
            }
        }
    }
}
Swagger UI

screen shot 2014-12-29 at 11 04 47 am

bug

All 6 comments

May relate to #713 ?

Your definition is fine, and it is indeed a bug (possibly in swagger-js). Yes, quite possibly related to #713.

One thing to note - you _cannot_ mix $ref with any other property, so your usage of example in the response is invalid. If you want to include it, you have to include it in the schema definition.

Thanks @webron. Makes me think of a relevant piece of info...

I have tried this without a $ref: definition as well. Meaning that I have put the schema info directly in the response section. Different results, but still doesn't give what I would expect..

Path & Response
"/instructions/{ID}/sequence": {
    "get": {
//...
        "responses": {
            "200": {
                "description": "Instruction's Sequence",
                "schema": {
                    "type": "array",
                    "items": {
                        "type": "string"
                    }
                }
            }
    }
Swagger UI

screen shot 2014-12-29 at 11 23 36 am

Yes, that relates to a different bug that inline schema definitions are not parsed properly (can't remember the #, but the issue exists).

@webron
Is this fixed?
My Rest API returns array of array of strings without key values, how can that be modelled in swagger?

[ "1459451302225", "INFO", "INFO\taudit\t20,225\tRequest GET /rest/foo&skip=0&limit=25 exesults count: 10 (Status 200 OK) 135ms", "admin" ]

It should be fixed, yes.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

replaysMike picture replaysMike  路  120Comments

grosch picture grosch  路  75Comments

reginaldlouis picture reginaldlouis  路  43Comments

azamatsulaiman picture azamatsulaiman  路  34Comments

chanurahemal picture chanurahemal  路  87Comments