spring-hateoas
spring-hateoas copied to clipboard
LinkTo does not resolve Request mapping placeholder
Spring framework allows to use placeholder in the request mapping.
@RequestMapping("${people.path:/people}")
interface PersonController {}
Using hateoas 1.1.0 and the linkTo(PersonController.class).toUri() method, the url is resolved as "/people}" with convert to "/people%7D"
Using hateaos 1.4.4 it just throw an error "Illegal character in path at index 30: http://localhost:55407/people}"
I can confirm this still causes errors using HATEOAS version 2.1.0. But now the error seems to look a bit different:
java.net.URISyntaxException: Illegal character in path at index 23: http://localhost:8080/${api.base-path}/method
Note that the controller is configured with @RequestMapping("${api.base-path:}"), i.e. somewhere the colon : in the template gets removed.
I don't find pretty workarounds for this issue. Something like
new PropertyPlaceholderHelper("\${", "}").replacePlaceholders(
value,
environment::getProperty
)
does not work well for empty path properties, because the result will be http://localhost:8080//method (double slash), which breaks things.
I confirm
@RequestMapping("${openapi.myapi.base-path:/v1}") is not resolved using spring-hatoas:2.2.0
ink selfRel = linkTo (methodOn(MyApi.class).resourceGet(resource.getId().toString())).withSelfRel();
return :
"links": [
{
"rel": "self",
"href": "http://localhost:8080/${openapi.myapi.base-path/v1}/resource/01cd1d5f-8336-4a0b-b295-21e54a7af459"
}
+1