Hypermedia links in Swagger UI using Springfox

☆樱花仙子☆ 提交于 2019-12-13 02:36:16

问题


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).

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.

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
}

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?


回答1:


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);
}


来源:https://stackoverflow.com/questions/38694734/hypermedia-links-in-swagger-ui-using-springfox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!