spring-hateoas
spring-hateoas copied to clipboard
linkTo with inheritance - @PathVariable from parent is ignored
Given the following classes, ControllerLinkBuilder.linkTo(methodOn(FooApiImpl.class).getFoo("someId")) ignores the path param.
public interface FooApi {
@RequestMapping(value = "/foos/{foo-id}", method = RequestMethod.GET)
ResponseEntity<Foo> getFoo(@PathVariable(value="foo-id") String fooId);
}
@Controller
@RequestMapping("/basePath")
public class FooApiImpl implements FooApi {
public ResponseEntity<Foo> getFoo(String fooId){
// ...
}
}
The generated Link looks like http://localhost:8080/basePath/foos/{foo-id}
If I copy the @PathVariable to the param in FooApiImpl, the link looks like it should: http://localhost:8080/basePath/foos/someId
Calling linkTo on the FooApi class also works, but obviously ignores the basePath from the @RequestMapping from FooApiImpl.
I'm using spring-hateoas 0.25.2.RELEASE.
Can you elaborate how exactly you create the link? Given what you show, the base path of the class gets considered, as well as the request mapping on the interface's method. Whether the parameter is actually expanded depends on whether you hand in a value for fooId or simply provide null. So both the URI template and the URI you show might be correct output depending on how you create the link.
From the examples given, I don't see how the interface is not considered during link building.