OpenAPITools / OpenAPITools/openapi-generator
[Bug][java][jersey2] POST without body sends content-type header not found in spec
Nobody has claimed this yet.
- 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)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
A server I do not control declares a POST endpoint that accepts no body.
The server is implemented in such a way that one of the following must be true of requests to the endpoint:
- the body must be non-blank, such as
{}, if acontent-type: application/jsonheader is sent - there can be no
content-typeheader if the body is empty.
Until now, I have been using an older version (v3.3.2) of openapi-generator which sent both the content-type header and an empty json-object body. The latest (v5.1.0) version sends the content-type header, but no longer sends a body (changed in commit: b06c8ecd696295a08abd4915cbbb173ae5429d8e ). Seeing the content-type header, the server attempts to parse the empty body as JSON and fails.
I believe I am able to work around this issue by overriding the ApiClient.mustache (see gist below), but it would be ideal if this worked out of the box.
openapi-generator version
v.5.1.0
OpenAPI declaration file content or url
openapi: 3.0.2
info:
title: Post Endpoint without content-type
version: 0.0.1
paths:
/foo:
post:
responses:
204:
description: success
Generation Details
Steps to reproduce
- Generate a Java / Jersey2 client for the endpoint above.
- Call the endpoint using the generated client.
- See that a ContentType header is sent, even though the spec does not declare that type as accepted.
- It is expected that no ContentType header is sent, since there is no content!
Related issues/PRs
https://github.com/OpenAPITools/openapi-generator/pull/3703
Suggest a fix
Update the default ApiClient.mustache template similarly to the changes in this gist (changes marked with "dwc"): https://gist.github.com/davidwcarlson/6c1796a2c72c1bb69ca658a0349e124f
It is also interesting that the value ofisBodyNullable is false for endpoints without declared body, probably because false is the default value of an uninitialized boolean.
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 with the default ApiClient.mustache template and the Java/Jersey2 generation steps described in the issue. Compare the generated request behavior with the older v3.3.2 output and the provided workaround. Done means a POST endpoint with no declared body does not send a Content-Type header or an empty body unexpectedly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100