Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LinkTo does not resolve Request mapping placeholder #1816

Open
roll57 opened this issue Jul 15, 2022 · 3 comments
Open

LinkTo does not resolve Request mapping placeholder #1816

roll57 opened this issue Jul 15, 2022 · 3 comments

Comments

@roll57
Copy link

roll57 commented Jul 15, 2022

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}"

@cureaid
Copy link

cureaid commented Jul 13, 2023

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.

@sebwt
Copy link

sebwt commented Feb 26, 2024

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"
}

@wilx
Copy link

wilx commented Mar 25, 2024

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants