在 Swagger 中呈现为空数组的对象数组 UI
Object array rendered as empty array in Swagger UI
我在 OpenAPI/Swagger 规范中有以下模型定义:
"definitions": {
"models.Equipment": {
"title": "Equipment",
"type": "object",
"properties": {
"Features": {
"type": "array",
"items": {
"$ref": "#/definitions/models.Feature"
}
},
"Id": {
"type": "integer",
"format": "int64"
},
"IdType": {
"type": "string"
},
"Name": {
"type": "string"
},
"Price": {
"type": "integer",
"format": "int32"
}
}
},
"models.Feature": {
"title": "Feature",
"type": "object",
"properties": {
"Equipments": {
"type": "array",
"items": {
"$ref": "#/definitions/models.Equipment"
}
},
"Id": {
"type": "integer",
"format": "int64"
},
"IdFeature": {
"$ref": "#/definitions/models.Feature"
},
"Name": {
"type": "string"
}
}
}
}
在Feature
模型中,他Equipments
属性定义为Equipment
个模型的数组,而SwaggerUI3.x将其呈现为空数组 []
。到处都使用 Feature
模型,例如 Feature
中的 POST
方法示例 我有这种显示。
定义是否有误?
完整的规范在这里:
https://dl.dropboxusercontent.com/s/anjfhgxhr0pfmnu/swagger-bug.json
这似乎是 Swagger UI 中的一个错误,很可能是由模型中的循环引用引起的 - models.Equipment
引用 models.Feature
和 models.Feature
引用 models.Equipment
。您可以在 GitHub 上的 Swagger UI repository 中打开一个问题。
您的规范还包含响应定义中的错误:
"responses": {
"200": {
"schema": {
"$ref": "#/definitions/models.Equipment"
}
},
"403": {}
}
每个回复 must have a description
,所以正确的版本是:
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/models.Equipment"
}
},
"403": {
"description": "Oops"
}
}
我在 OpenAPI/Swagger 规范中有以下模型定义:
"definitions": {
"models.Equipment": {
"title": "Equipment",
"type": "object",
"properties": {
"Features": {
"type": "array",
"items": {
"$ref": "#/definitions/models.Feature"
}
},
"Id": {
"type": "integer",
"format": "int64"
},
"IdType": {
"type": "string"
},
"Name": {
"type": "string"
},
"Price": {
"type": "integer",
"format": "int32"
}
}
},
"models.Feature": {
"title": "Feature",
"type": "object",
"properties": {
"Equipments": {
"type": "array",
"items": {
"$ref": "#/definitions/models.Equipment"
}
},
"Id": {
"type": "integer",
"format": "int64"
},
"IdFeature": {
"$ref": "#/definitions/models.Feature"
},
"Name": {
"type": "string"
}
}
}
}
在Feature
模型中,他Equipments
属性定义为Equipment
个模型的数组,而SwaggerUI3.x将其呈现为空数组 []
。到处都使用 Feature
模型,例如 Feature
中的 POST
方法示例 我有这种显示。
定义是否有误?
完整的规范在这里:
https://dl.dropboxusercontent.com/s/anjfhgxhr0pfmnu/swagger-bug.json
这似乎是 Swagger UI 中的一个错误,很可能是由模型中的循环引用引起的 - models.Equipment
引用 models.Feature
和 models.Feature
引用 models.Equipment
。您可以在 GitHub 上的 Swagger UI repository 中打开一个问题。
您的规范还包含响应定义中的错误:
"responses": {
"200": {
"schema": {
"$ref": "#/definitions/models.Equipment"
}
},
"403": {}
}
每个回复 must have a description
,所以正确的版本是:
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/models.Equipment"
}
},
"403": {
"description": "Oops"
}
}