我有一个 REST 服务,我想为我的客户开发团队记录。
因此,我在我的资源 API 中添加了一些Links
from Spring-Hateoas
,并插入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 更改为另一个链接生成器,但我不确定现在是否有更好的工具可用。