-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[BUG][JAVA][Client] Regression: Unconditionally sends empty object request body #3276
Comments
👍 Thanks for opening this issue! The team will review the labels and make any necessary changes. |
Thank you a lot for this issue! I did a review while working on a test suite for the Java clients (more to come in #689) With
I agree that For resteasy:
As far as I can tell, the other clients are OK |
Your PR looks great @jmini, thanks for taking the time to work through it and implement a fix! Note that it doesn't fix the empty object request body for Thanks again! |
Of course.
I can have a look at this too. I am trying to understand the original motivation in #98, but I do not get it (I must admit that I did not dig into the history as you did).
I must admit that now that I have a test-suite (see details in #689 (comment)), I am much more confident with these kind of changes. I have the proof that there is an improvement (and no regression). |
I agree with that. And this might be the problematic point back then (I think Jackson was updated in-between). I guess I have found how to formulate the expected behavior when no
=> This |
Thanks for the additional investigation @jmini! I agree about the test suite. Great addition! I would expect most request libraries have a way to make a request without a body (e.g. Sending Thanks again! |
I am speaking from the expectation at test suite level, the library should take care of this stuff. The code generated by OpenAPI-Generator is just about using the HTTP-Library in an correct & opinionated way (this is more or less the role of |
IMO and according to my tests, the Lines 1084 to 1091 in 10a310e
So it is safe to set |
This comment has been minimized.
This comment has been minimized.
I found an other issue with When the request body is not defined in the OpenAPI Spec, the generated code is: Line 99 in 10a310e
This is wrong, the request send to the server is:
The solution is the instantiate a |
Looks great @jmini. Thanks so much for all of your effort on this! |
Bug Report Checklist
Description
The java
okhttp-gson
client (and likely other Java clients) always send an empty object in the request body forDELETE
(and likelyPOST
andPUT
) operations which do not definerequestBody
. SinceDELETE
request payload has no defined semantics this is likely to cause compatibility issues (and causes 4XX responses from the API I am working with).openapi-generator version
The issue first appeared in 0fb1ffa (#98) and still occurs on
master
(0cb9212).OpenAPI declaration file content or url
(Note: At least one schema must be defined for the generated code to compile, so I added
Error
for this purpose.)Command line used for generation
openapi-generator-cli.jar generate -i openapi.yaml -g java -o openapi-generator-test-client
Steps to reproduce
example.com/api
with a test server.src/main/java/TestApp.java
with contentgradle -DmainClass=TestApp execute
and observe traffic on the test server.The client generated from code before 0fb1ffa will send:
The client generated with 0fb1ffa or later will send:
Suggest a fix
This was fixed for resttemplate by #605 but not for
jersey2
,okhttp-gson
, orresteasy
. Reverting 0fb1ffa for the other clients would fix this, but presumably reintroduce #98 (although I'm not sure why Jackson would be called to serializenull
, presumably we could just stop doing that).Thoughts from the participants on #98 and #605? @bmordue, @jmini, @rubms
The text was updated successfully, but these errors were encountered: