我在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
模型的数组,但Swagger UI 3.x将其呈现为空数组[]
。使用Feature
模型,就像POST
中Feature
方法的示例一样。我有这种显示方式。
定义是否以某种方式不正确?
完整的规范如下:
https://dl.dropboxusercontent.com/s/anjfhgxhr0pfmnu/swagger-bug.json
答案 0 :(得分:1)
这似乎是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"
}
}