在我的"简化"API中,所有响应都是从基础"响应"类派生(继承)的.响应类由填充元数据的标头和包含用户请求的核心数据的主体组成.响应(在JSON中)的布局使得所有元数据都在第一个"层"上,而主体是一个称为"body"的单个属性,因此
response
|--metadata attribute 1 (string/int/object)
|--metadata attribute 2 (string/int/object)
|--body (object)
|--body attribute 1 (string/int/object)
|--body attribute 2 (string/int/object)
Run Code Online (Sandbox Code Playgroud)
我试图使用以下JSON在swagger中定义这种关系:
{
...
"definitions": {
"response": {
"allOf": [
{
"$ref": "#/definitions/response_header"
},
{
"properties": {
"body": {
"description": "The body of the response (not metadata)",
"schema": {
"$ref": "#/definitions/response_body"
}
}
}
}
]
},
"response_header": {
"type": "object",
"required": [
"result"
],
"properties": {
"result": {
"type": "string",
"description": "value of 'success', for a …Run Code Online (Sandbox Code Playgroud) swagger ×1