OpenAPITools / OpenAPITools/openapi-generator
[BUG][JAVA] Java-Jersey2 generator creates "Accept:null" header
Nobody has claimed this yet.
- 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
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 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