我有一个REST服务,我希望为我的客户开发团队提供文档。
因此,我在我的资源API中添加了一些来自Spring-Hateoas
的Links
,并插入了swagger-springmvc
的@Api...
注释以记录所有内容,并为我的Angular团队制作良好的API参考,以便他们能够理解我的REST服务。
问题在于,swagger
无法发现可能的链接,并且只是给出一个Links
的大数组,而不指定它们的可能值。
这里是(简单的)例子。Swagger检测到:
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
以使它们有注释版本,但是这让我陷入了困境。
有没有一种工具/方式可用于生成良好的API文档,说明一个self
关系是获取内容,而delete
关系是删除集合?
我喜欢Swagger的良好UI,但如果有助于使文档真正完整,我不介意更改我的文档工具。
最终我可以考虑更改spring-hateoas以使用其他链接生成器,但我不确定现在是否有更好的工具可用。