spring-cloud / spring-cloud/spring-cloud-openfeign
Optional request body should be supported by feign
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.3k
- Forks
- 838
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 13
Description
In Spring MVC it is possible to annotate body parameter as optional using @RequestBody(required = false) parameter annotation, e.g.:
@FeignClient("foo-service")
public interface FooService {
@RequestMapping(value = "/foo", method = RequestMethod.POST)
void doFoo(@RequestBody(required = false) FilterDto filter);
}
However, Spring-Feign contract does not consider the optionality flag which leads to an IllegalStateException on proxy bootstrapping in consumer when calling something like:
fooService.doFoo(null);
java.lang.IllegalArgumentException: Body parameter 0 was null
at feign.Util.checkArgument(Util.java:102)
at feign.ReflectiveFeign$BuildEncodedTemplateFromArgs.resolve(ReflectiveFeign.java:323)
at feign.ReflectiveFeign$BuildTemplateByResolvingArgs.create(ReflectiveFeign.java:213)
at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:72)
at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:103)
It is expected that null can be passed as parameter since it is optional.
Using:
- spring-cloud-starter-feign:1.1.0.RELEASE
- feign-core:8.16.2
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 by tracing the Spring-Feign contract handling of @RequestBody(required = false), then inspect the failure path in feign/ReflectiveFeign.java shown in the stack trace. Reproduce the FooService example with a null body and verify that optional request bodies no longer fail during template resolution.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100