spring-cloud / spring-cloud/spring-cloud-openfeign
feignclient does not support non-required path variables
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.3k
- Forks
- 838
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 13
Description
SpringCloud - 2.2.1
Issue Description -
I'm extending controller from another service using @FeignClient -
@FeignClient(name = "<NAME>", url = "<URL>")
public interface IMyController extends IFromAnotherServiceController {
}
in the other controller I have the following api definition -
@ApiOperation(value = "", nickname = "getSomething")
@ApiResponse(code = 200, message = "")
@GetMapping(path= {"/api/get-something/a/{a}",
"/api/get-something/a/{a}/b/{b}",
"/api/get-something/a/{a}/b/{b}/c/{c}"})
SomeDto getSomething(@PathVariable(name = "a") String a,
@PathVariable(required = false, name = "b") String b
@PathVariable(required = false, name = "c") String c);
So i have only 1 path variable which is required, other 2 are optional.
I use this method getSomething in my code with 3 parameters this way :
client.getSomething(x, y, z); (while client is of type IMyController)
And when I try to start the application, I get the following error -
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '...IFromAnotherServiceController ': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: Method getSomething can only contain at most 1 value field. Found: [/api/get-something/a/{a}, /api/get-something/a/{a}/b/{b}, /api/get-something/a/{a}/b/{b}/c/{c}]
Any idea what configuration am I missing? Why it enables me to call this method with 3 arguments but then at the start up it throws exception that i can use only 1?
Thanks!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the inherited @GetMapping and the @FeignClient interface shown in the issue, then reproduce application startup with the three alternative paths and optional path variables. Trace the Feign contract parsing that reports multiple path values. Done means the client can be created without the BeanCreationException and the three-argument method remains usable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100