You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Aliases in parameter annotations on a controller interface are not evaluated [SPR-17460] #21992
The goal would be Spring Framework to consider/evaluate the annotations on interface methods (e.g. public void getUser(@RequestParam("user-id")), so a developer doesn't have to define the annotations in the implementing class again.
We aimed to address this in 5.1 through #15682... Could you please double-check that your case indeed does not work against 5.1.2 and ideally provide a particular case to reproduce?
Juergen Hoeller: I've got the same problem in version 5.1 and debugged the code:
The difference seems to be, that the @AliasFor-Annotation (e.g. in PathVariable) is not evaluated by the new code that takes over the interface annotations.
And the swagger-codegen (OpenApiGenerator likewise) generates interfaces in which only value is set, e.g.: @PathVariable("test-id")
WiedemannA, good catch! I was able to reproduce this; we indeed miss a synthesizeAnnotation step for interface-level annotations, not evaluating their aliases. Fixed in master now for the 5.1.3 release.
Activity
spring-projects-issues commentedon Nov 2, 2018
Juergen Hoeller commented
We aimed to address this in 5.1 through #15682... Could you please double-check that your case indeed does not work against 5.1.2 and ideally provide a particular case to reproduce?
spring-projects-issues commentedon Nov 5, 2018
Bogdan Zafirov commented
Juergen Hoeller I attached an example Spring-Boot application (created with https://start.spring.io). There is one interface (TestInterface.java) and an implementing class annotated with RestController (TestController.java). When I do a HTTP GET with the following URL http://localhost:8080/v1/test/ZZ95711905000000500000 I get 'Internal Server Error'. The error message is: "Missing URI template variable 'testId' for method parameter of type String". This actually shows that Spring is considering the variable name instead of the value set in the PathVariable (e.g. test-id) annotation. The same thing happens for the header parameter 'X-Request-ID', namely the header parameter has to named xRequestID.
spring-projects-issues commentedon Nov 5, 2018
Juergen Hoeller commented
Brian Clozel, could you please try to debug the repro app and double-check why this still doesn't work against 5.1.x there?
spring-projects-issues commentedon Nov 12, 2018
WiedemannA commented
Juergen Hoeller: I've got the same problem in version 5.1 and debugged the code:
The difference seems to be, that the
@AliasFor-Annotation (e.g. in PathVariable) is not evaluated by the new code that takes over the interface annotations.And the swagger-codegen (OpenApiGenerator likewise) generates interfaces in which only
valueis set, e.g.:@PathVariable("test-id")The PathVariableMethodArgumentResolver only takes over the
nameout of the PathVariable-Annotation.Therefore the check if the
nameis empty in AbstractNamedValueMethodArgumentResolver.updateNamedValueInfo() delivers true and falls back to theParameterName, which causes the error Bogdan Zafirov describes...Bogdan Zafirov: Can you verifiy, that the Problem doesn't occure, if you set both value and name?
@PathVariable(name= "test-id", value = "test-id")spring-projects-issues commentedon Nov 12, 2018
Juergen Hoeller commented
WiedemannA, good catch! I was able to reproduce this; we indeed miss a
synthesizeAnnotationstep for interface-level annotations, not evaluating their aliases. Fixed in master now for the 5.1.3 release.