Swagger 在直接响应对象上创建定义

Swagger 在直接响应对象上创建定义,swagger,swagger-editor,Swagger,Swagger Editor,我有这个错误定义 "definitions": { "error": { "description": "The error", "properties": { "code": { "description": "The code.", "type": "string" }, "description": {

我有这个错误定义

"definitions": {
    "error": {
        "description": "The error",
        "properties": {
            "code": {
                "description": "The code.",
                "type": "string"
            },
            "description": {
                "description": "Uma descrição do erro.",
                "type": "string"
            }
        }
我使用$ref的“错误”定义,它是有效的:

"responses": {
    "400": {
        "description": "Error.",
        "schema": {
            "$ref": "#/definitions/erro"
        }
但我在另一个路径中有一个不同的“错误”定义,我想直接在响应上编写错误定义,例如:

"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"
                    }
                }
        }
但这不起作用,因为有这样一条信息: “招摇过市错误。不是有效的响应定义”


我该怎么做呢?

您必须将响应json更改为:

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