OpenAPITools / OpenAPITools/openapi-generator

[BUG][JAVA] Java-Jersey2 generator creates "Accept:null" header

Open
#6,882 6 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

Description

I use Jersey2 as generator for my REST, including DELETE operations that don't "accept" any body.
As a result, I see that the generated code executes HTTP requests with header "Accept:null" that is not a valid header (because of "null" string).

openapi-generator version

I use openapi-generator-maven-plugin 4.2.3, but from what I see in source code this bug should be reproducible in the master too.

OpenAPI declaration file content or url
paths:
  /v2/something/{name}:
    delete:
      tags:
      - Repository
      summary: Delete something
      operationId: something_delete
      parameters:
      - name: paramone
        in: path
        required: true
        schema:
          type: string
      responses:
        "204":
          description: delete success or nothing to delete
        "401":
          description: not authenticated / invalid credentials
        "403":
          description: not authorized, the current user does not have the "repository"
            privilege
        "500":
          description: internal server error
Command line used for generation

pom.xml config:

                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>4.2.3</version>
...
                            <generatorName>java</generatorName>
                            <configOptions>
                                <java8>true</java8>
                                <library>jersey2</library>
                            </configOptions>
...
Steps to reproduce

See description, it's quite obvious.

Related issues/PRs

Not found

Suggest a fix

In file openapi-generator/src/main/resources/Java/libraries/jersey2/ApiClient.mustache change line from

Invocation.Builder invocationBuilder = target.request().accept(accept);

to

Invocation.Builder invocationBuilder = accept != null ? target.request().accept(accept) : target.request();

Also, need to check other generator for this problem.

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 in openapi-generator/src/main/resources/Java/libraries/jersey2/ApiClient.mustache and inspect how the Jersey2 client builds request headers for operations without response bodies. Generate the provided DELETE operation with the Java generator and verify that the resulting request does not send an Accept:null header; also check whether other generators contain the same pattern.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.