使用 Springfox 的 Swagger UI 中的超媒体链接 [英] Hypermedia links in Swagger UI using Springfox
问题描述
我正在构建一个 RESTful API,使用 spring-hateoas 库来实现超媒体.我的端点的响应是 application/hal+json(我的 DTO 扩展了 ResourceSupport).
I'm building a RESTful API, using spring-hateoas library to implement hypermedia. The response of my endpoints is application/hal+json (My DTO extends ResourceSupport).
我使用 Swagger 来记录端点,并使用 Springfox 自动生成 swagger-ui.
I'm using Swagger to document the endpoints, and using Springfox to autogenerate the swagger-ui.
问题是,生成的文档不正确.
The problem is, that the generated documentation is not correct.
作为对 POST 端点的请求,UI 将我的 DTO 中的 _links 部分设置为有效负载的一部分,因此我认为应该将其作为参数发送给我的 POST 端点:
As a request for a POST endpoint, the UI is setting the _links section from my DTO as part of the payload, so this is what I see I should send as a parameter for my POST endpoint:
{
"category": "string",
"creator": "string",
"description": "string",
"id": 0,
"links": [
{
"href": "string",
"rel": "string",
"templated": true
}
],
"period": 0,
"recipient": 0,
"title": "string",
"type": 0
}
所以我的问题是:有没有办法让 springfox 知道 application/hal+json 作为参数内容类型?如果没有,有没有办法从请求中隐藏 _links 部分?
So my question is: Is there any way of making springfox aware of application/hal+json as the Parameter content type? In case there isn't, is there any way of hiding the _links section from the request?
推荐答案
所以,我发现隐藏链接部分的唯一方法是覆盖我的 DTO 扩展 ResourceSupport 中的 setLinks 方法,并将 hidden 设置为 true,如下所示:
So, the only way I found of hiding the links section was to override the setLinks method in my DTO extending ResourceSupport, and set hidden to true as follows:
@ApiModelProperty(hidden = true)
public void setLinks(final Link... links) {
super.add(links);
}
这篇关于使用 Springfox 的 Swagger UI 中的超媒体链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!