-
Notifications
You must be signed in to change notification settings - Fork 473
Description
Using Spring HATEOAS does not seem to allow to match specs configured to explode arrays:
- name: make
in: query
schema:
type: array
items:
type: string
style: form
explode: false
I am generating the links as follows:
@GetMapping(value = "/cars")
public HttpEntity<?> getCars(@RequestParam(name = "make", required = false) List<String> make) {
Link selfLink = linkTo(methodOn(InstrumentController.class).getCars(make)).withSelfRel();
CollectionModel<Car> someCars = searchCars(make);
someCars.add(selfLink);
return new ResponseEntity<>(someCars, HttpStatus.OK);
}
Calling the endpoint with http://localhost:8080/cars?make=Renault,BMW gives the response response like:
{
"_embedded": {
"carList": [
{
"make": "BMW",
"model": "i3"
},
{
"make": "Renault",
"model": "Clio"
}
]
},
"_links": {
"self": {
"href": "http://localhost:8080/cars?make=Renault&make=BMW"
}
}
}
The link is http://localhost:8080/cars?make=Renault&make=BMW but should be http://localhost:8080/cars?make=Renault,BMW"
Debugging the code from org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo reaches HierarchicalUriComponents.getQuery which always duplicates the query variable name for each value.
Trying to change the behaviour of WebMvcLinkBuilder by creating a custom one seems to need a lot of code duplication. Maybe there is a better way to achieve this, but it would be better to have it done in a simple way (e.g. like using a spring configuration).