OpenFeign / OpenFeign/feign

RequestTemplateFactoryResolver throws IllegalArgumentException for non required parameters

Open
#2,039 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feedback provided spring-cloud
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.