Spring HATEOAS Swagger Example Value Problem (question)
See original GitHub issueI’m using springfox-swagger2 and springfox-swagger-ui version 2.7.0 (2.8.0 fails with an ‘auth’ problem and 2.9.0 isn’t available to me) with a Spring Boot 2.0 REST application using HATEOAS. I have a question about the output I’m seeing for the example value for one of my API endpoints. The swagger example doesn’t match the output generated by the application. My endpoint is defined in a RestController like this:
@RequestMapping(value = "/documents", method = RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE)
public Resources<Resource<Document>> getAvailableDocuments) {
...
}
(the Resources and Resource are standard Spring HATEOAS classes, Document is our code which just contains a bunch of document related attributes)
The output I get when I execute the method is this:
{
"_embedded": {
"documentList": [
{
"name": "...",
"format": "...",
"created_at": "...",
...
"_links": {
"self": {
"href": "..."
}
}
},
... more documents like above ...
]
},
"_links": {
"self": {
"href": "..."
}
}
}
(note the “_embedded” and “_links” elements as well as the structure of the “_links” elements. However the example generated by the Swagger UI is this:
{
"content": [
{
"created_at": "2018-05-05T13:54:27.743Z",
"description": "string",
...
"links": [
{
"deprecation": "string",
"href": "string",
"hreflang": "string",
"media": "string",
"rel": "string",
"templated": true,
"title": "string",
"type": "string"
}
],
"name": "string",
"system_id": "string",
"updated_at": "2018-05-05T13:54:27.743Z"
}
],
"links": [
{
"deprecation": "string",
"href": "string",
"hreflang": "string",
"media": "string",
"rel": "string",
"templated": true,
"title": "string",
"type": "string"
}
]
}
The Swagger example doesn’t contain the “_embedded” object, “_links” are called “links” and are structured differently than what is really produced. Are there some configuration changes I can make to get the example to look more like the real result? In the Links section, are there ways to tell Swagger that the application is not going to populate certain fields (e.g. media, templated, etc.)
Any help our pointers would be appreciated. Thanks!
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
@dilipkrish I upgraded to 2.9.2 but am still encountering this issue. Is there anything I am missing or should it work out of the box?
Example endpoint: @GetMapping(“/{modelId}/results”) public Resources<ResultsResource> findAllBlaBla(@PathVariable(“modelId”) String modelId)
Thanks!
How we can disable the HAL format by default. I am using the below property in properties file but didn’t affect. spring.hateoas.use-hal-as-default-json-media-type=false