Do not apply content-type header if no request body#6648
Do not apply content-type header if no request body#6648wing328 merged 7 commits intoswagger-api:masterfrom bmordue:fix-6647
Conversation
| } | ||
| //only add content-Type if its no a GET-Method | ||
| if(path.getGet() != null || ! operation.equals(path.getGet())){ | ||
| if (hasBodyParameters){ |
There was a problem hiding this comment.
@bmordue shall we keep the logic path.getGet() != null || ! operation.equals(path.getGet()) ?
For POST using HTTP form (not JSON/XML string), we also need the content-type right?
There was a problem hiding this comment.
Thanks, I've made sure the default content-type for form data gets applied too.
I don't think the original logic was correct: any path that includes a GET operation would have a default content-type applied, which doesn't seem right. I've added some tests that demonstrate this (ac79987).
|
Please run |
|
Apologies for my slow reply, I've been travelling. I ran the update script and committed the changes. |
|
@wing328 Is it normal that this generator use "gson" ? AFAIK, most if not all generator here use jackson? |
|
cc @davidgri for review as well since the previous if-condition has been revised. |
|
@JFCote Java Feign client uses jackson: |
| private OffsetDateTimeTypeAdapter offsetDateTimeTypeAdapter = new OffsetDateTimeTypeAdapter(); | ||
| private LocalDateTypeAdapter localDateTypeAdapter = new LocalDateTypeAdapter(); | ||
|
|
||
| public static GsonBuilder createGson() { |
There was a problem hiding this comment.
@wing328 I'm talking about this. You can see use of Gson in other modifier files too.
There was a problem hiding this comment.
The retrofit generator does use gson. I guess this change is due to regenerating all the Java samples.
|
If no further question or feedback on this, I'll merge it on coming Monday/Tuesday. |
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
The intent is to avoid adding a Content-Type header on requests made by a generated Java-feign client if the request body is empty. This is to fix #6647
contentTypefor requests that have no body params specified.@Headersannotation for "Content-Type" ifcontentTypeis not set.