直接在响应对象上创建定义
Create a definition direct on response object
我有这个错误定义
"definitions": {
"error": {
"description": "The error",
"properties": {
"code": {
"description": "The code.",
"type": "string"
},
"description": {
"description": "Uma descrição do erro.",
"type": "string"
}
}
我使用了 $ref 的这个 "error" 定义并且有效:
"responses": {
"400": {
"description": "Error.",
"schema": {
"$ref": "#/definitions/erro"
}
但是我在另一个路径中有不同的 "error" 定义,我想直接在响应上写错误定义,例如:
"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"
}
}
}
但是没有成功,消息如下:
"Swagger Error. Not a valid response definition"
我该怎么做?
您必须将您的回复 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."
}
}
}
}
我有这个错误定义
"definitions": {
"error": {
"description": "The error",
"properties": {
"code": {
"description": "The code.",
"type": "string"
},
"description": {
"description": "Uma descrição do erro.",
"type": "string"
}
}
我使用了 $ref 的这个 "error" 定义并且有效:
"responses": {
"400": {
"description": "Error.",
"schema": {
"$ref": "#/definitions/erro"
}
但是我在另一个路径中有不同的 "error" 定义,我想直接在响应上写错误定义,例如:
"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"
}
}
}
但是没有成功,消息如下: "Swagger Error. Not a valid response definition"
我该怎么做?
您必须将您的回复 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."
}
}
}
}