假設我有一個User和一個UserType模型。我想在用戶模型中添加對UserType-ID的引用。 swagger文檔僅顯示如何引用另一個(整個)模型,而不僅僅涉及它的一個屬性。如何引用Swagger中另一個模型定義的ID
所以我想知道它甚至有可能只引用另一個模型定義的屬性。
"definitions": {
"User": {
"required": [
"username",
"typeId"
],
"properties": {
"id": {
"type": "integer",
"format": "int32"
},
"username": {
"type": "string"
},
"typeId": {
"$ref": "UserType.id" // ==> this doesn't work! and without
// the ".id" part it would include all
// the properties of UserType
}
}
},
"UserType": {
"required": [
"name"
],
"properties": {
"id": {
"type": "integer",
"format": "int32"
},
"name": {
"type": "string"
}
}
}
}
或者是根本不可能的,它應該永遠只是:
"definitions": {
"User": {
...
"properties": {
"typeId": {
"type": "integer",
"format": "int32"
}
}
},
...
}
在我進入答案之前,你爲什麼要引用一個* primitive *定義?什麼讓你保存在書面上? – Ron 2014-11-08 08:16:24
我想我認爲任何人閱讀REST文檔以查看「鏈接」模型會更清楚。 – roberkules 2014-11-08 08:18:38
如果我需要改變UserType.id的類型,我不需要更新所有的引用。 – roberkules 2014-11-08 08:24:36