[JAVA][Client] New object instead of null for empty POST request#7551
[JAVA][Client] New object instead of null for empty POST request#7551bmordue wants to merge 3 commits intoswagger-api:masterfrom bmordue:new-object-empty-request
Conversation
There was a problem hiding this comment.
I've commented on a couple of things but I find very odd that there are sooooooo much files that changed and that most of the changes are not linked to your changes. @wing328 , is this something normal?
Also, I'm not sure that replacing null by new Object is a good practice. @bmordue , do you have any documentation backing the fact that it's safer or a good practice?
|
|
||
| ext { | ||
| swagger_annotations_version = "1.5.17" | ||
| swagger_annotations_version = "1.5.15" |
There was a problem hiding this comment.
why reverting to this version?
| resolvers += Resolver.mavenLocal, | ||
| libraryDependencies ++= Seq( | ||
| "io.swagger" % "swagger-annotations" % "1.5.17", | ||
| "io.swagger" % "swagger-annotations" % "1.5.15", |
There was a problem hiding this comment.
why reverting to this version?
| <properties> | ||
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| <swagger-core-version>1.5.18</swagger-core-version> | ||
| <swagger-core-version>1.5.15</swagger-core-version> |
There was a problem hiding this comment.
why reverting to this version?
|
|
||
| ext { | ||
| swagger_annotations_version = "1.5.17" | ||
| swagger_annotations_version = "1.5.15" |
There was a problem hiding this comment.
same question everywhere... i will not mark every places
|
@JFCote there was a use case before in which the POST operation allows empty body (in other words, the body parameter is optional), and the API server will create an object automatically and return it back to the client. |
|
@JFCote Thanks for your feedback. I had a read through the HTTP spec and couldn't see anything that states that POST (or PUT) requests must have a request body. I also found this thread on the IETF mailing list about a similar question: http://lists.w3.org/Archives/Public/ietf-http-wg/2010JulSep/0272.html In my specific case, the entity that is being POSTed is described by header and query parameters, which is why there's no body in the request. From my point of view, part of the problem is that swagger-codegen applies a "Content-Type: application/json" header if none is specified. This means that my service is attempting to parse an empty body as JSON, and fails. The two approaches to resolve this with a generated client seem to be either don't apply the content-type header, or make sure that the request body is parseable as JSON even if I don't have data to send in the body. The second approach seemed to require fewer changes in swagger-codegen with potentially wide effect. |
|
@wing328 @bmordue I understand better now! Thanks for the clarification. You changes looked good but I wasn't sure about all the generated samples with what looked like regression. Maybe it's because samples didn't get updated in a while but I found strange that the version are going back. Maybe we should wait for another reviewer to validate. |
|
@bmordue CircleCI reports the following issues with updated samples: Please take a look when you've time. |
PR checklist
./bin/to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.shand./bin/security/{LANG}-petstore.shif 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\.3.0.0branch for changes related to OpenAPI spec 3.0. Default:master.Description of the PR
It's safer to initialize the request body to an empty
Objectinstead ofnullif 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.cc @bbdouglas @JFCote @sreeshas @jfiala @lukoyanov @cbornet @jeff9finger