OpenAPITools / OpenAPITools/openapi-generator

[BUG][Java Client][Feign] Request headers are sent in body

Open
#6,069 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

Generated Feign client methods use wrong parameter names. This causes headers to be sent in request body.

Method generated by the definition provided below looks like this:

  @RequestLine("POST /resource")
  @Headers({
    "Accept: */*",
    "X-Correlation-ID: {xCorrelationID}",
    
    "X-Request-ID: {xRequestID}"
  })
  Object createResource(@Param("X-Correlation-ID") String xCorrelationID, @Param("X-Request-ID") String xRequestID);

And according to OpenFeign docs it should look like this:

  @RequestLine("POST /resource")
  @Headers({
    "Accept: */*",
    "X-Correlation-ID: {xCorrelationID}",
    
    "X-Request-ID: {xRequestID}"
  })
  Object createResource(@Param("xCorrelationID") String xCorrelationID, @Param("xRequestID") String xRequestID);

Note the difference between the @Param annotation values.

openapi-generator version

3.4.0

OpenAPI declaration file content or url

LINK

Command line used for generation
<plugin>
  <groupId>org.openapitools</groupId>
  <artifactId>openapi-generator-maven-plugin</artifactId>
  <version>4.3.0</version>
  <executions>
    <execution>
      <goal>generate</goal>
      <configuration>
        <inputSpec>${project.basedir}/src/main/resources/api/@item@.json</inputSpec>
        <generatorName>java</generatorName>
        <output>target/generated-sources</output>
        <apiPackage>com.company.api</apiPackage>
        <modelPackage>com.company.model</modelPackage>
        <skipValidateSpec>true</skipValidateSpec>
        <generateApis>true</generateApis>
        <generateApiDocumentation>false</generateApiDocumentation>
        <generateSupportingFiles>true</generateSupportingFiles>
        <generateModels>true</generateModels>
        <generateModelTests>false</generateModelTests>
        <generateModelDocumentation>false</generateModelDocumentation>
        <configOptions>
          <sourceFolder>swagger</sourceFolder>
          <java8>true</java8>
          <interfaceOnly>false</interfaceOnly>
          <dateLibrary>java8-localdatetime</dateLibrary>
          <library>feign</library>
          <hideGenerationTimestamp>true</hideGenerationTimestamp>
          <serializableModel>true</serializableModel>
          <invokerPackage>com.company</invokerPackage>
          <allowUnicodeIdentifiers>true</allowUnicodeIdentifiers>
        </configOptions>
      </configuration>
    </execution>
  </executions>
</plugin>

Steps to reproduce

Just generate client code and try to sent a request.

Related issues/PRs

This bug was introduced in 4.2.3 as a result of fixing #3295 (pull request #4883)

Suggest a fix

Reverse the above-mentioned or find a better way of generating headers in the mustache template.

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 the Java Feign mustache template responsible for generated @Param annotations, then compare the regression described from #3295 and #4883. Reproduce using the linked gist and Maven configuration. Done means generated @Param values match the Java parameter names so Feign sends headers as headers rather than in the request body.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.