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] [okhttp-gson] Update OkHttp to version 3.x #9632

Closed
wants to merge 2 commits into from

Conversation

nicktrav
Copy link

@nicktrav nicktrav commented Aug 11, 2019

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.

Description of the PR

The current implementation of the okhttp-gson client uses OkHttp 2.x as
the underlying client. This library was superseded by version 3.x in
early 2016. Version 3.x of the library is still under active
development.

Update codegen templates for okhttp-gson to use version 3.x of the
OkHttp client library.

Closes #9606.

The current implementation of the okhttp-gson client uses OkHttp 2.x as
the underlying client. This library was superseded by version 3.x in
early 2016. Version 3.x of the library is still under active
development.

Update codegen templates for okhttp-gson to use version 3.x of the
OkHttp client library.

Signed-off-by: Nick Travers <n.e.travers@gmail.com>
@nicktrav
Copy link
Author

cc: @frantuma

@nicktrav
Copy link
Author

This is a first pass at porting to OkHttp 3.x.

Please let me know if it makes sense to have this in a completely separate package. The changes aren't too invasive (only one new public method was added), but as mentioned on #9606, this is technically a breaking change as the underlying okhttp package name changed to com.squareup.okhttp3, which changes the signatures on the APIs.

There were some seemingly unrelated changes to some files after running the ./bin/security/java-petstore-okhttp-gson.sh (probably due to changes not being checked in in the past).

Unit tests in samples/client/petstore/java/okhttp-gson and samples/client/petstore-security-test/java/okhttp-gson compile and pass. Not sure if there are any other tests that need updating.

@@ -2,10 +2,20 @@

package {{invokerPackage}};

import com.squareup.okhttp.*;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Google styleguide discourages wildcards:
https://google.github.io/styleguide/javaguide.html#s3.3.1-wildcard-imports

If it's preferable to use wildcards from a codegen perspective, I can revert.

@@ -454,7 +468,9 @@ public class ApiClient {
* @return Api client
*/
public ApiClient setConnectTimeout(int connectionTimeout) {
httpClient.setConnectTimeout(connectionTimeout, TimeUnit.MILLISECONDS);
httpClient = httpClient.newBuilder()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One notable change in version 3.x is that a client cannot be modified after it has been created. The alternative is to create a new client by converting back to a builder, modifying the relevant fields and the instantiating a new client. I've adopted this pattern throughout, where client mutations need to take place.

compile 'com.google.code.gson:gson:2.8.1'
compile 'io.gsonfire:gson-fire:1.8.0'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some additional changes in petstore-security-test that don't seem related to the OkHttp 3.x change. I'm guessing something wasn't updated in a previous commit.

Signed-off-by: Nick Travers <n.e.travers@gmail.com>
@nicktrav
Copy link
Author

Bumping this. Would someone be able to help me out with finding a reviewer? cc: @wing328

@autodidacticon
Copy link

You might try submitting this here:
https://github.com/OpenAPITools/openapi-generator

@kgrosvenor
Copy link

Could someone point out to me how you generate okhttp v3? I always get 2.7.5?

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

Successfully merging this pull request may close these issues.

[Java] [okhttp-gson] Updating OkHttp to version 3.x
3 participants