Skip to content

RequestTemplateFactoryResolver throws IllegalArgumentException for non required parameters #2039

@Ragin-LundF

Description

@Ragin-LundF

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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    feedback providedFeedback has been provided to the authorspring-cloudIssues related to Spring Cloud OpenFeign

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions