specification-arg-resolver
specification-arg-resolver copied to clipboard
@PathVariable issues
Hello, when i trying to use this @Spec(path = "id", pathVars = "id", spec = Equal.class), my path variable is not consumed, and i get exception -> Requested path variable {id} is not present in Controller request mapping annotations. What is the problem, I read old posts and didn't find a solution? I using v2.6.2.
Hi, I have the same issue, same version ... I can't find solution ...
I've the same problem, but it was my fault : the request mapping of my controller didn't start with "/", so the AntMatcher didn't detect the pahtVars. Probably if you add "/" before your url mapping, the Pathvariable will be detected. Like this :
Before :
@RestController
@RequestMapping("programs")
@Slf4j
public class ProgramController
after :
@RestController
@RequestMapping("/programs")
@Slf4j
public class ProgramController
In my case, I had a prefix path to the Spring WebMVC config :
` @Configuration @EnableWebMvc @EnableHypermediaSupport(type = EnableHypermediaSupport.HypermediaType.HAL) public class WebMvcConfig implements WebMvcConfigurer {
public static final String PREFIX = "/api";
private final String baseUrl = "/";
private static final String[] API_VERSIONS = new String[] {"v1"};
/*
* add prefix PREFIX and VERSION to all Webservice API Spring REST
*/
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
for (String version : API_VERSIONS) {
configurer.addPathPrefix(PREFIX + "/" + version, c -> c.isAnnotationPresent(RestController.class) && checkVersion(c, version));
}
}
`
and my controller is like that :
@RestController @RequestMapping("/groupes") public class GroupeController { ...
my webservice method declaration :
` @ApiOperation(value = "Liste des fonctions du groupe", produces = "application/json", authorizations = { @Authorization(value = "JWT_TOKEN", scopes = { @AuthorizationScope(scope = "read", description = "") }) }) @ApiImplicitParams({ @ApiImplicitParam(name = "idGroupe", value = "id du groupe", required = false, dataTypeClass = String.class, paramType = "path") })
@GetMapping("/{idGroupe}/fonctions")
public PagedModel<EntityModel<com.bayard_service.webservice.rest.projections.relationship.FonctionGroupe>> getGroupeFonctions(FonctionSpec spec, Pageable pageable, @RequestParam(defaultValue="defaultFonctionGroupeProjection", required = false) String projection, @ApiIgnore PagedResourcesAssembler<com.bayard_service.webservice.rest.projections.relationship.FonctionGroupe> assembler) throws ResponseStatusException {
... `
So, in the WebRequestProcessingContext class, in getPathVariableValue() method where exception is throw :
` public String getPathVariableValue(String pathVariableName) {
if(resolvedPathVariables == null) {
resolvedPathVariables = PathVariableResolver.resolvePathVariables( pathPattern(), actualWebPath());
}
String value = resolvedPathVariables.get(pathVariableName);
if (value != null) {
return value;
} else {
throw new InvalidPathVariableRequestedException(pathVariableName);
}
}
`
For the call /api/v1/groupes/4402/fonctions, I want macthing {idGroupe} on '4402' value that in the path but the actualPath is "/api/v1/groupes/4402/fonctions" and the patternPath is "/groupes/{idGroupe}/fonctions"
and the method don't find idGroupe because patternPath is wrong : the PREFIX (that I had in the Spring config) is missing.
The result is the WebRequestProcessingContext exception throws :
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is net.kaczmarzyk.spring.data.jpa.web.InvalidPathVariableRequestedException: Requested path variable {idGroupe} is not present in Controller request mapping annotations
Could you find a way for add the prefix in the patternPath computation ?
( Ask me if it's not clear ;-) )
Thank's
Eric
resolved in https://github.com/tkaczmarzyk/specification-arg-resolver/pull/135/](https://github.com/tkaczmarzyk/specification-arg-resolver/pull/135/commits/2f98da0dbd5dd9a1ed5ddb90457ba6d5e5b380e7), will be released in v2.12.1 today