我想爲我的客戶開發團隊記錄一份REST服務。來自Spring Hateoas的文檔HAL「_links」(與swagger)?
所以我添加從Spring-Hateoas
一些Links
到我的資源API,並插入到它swagger-springmvc
@Api...
註解記錄的一切,使一個很好的API參考我的角團隊能夠理解我的REST服務。
問題是,swagger
無法發現哪些鏈接是可能的,只是給我一大堆Links
沒有說明它們的可能值。
這是一個(簡單)示例。揚鞭檢測:
Model Schema
CollectionListResource {
collections (array[CollectionResource]): All available collections,
links (array[Link]): Relations for next actions
}
CollectionResource {
collectionId (string): Collection Unique Id,
name (string): Human readable collection name,
links (array[Link]): Relations for next actions
}
Link {
rel (string, optional),
templated (boolean, optional),
href (string, optional)
}
而且我得到了事實的HAL:
{"collections":
[{"collectionId":"5370a206b399c65f05a7c59e",
"name":"default",
"_links":{ [
"self":{
"href":"http://localhost:9080/collections/5370a206b399c65f05a7c59e"
},
"delete":{
"href":"http://localhost:9080/collections/5370a206b399c65f05a7c59e"
}
]}
}, ...]}
我試圖擴大Link
和ResourceSupport
已經annoted他們的版本,但這個使我無處。
有沒有一種方法/工具可以用來生成一個好的API文檔,告訴self
關係是獲取內容,而delete
關係是刪除集合?
我很喜歡Swagger的良好用戶界面,但我不介意更改我的文檔工具,如果它的幫助文檔真的完成。
我最終可能會想到爲另一個鏈接生成器更改spring-hateoas,但我不確定現在是否有更好的工具可用。
感謝您的所有參考;我已經知道一些,但發現了其他人。 你提出的新HAL確實比我現在的更完整,但我仍然沒有看到一種方式來大舉發現_links數組的內容。實際上,現在我對HAL Spring爲我產生的感覺非常滿意。 我不知道該解決方案是不是將通用_links數組轉換爲包含預定義可選鏈接字段的結構。 從語法上講,實際上,刪除[]是「公正的」,但在實現方面,它肯定要複雜得多;) –