Skip to content
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

Do not display error model #331

Closed
maximemenard opened this issue Oct 11, 2013 · 16 comments
Closed

Do not display error model #331

maximemenard opened this issue Oct 11, 2013 · 16 comments
Milestone

Comments

@maximemenard
Copy link

Hi,

The JSON generated when I indicate the error java class is correct, but it is not displayed in swagger-ui.

In Java code :

@ApiResponses({ @ApiResponse(code = 400, response = ErrorResponse.class, message = "Transaction not found, or error when sending sms") })

JSON generated :

responseMessages": [
    {
        "code": 400,
        "message": "Transaction not found, or error when sending sms",
        "responseModel": "ErrorResponse"
    }
]
"models": {
    "ErrorResponse": {
        "id": "ErrorResponse",
        "properties": {
            "message": {
                "type": "string"
            },
            "code": {
                "type": "integer",
                "format": "int32"
            }
        }
    }

The problem is that I don't have any information about ErrorResponse in swagger-ui. I just have the code "400' and the message.

Regards

@neilyoung
Copy link

I second this. ResponseModel is not recognized :(

@fehguy
Copy link
Contributor

fehguy commented Oct 23, 2013

Yes, the alternate response models & polymorphic types are not currently in the UI. Marking this as a feature...

@fehguy
Copy link
Contributor

fehguy commented Aug 2, 2014

please reopen if still an issue

@fehguy fehguy closed this as completed Aug 2, 2014
@hoyle1974
Copy link

I still see this same issue occurring with the latest pull from git. I see a model for the operation but not the response specific models.

My json looked something like this:

{
    "swaggerVersion": "1.2",
    "apis": [
        {
            "path": "/ping",
            "description": "???",
            "operations": [
                {
                    "method": "GET",
                    "nickname": "ping",
                    "notes": "Ping the application.",
                    "parameters": [],
                    "type": "controllers.Ping",
                    "responseMessages": [
                        {
                            "code": 200,
                            "message": "Ok",
                            "responseModel": "controllers.Ping"
                        },
                        {
                            "code": 201,
                            "message": "Created",
                            "responseModel": "controllers.Ping"
                        },
                        {
                            "code": 500,
                            "message": "Test",
                            "responseModel": "controllers.Ping"
                        }
                    ]
                }
            ]
        }
    ],
    "apiVersion": "v1",
    "info": {
        "title": "Title",
        "description": "Description"
    },
    "models": {
        "controllers.Ping": {
            "id": "controllers.Ping",
            "properties": {
                "status ": {
                    "type": "string"
                },
                "timestamp ": {
                    "type": "int64"
                },
                "version ": {
                    "type": "string"
                }
            },
            "required": [
                "status ",
                "timestamp ",
                "version "
            ]
        }
    },
    "resourcePath": "http://localhost:9000"
}

@fehguy
Copy link
Contributor

fehguy commented Sep 29, 2014

This is supported when using swagger 2.0 specifications:

image

@neilyoung
Copy link

2.0 does not fix the problem.

Using swagger 2.0 editor (http://editor.swagger.io/#/edit) with the default "Uber" sample seems to solve the problem (see screenshot):

https://cloud.githubusercontent.com/assets/731020/5027847/f5439ff2-6b33-11e4-8db0-2cee479e3075.png

But if I examine the produced JSON in the latest swagger-ui the result does only show the "default" response. The 200 response is missing.

https://cloud.githubusercontent.com/assets/731020/5027890/53b95ca2-6b34-11e4-893c-8bc71a826722.png

Here some other examples, which illustrate, that swagger-ui is unable to display the response models correctly:

            "responses": {
                "201": {
                    "description": "History information for the given user",
                    "schema": {
                        "$ref": "Product"
                    }
                },
                "default": {
                    "description": "Unexpected error",
                    "schema": {
                        "$ref": "Activities"
                    }
                }
            }

This setup does show "default".

            "responses": {
                "300": {
                    "description": "History information for the given user",
                    "schema": {
                        "$ref": "Product"
                    }
                },
                "default": {
                    "description": "Unexpected error",
                    "schema": {
                        "$ref": "Activities"
                    }
                }
            }

This setup shows "300". Do you see a pattern here?

@webron
Copy link
Contributor

webron commented Nov 13, 2014

@neilyoung - now looking at the posted sample you have, the $ref is wrong. It should be "$ref": "#/definitions/Activities". Can you try that and see if that works? Same goes for the Product reference.

@neilyoung
Copy link

Thanks for the hint. But no, that doesn't help. BTW: The JSON is the unmodified export from the Swagger 2.0 editor sample

Regards

@neilyoung
Copy link

No, it is not a question of the syntax. It seems to simply just accept one model definition. Not to predict, which.

@neilyoung
Copy link

I have a little more input. Maybe there is a higher sense :)

If the response definition looks like this (don't care too much about sense or nonsense of definition):

            "responses": {
                "300": {
                    "description": "An array of products",
                    "schema": {
                        "type": "array",
                            "$ref": "Product"
                    }
                },
                "400": {
                    "description": "An array of products",
                    "schema": {
                        "type": "array",
                            "$ref": "Error"
                    }
                }
            }

Then the result looks like this:

https://cloud.githubusercontent.com/assets/731020/5031043/7f154904-6b54-11e4-9587-5ba51ca358a9.png

If I just change 300 to 200, 200 disappears from the response messages (although defined there) and appears somewhere above as "Response Class". Does that make sense?

https://cloud.githubusercontent.com/assets/731020/5031092/ed4a0c2a-6b54-11e4-8936-9232cc36e798.png

@webron
Copy link
Contributor

webron commented Nov 13, 2014

Yes, it makes sense.

This is due to the current behavior that the 'first' 2XX response is considered as the 'main' response of the API call and it is displayed separately. This is related to the behavior in Swagger 1.2 and prior to it where operations had a distinct return type (unrelated to the responseMessages) as the 'successful' response, regardless of the http status code.

We're considering if and how to modify this behavior - you can follow #674 on that.

@neilyoung
Copy link

Thanks. Have made my +1 there :)

@webron
Copy link
Contributor

webron commented Nov 13, 2014

Great. By the way, with regards to the $ref, whether the editor does that or not, and whether the UI currently supports it or not, I'm just giving you a heads-up this is a malformed spec and it shouldn't work, so the behavior of the tools may change in the future to reflect that.

@fehguy fehguy added this to the v2.1.0-M1 milestone Jan 28, 2015
fehguy added a commit to swagger-api/swagger-js that referenced this issue Jan 31, 2015
@fehguy
Copy link
Contributor

fehguy commented Feb 1, 2015

the default response type is now set as the minimum 2xx type, or default if none exists.

@fehguy fehguy closed this as completed Feb 1, 2015
@dariusz
Copy link

dariusz commented May 6, 2015

Hey all, this issue is actually not resolved from what I can tell ... ResponseModel for Swagger 1.2 are not rendered by swagger-ui (as OP reported).

The code below (result of swagger-php, most recent dev-master as of today) does not result in an entry in the Response column.

Tested with master as well as 2.0_develop branches.

{
    "basePath": "...",
    "swaggerVersion": "1.2",
    "apiVersion": "1.0",
    "resourcePath": "/v1/products",
    "apis": [
        {
            "path": "/v1/products/{tulip_id}",
            "operations": [
                {
                    "method": "GET",
                    "summary": "Find Product by Id",
                    "nickname": "getProductById",
                    "type": "string",
                    "parameters": [
                        {
                           ...
                        }
                    ],
                    "responseMessages": [
                        {
                            "code": 403,
                            "message": "Not authorized",
                            "responseModel": "ProblemJson"
                        }
                    ],
                    "notes": "Returns the product with the matching unique tulip_id"
                }
            ]
        }
    ],
    "models": {
        "ProblemJson": {
            "id": "ProblemJson",
            "properties": {
                "status": {
                    "description": "HTTP response status code",
                    "type": "integer"
                },
                "title": {
                    "description": "Title of the HTTP response code",
                    "type": "string"
                },
                "detail": {
                    "description": "Human-readable message to explain what happenend.",
                    "type": "string"
                }
            }
        }
    },
    "produces": [
        "application/json"
    ]
}

Any chance of this getting resolved in the master branch?

@webron
Copy link
Contributor

webron commented May 6, 2015

@dariusz - #671

JuanSW18 pushed a commit to Digital-Paw/digital-paw-swagger-ui that referenced this issue Aug 23, 2024
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