[Java][google-api-client] Fix bug with empty POST request not sending content-type #7787
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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\
.3.0.0
branch for changes related to OpenAPI spec 3.0. Default:master
.Java technical committee - @bbdouglas (2017/07) @JFCote (2017/08) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01)
Description of the PR
Fixes #7786
This PR basically fixes a few issues with the
google-api-client
templates.The biggest issue is POST requests for endpoints that send empty request bodies are failing with a 415 status code (Unsupported Media Type) because the
Content-Type: application/json
isn't being sent in this case.A good example would be -- in our APIs we have lifecycle operations such as
POST /foo/{id}/publish
orPOST /foo/{id}/pause
which transition some entity to a different state, but no request body is required since we are simply indicating that apublish
is taking place.This PR also fixes a few random issues with the templates:
List<String>
orList<Object>
of any kind.Object[]
to theUriBuilder
in the generated code.java.io.InputStream
as the request body.text/csv
type).Test Plan
./bin/java-petstore-google-api-client.sh
mvn clean test
in thesamples/client/petstore/java/google-api-client
directory and it succeededgoogle-api-client
client for a complex API with the new codegen code. I have verified that empty POST requests now work, list query params now work, and input streams work for the request body if the overloaded method is used.