Skip to content

Response with array different then 200 doesn't show. #1055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
marcinskubala opened this issue Mar 20, 2015 · 16 comments
Closed

Response with array different then 200 doesn't show. #1055

marcinskubala opened this issue Mar 20, 2015 · 16 comments

Comments

@marcinskubala
Copy link

Hi, ui doesn't show the model shema.

"responses": {
    "200": {
        "description": "media response",
        "schema": {
            "type": "array",
            "items": {
                "$ref": "#\/definitions\/Media"
            }
        }
    },
    "default": {
        "description": "unexpected error",
        "schema": {
            "$ref": "#\/definitions\/Error"
        }
    },
    "422": {
        "description": "validation error",
        "schema": {
            "type": "array",
            "items": {
                "$ref": "#\/definitions\/ValidationError"
            }
        }
    }
}
@webron
Copy link
Contributor

webron commented Mar 26, 2015

You mean it doesn't display it for default and 422?

@marcinskubala
Copy link
Author

The model schemes for 200 and default are fine, but the 422 is an array of ValidationError and the "Model" and the "Model Scheme" tabs in UI are empty.

@webron
Copy link
Contributor

webron commented Mar 27, 2015

Is there actually a ValidationError model in the definition? It would help if you shared your whole Swagger definition for testing.

@marcinskubala
Copy link
Author

{
    "swagger": "2.0",
    "info": {
        "title": "XXX",
        "version": "XXX"
    },
    "host": "XXX",
    "basePath": "XXX",
    "schemes": [
        "http"
    ],
    "consumes": [
        "application\/x-www-form-urlencoded"
    ],
    "produces": [
        "application\/json",
        "application\/xml"
    ],
    "paths": {
        "\/media": {
            "post": {
                "tags": [
                    "Media Operations"
                ],
                "summary": "Create a new media",
                "parameters": [
                    {
                        "name": "title",
                        "in": "formData",
                        "description": "Media title",
                        "required": false,
                        "type": "string"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Media Response",
                        "schema": {
                            "$ref": "#\/definitions\/Media"
                        }
                    },
                    "Default": {
                        "description": "Default Error",
                        "schema": {
                            "$ref": "#\/definitions\/Error"
                        }
                    },
                    "422": {
                        "description": "Validation Error",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#\/definitions\/ValidationError"
                            }
                        }
                    }
                }
            }
        }
    },
    "definitions": {
        "Media": {
            "required": [
                "id"
            ],
            "properties": {
                "id": {
                    "type": "integer"
                },
                "title": {
                    "type": "string"
                }
            }
        },
        "Error": {
            "required": [
                "code"
            ],
            "properties": {
                "code": {
                    "type": "integer"
                }
            }
        },
        "ValidationError": {
            "required": [
                "field"
            ],
            "properties": {
                "field": {
                    "type": "string"
                }
            }
        }
    }
}

@webron
Copy link
Contributor

webron commented Mar 27, 2015

Which library produced that spec?

@marcinskubala
Copy link
Author

zircote/swagger-php v2.x

@webron
Copy link
Contributor

webron commented Mar 27, 2015

I believe this is related to swagger-api/swagger-js#270.

@webron
Copy link
Contributor

webron commented Mar 27, 2015

@marcinskubala - do you mind if I use the Swagger definition you shared here to open an issue on swagger-php? There are three problems with it they should solve.

@marcinskubala
Copy link
Author

@webron - fill free to share this code, thanks

@webron
Copy link
Contributor

webron commented Mar 27, 2015

@marcinskubala - thanks.

@mohsen1 - can you please confirm this is the same issue?

@tlbdk
Copy link

tlbdk commented Apr 13, 2015

Have the same issue, with this schema where the response model is missing for everything but 200:

image

{
    "swagger": "2.0",
    "info": {
        "version": "1.0.0",
        "title": "Test sample showing swagger error",
        "description": "Show that response headers are not rendered",
        "contact": {
            "name": "Troels Liebe Bentsen",
            "email": "[email protected]"
        }
    },
    "host": "localhost",
    "basePath": "/",
    "schemes": [
        "http"
    ],
    "consumes": [
        "application/json"
    ],
    "produces": [
        "application/json"
    ],
    "paths": {
        "/test": {
            "post": {
                "summary": "Test",
                "description": "Test stuff",
                "operationId": "doTest",
                "parameters": [
                    {
                        "in": "body",
                        "name": "body",
                        "required": true,
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/test"
                            }
                        }                       
                    },
                    {
                        "in": "header",
                        "name": "ETag",
                        "description": "Used as caching key for future requests",
                        "type": "string"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Test stuff response",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/test"
                            }
                        },
                        "headers": {
                            "ETag": {
                                "description": "Used as caching key for future requests",
                                "type": "string"
                            }
                        }
                    },
                    "405": {
                        "description": "Invalid input",
                        "headers": {
                            "ETag": {
                                "description": "Used as caching key for future requests",
                                "type": "string"
                            }
                        },
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/test"
                            }
                        }
                    }
                },
                "tags": ["test"]
            }
        }
    },
    "definitions": {
        "test": {
            "required": [
                "test1",
                "test2"
            ],
            "properties": {
                "test1": {
                    "type": "string"
                },
               "test": {
                    "description": "Amount to be payment",
                    "type": "number",
                    "format": "double",
                    "default": 0
                }
            }
        }
    }
}

@fehguy fehguy added this to the v2.1 milestone Apr 14, 2015
@fehguy
Copy link
Contributor

fehguy commented Apr 14, 2015

@mohsen1 can you please look at this?

@mohsen1 mohsen1 assigned mohsen1 and unassigned mohsen1 Apr 14, 2015
@tlbdk
Copy link

tlbdk commented Apr 20, 2015

Updated to latest version from master and I still see the issue

@mohsen1
Copy link
Contributor

mohsen1 commented Apr 20, 2015

I've spent some time looking into this issue. I don't know exactly what we should do here because the way we're passing responseModel to StatusCodeView is via optiosn.responseModel option which is a string and use that string to lookup router.api.models object

We're resolving $refs here but we're not doing it deeply. If we were to resolve deeply then should we pass the inner schema name string? If we do that, it's not accurate because the model should be the array.

I think $ref resolving mechanism needs a refactoring. We can't rely on little components resolve $refs little by little.

@ponelat
Copy link
Contributor

ponelat commented Apr 30, 2015

I agree, a little refactoring would be great. I kinda went looking at the same problem...
#671 (comment)

@fehguy
Copy link
Contributor

fehguy commented May 8, 2015

please follow parent issue #1248

@fehguy fehguy closed this as completed May 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants