RequestTemplateFactoryResolver throws IllegalArgumentException for non required parameters
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.8k
- Forks
- 1.9k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 41
Description
We wanted to add headers, which are meant to transport an URI.
The RequestTemplateFactoryResolver (or the ReflectiveFeign class before) throws an exception if an optional (required=false in the annotation/OpenAPI + nullable=true in the OpenAPI) header was not set and if the header is from type URI.
The reason is the metaData.urlIndex, which was created in the Contract.parseAndValidateMetadata() method:
// Line 137
if (parameterTypes[i] == URI.class) {
data.urlIndex(i);
The generated client class for Feign looks like this:
@PostMapping(
value = "/dummy/test",
produces = {"application/json"},
consumes = {"application/json"})
DummyResponseModel createDummyExample(
@RequestHeader(value = "FIRST_MANDATORY", required = true) String first,
@RequestHeader(value = "SECO_MANDATORY", required = true) String second,
@RequestHeader(value = "THIRD_MANDATORY", required = true) String third,
@Valid @RequestBody MyBodyModel bodyModel,
@RequestHeader(value = "OPT_FIRST", required = false) String optFirst,
@RequestHeader(value = "OPT_SEC", required = false) URI optSec,
@RequestHeader(value = "OPT_THIRD", required = false) URI optThird);
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 Contract.parseAndValidateMetadata(), especially the URI handling at the cited line, then trace how metaData.urlIndex is used by RequestTemplateFactoryResolver and ReflectiveFeign. Reproduce the generated-client case with an omitted optional URI header and verify that it no longer throws IllegalArgumentException while required parameters still behave as before.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100