在 Swagger UI 中呈现为空数组的对象数组 [英] Object array rendered as empty array in Swagger UI
问题描述
我在 OpenAPI/Swagger 规范中有以下模型定义:
I have the following model definitions in an OpenAPI/Swagger spec:
"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
模型的数组,但 Swagger UI 3.x 将其呈现为一个空数组 []
.到处都使用 Feature
模型,例如 Feature
中 POST
方法的示例,我有这种显示.
In the Feature
model, he Equipments
property is defined as an array of Equipment
models, but Swagger UI 3.x renders it as an empty array []
. Everywhere Feature
model is used, like as examples for POST
method in Feature
I have this kind of display.
该定义在某些方面不正确吗?
Is the definition incorrect in some way?
完整的规范在这里:
https://dl.dropboxusercontent.com/s/anjfhgxhr0pfmnu/swagger-bug.json
推荐答案
这似乎是 Swagger UI 中的一个错误,很可能是由模型中的循环引用引起的 - models.Equipment
引用 models.Feature
和 models.Feature
引用了 models.Equipment
.您可以在 GitHub 上的 Swagger UI 存储库中打开问题.
This seems to be a bug in Swagger UI and is most likely caused by circular references in your models - models.Equipment
references models.Feature
, and models.Feature
references models.Equipment
. You can open an issue in the Swagger UI repository on GitHub.
您的规范还包含响应定义中的错误:
Your spec also contains errors in the response definitions:
"responses": {
"200": {
"schema": {
"$ref": "#/definitions/models.Equipment"
}
},
"403": {}
}
每个响应必须有一个描述
,所以正确的版本是:
Each response must have a description
, so the correct version would be:
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/models.Equipment"
}
},
"403": {
"description": "Oops"
}
}
这篇关于在 Swagger UI 中呈现为空数组的对象数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!