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-client][okhttp-gson] fixes for interceptors in ApiClient.java #3502

Merged
merged 2 commits into from
Aug 1, 2019
Merged

[java-client][okhttp-gson] fixes for interceptors in ApiClient.java #3502

merged 2 commits into from
Aug 1, 2019

Conversation

lostiniceland
Copy link
Contributor

@lostiniceland lostiniceland commented Jul 30, 2019

ApiClient for Okhttp3 must not copy the interceptors when setting the HttpClient.

fixes #3497

@@ -335,7 +335,7 @@ public void testInterceptorCleanupWithNewClient() {
OkHttpClient oldClient = apiClient.getHttpClient();
assertEquals(1, oldClient.networkInterceptors().size());

OkHttpClient newClient = new OkHttpClient();
OkHttpClient newClient = apiClient.getHttpClient().newBuilder().build();
Copy link
Member

Choose a reason for hiding this comment

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

CircleCI reports that this change gets overridden when the samples are updated:

diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/ApiClientTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/ApiClientTest.java
index 3675d8645a..6181e8afa2 100644
--- a/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/ApiClientTest.java
+++ b/samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/ApiClientTest.java
@@ -335,7 +335,7 @@ public class ApiClientTest {
         OkHttpClient oldClient = apiClient.getHttpClient();
         assertEquals(1, oldClient.networkInterceptors().size());
 
-        OkHttpClient newClient = apiClient.getHttpClient().newBuilder().build();
+        OkHttpClient newClient = new OkHttpClient();
         apiClient.setHttpClient(newClient);
         assertEquals(1, apiClient.getHttpClient().networkInterceptors().size());
         apiClient.setHttpClient(newClient);

This is because the source for this file is in the CI/samples.ci folder. Can you update this file:

@jmini jmini changed the title fixes OpenAPITools/openapi-generator#3497 [java-client][okhttp-gson] fixes for interceptors in ApiClient.java Jul 31, 2019
Copy link
Member

@jmini jmini left a comment

Choose a reason for hiding this comment

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

@lostiniceland: Thank you a lot for this PR. It looks great.

Can you also change the mentioned file?

ApiClient for Okhttp3 must not copy the interceptors when setting the HttpClient.
@lostiniceland
Copy link
Contributor Author

Updated as requested by review.

I would argue though that the Tests I've fixed are not very usefull at all. They might have been with the old "logic" but now the tested method is a plain setter, except the check for equality, which could also be removed.
A usefull invariant would be that the passed client must not be null, because the ApiClient cannot function without a httpClient.

@lostiniceland
Copy link
Contributor Author

@jmini I've added another commit which contains the mentioned invariant and removed the unnecessary tests

Enforce invariant that the HttpClient must never be null.
@wing328
Copy link
Member

wing328 commented Jul 31, 2019

Thanks for the PR but your commit (as shown in the Commits tab) is not linked to your Github account, which means this PR won't count as your contribution in https://github.com/OpenAPITools/openapi-generator/graphs/contributors.

Let me know if you need help fixing it.

Ref: https://github.com/OpenAPITools/openapi-generator/wiki/FAQ#how-can-i-update-commits-that-are-not-linked-to-my-github-account

@lostiniceland
Copy link
Contributor Author

@wing328 thanks for pointing that out. I've added my work-email to Github so it should match now.

Copy link
Member

@jmini jmini left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you for the change.

@jmini jmini merged commit 0a7527b into OpenAPITools:master Aug 1, 2019
@wing328 wing328 added this to the 4.1.0 milestone Aug 1, 2019
@lostiniceland lostiniceland deleted the bugfix/issue-3497 branch August 1, 2019 06:52
@wing328
Copy link
Member

wing328 commented Aug 10, 2019

@lostiniceland thanks for the PR, which has been included in the 4.1.0 release: https://twitter.com/oas_generator/status/1160000504455319553

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.

[BUG] [JAVA] okhttp-gson generates broken method in ApiClient.java
4 participants