Skip to content
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][google-api-client] Fix bug with empty POST request not sending content-type #7787

Merged

Conversation

charlescapps
Copy link
Contributor

@charlescapps charlescapps commented Mar 7, 2018

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./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\.
  • Filed the PR against the correct branch: 3.0.0 branch for changes related to OpenAPI spec 3.0. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

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 or POST /foo/{id}/pause which transition some entity to a different state, but no request body is required since we are simply indicating that a publish is taking place.

This PR also fixes a few random issues with the templates:

  • They were failing for query params declared as List<String> or List<Object> of any kind.
    • => fixed this by sending an Object[] to the UriBuilder in the generated code.
  • Added an overloaded method to use a java.io.InputStream as the request body.
    • This is incredibly useful for proxy services that forward data, and allows us to use some non-JSON APIs that we have with the swagger client (e.g. text/csv type).

Test Plan

  • Generated samples with ./bin/java-petstore-google-api-client.sh
  • Did mvn clean test in the samples/client/petstore/java/google-api-client directory and it succeeded
  • I have tested this thoroughly before putting up this PR by generating a google-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.

@charlescapps
Copy link
Contributor Author

Travis failed on some unrelated Python thing, I'm guessing this is a known issue: ERROR: InvocationError: '/home/travis/build/swagger-api/swagger-codegen/samples/client/petstore/python-tornado/.tox/py3/bin/nosetests'

@wing328
Copy link
Contributor

wing328 commented Mar 8, 2018

The Travis build error is likely due to a change in the build image. I'll look into it tomorrow.

Thanks for the fix.

@wing328 wing328 merged commit 4eeb974 into swagger-api:master Mar 8, 2018
@wing328 wing328 modified the milestones: Future, v2.4.0 Mar 8, 2018
@charlescapps
Copy link
Contributor Author

Thanks @wing328 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Java][google-api-client] Empty POST requests don't send content type; List type query params
2 participants