-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[JAVA][Client] New object instead of null for empty POST request #98
Conversation
Because the "ci/circleci" if failing for some download failed errors:
I have tried to run the java sample locally. This is not working for me:
I get these compile errors:
The reset-assured project on Because of the review delay (sorry about that), can you also merge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please have a look at the compile errors that are created in the samples/
folder
@@ -623,146 +623,146 @@ public TestEndpointParametersOper(RequestSpecBuilder reqSpec) { | |||
return handler.apply(RestAssured.given().spec(reqSpec.build()).expect().spec(respSpec.build()).when().request(POST, REQ_URI)); | |||
} | |||
|
|||
public static final String INTEGER_FORM = "integer"; | |||
public static final String _FORM = "integer"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This produces compile errors
By the way to test locally all java clients, I am using a pom file that looks like this: <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>tmp</groupId>
<artifactId>tmp-build-root</artifactId>
<packaging>pom</packaging>
<version>1.0.0-SNAPSHOT</version>
<modules>
<module>samples/client/petstore/java/feign/</module>
<module>samples/client/petstore/java/google-api-client/</module>
<module>samples/client/petstore/java/jersey1/</module>
<module>samples/client/petstore/java/jersey2-java6/</module>
<module>samples/client/petstore/java/jersey2-java8/</module>
<module>samples/client/petstore/java/jersey2/</module>
<module>samples/client/petstore/java/okhttp-gson-parcelableModel/</module>
<module>samples/client/petstore/java/okhttp-gson/</module>
<module>samples/client/petstore/java/rest-assured/</module>
<module>samples/client/petstore/java/resteasy/</module>
<module>samples/client/petstore/java/resttemplate-withXml/</module>
<module>samples/client/petstore/java/resttemplate/</module>
<module>samples/client/petstore/java/retrofit/</module>
<module>samples/client/petstore/java/retrofit2-play24/</module>
<module>samples/client/petstore/java/retrofit2/</module>
<module>samples/client/petstore/java/retrofit2rx/</module>
<module>samples/client/petstore/java/retrofit2rx2/</module>
</modules>
</project> |
Thanks @jmini |
I see this in the logs:
@bmordue: what is your workflow when you create the commit "Ran bin/java-petstore-all.sh again". It is not documented, but it should be:
Then the check in Shippable will be OK. |
…rator into new-object-empty-request
Commit c30afdf fixes the Shippable build. Can you please merge |
I have merged |
* master: Add 'unblu inc.' to company list (OpenAPITools#246) put company list in alphabetical order (OpenAPITools#244) [jaxrs-spec] generate spec file (yaml) correctly (OpenAPITools#243) [C++] Adjust the names (script, sample folder, generator) to lang option (OpenAPITools#220) Add GMO Pepabo to company list (OpenAPITools#242) [Spring] Add apiFirst option (OpenAPITools#184) [cli] Write to stdout/stderr, allow redirection (OpenAPITools#207) [JAVA][Client] New object instead of null for empty POST request (OpenAPITools#98) Make yaml serialization deterministic (OpenAPITools#233) Add syntax highlighting to migration guide (OpenAPITools#237) Fix shippable badge (OpenAPITools#232) update company list (OpenAPITools#227) Fix OpenAPITools#210: [Ada] Update the code generator for required and optional parameters (OpenAPITools#211) Delete unused methods in DefaultCodegen (OpenAPITools#209) add note about maven plugins (OpenAPITools#216) add raiffeisen to company list (OpenAPITools#223) add a remark about homebrew installatio (OpenAPITools#217)
This pull request is causing an error, that originated issue #513: now an empty Object is being set as request body on every request (not only POST requests) and by default message converters don't know how to treat empty Objects, throwing the exception Before this pull request, when post objects were null by default, this error did not happen. |
@rubms I was about to write the same problem. By setting 'postBody' to 'new Object' the RestTemplate.doWithRequest() does not jump into the first if block in line 829. It now jumps into the block to where it tries to serialize the body (Within a GET request) |
I just created the #605 pull request in order to get this fixed. |
I'm concerned. Why aren't there tests to cover this? Simple GET/PUT/POST for every library should be mandatory! |
PR checklist
./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
and./bin/security/{LANG}-petstore.sh
if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\
.master
.Description of the PR
It's safer to initialize the request body to an empty Object instead of null if there are no body parameters. In particular, this allows Jackson to successfully serialize a POST request with no body parameters when the Content-Type header is set to "application/json, which is set by default.
See swagger-api/swagger-codegen#7551 for more context -- bringing this over to
openapi-generator
cc @bbdouglas @JFCote @sreeshas @jfiala @lukoyanov @cbornet @jeff9finger