Computered
Computered

Reputation: 490

Create a definition direct on response object

I have this error definition

"definitions": {
    "error": {
        "description": "The error",
        "properties": {
            "code": {
                "description": "The code.",
                "type": "string"
            },
            "description": {
                "description": "Uma descrição do erro.",
                "type": "string"
            }
        }

And I used this "error" definition by $ref and it works:

"responses": {
    "400": {
        "description": "Error.",
        "schema": {
            "$ref": "#/definitions/erro"
        }

But I have a different "error" definition in another path, and I want to write the error definition direct on responses, for example:

"responses": {
    "400": {
        "description": "Error.",
        "schema": {
            "error": {
                "description": "The error",
                "properties": {
                    "code": {
                        "description": "The code.",
                        "type": "string"
                    },
                    "description": {
                        "description": "Uma descrição do erro.",
                        "type": "string"
                    }
                }
        }

But it wasn't work, with this message: "Swagger Error. Not a valid response definition"

How can I do that?

Upvotes: 0

Views: 91

Answers (1)

ByeBye
ByeBye

Reputation: 6946

You have to change you response json to:

"400": {
    "description": "Error.",
    "schema": {
        "title": "error",
        "description": "The error",
        "type": "object",
        "properties": {
            "code": {
                "type": "string",
                "description": "The code."
            },
            "description": {
                "type": "string",
                "description": "Uma descrição do erro."
            }
        }
    }
}

Upvotes: 1

Related Questions