Skip to content

Commit bd705a4

Browse files
committed
Merge pull request #3094 from karussell/patch-3
[Java] client: make all okhttp classes explicit to avoid conflict
2 parents a965b74 + 32cabcf commit bd705a4

File tree

5 files changed

+132
-147
lines changed

5 files changed

+132
-147
lines changed

modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/api.mustache

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ import {{invokerPackage}}.ProgressResponseBody;
1313

1414
import com.google.gson.reflect.TypeToken;
1515

16-
import com.squareup.okhttp.Call;
17-
import com.squareup.okhttp.Interceptor;
18-
1916
import java.io.IOException;
2017

2118
{{#imports}}import {{import}};
@@ -51,7 +48,7 @@ public class {{classname}} {
5148

5249
{{#operation}}
5350
/* Build call for {{operationId}} */
54-
private Call {{operationId}}Call({{#allParams}}{{{dataType}}} {{paramName}}, {{/allParams}}final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
51+
private com.squareup.okhttp.Call {{operationId}}Call({{#allParams}}{{{dataType}}} {{paramName}}, {{/allParams}}final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
5552
Object {{localVariablePrefix}}localVarPostBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};
5653
{{#allParams}}{{#required}}
5754
// verify the required parameter '{{paramName}}' is set
@@ -89,9 +86,9 @@ public class {{classname}} {
8986
{{localVariablePrefix}}localVarHeaderParams.put("Content-Type", {{localVariablePrefix}}localVarContentType);
9087

9188
if(progressListener != null) {
92-
apiClient.getHttpClient().networkInterceptors().add(new Interceptor() {
89+
apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
9390
@Override
94-
public com.squareup.okhttp.Response intercept(Interceptor.Chain chain) throws IOException {
91+
public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException {
9592
com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
9693
return originalResponse.newBuilder()
9794
.body(new ProgressResponseBody(originalResponse.body(), progressListener))
@@ -124,7 +121,7 @@ public class {{classname}} {
124121
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
125122
*/
126123
public ApiResponse<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}> {{operationId}}WithHttpInfo({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException {
127-
Call {{localVariablePrefix}}call = {{operationId}}Call({{#allParams}}{{paramName}}, {{/allParams}}null, null);
124+
com.squareup.okhttp.Call {{localVariablePrefix}}call = {{operationId}}Call({{#allParams}}{{paramName}}, {{/allParams}}null, null);
128125
{{#returnType}}Type {{localVariablePrefix}}localVarReturnType = new TypeToken<{{{returnType}}}>(){}.getType();
129126
return {{localVariablePrefix}}apiClient.execute({{localVariablePrefix}}call, {{localVariablePrefix}}localVarReturnType);{{/returnType}}{{^returnType}}return {{localVariablePrefix}}apiClient.execute({{localVariablePrefix}}call);{{/returnType}}
130127
}
@@ -137,7 +134,7 @@ public class {{classname}} {
137134
* @return The request call
138135
* @throws ApiException If fail to process the API call, e.g. serializing the request body object
139136
*/
140-
public Call {{operationId}}Async({{#allParams}}{{{dataType}}} {{paramName}}, {{/allParams}}final ApiCallback<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}> {{localVariablePrefix}}callback) throws ApiException {
137+
public com.squareup.okhttp.Call {{operationId}}Async({{#allParams}}{{{dataType}}} {{paramName}}, {{/allParams}}final ApiCallback<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}> {{localVariablePrefix}}callback) throws ApiException {
141138
142139
ProgressResponseBody.ProgressListener progressListener = null;
143140
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
@@ -158,7 +155,7 @@ public class {{classname}} {
158155
};
159156
}
160157

161-
Call {{localVariablePrefix}}call = {{operationId}}Call({{#allParams}}{{paramName}}, {{/allParams}}progressListener, progressRequestListener);
158+
com.squareup.okhttp.Call {{localVariablePrefix}}call = {{operationId}}Call({{#allParams}}{{paramName}}, {{/allParams}}progressListener, progressRequestListener);
162159
{{#returnType}}Type {{localVariablePrefix}}localVarReturnType = new TypeToken<{{{returnType}}}>(){}.getType();
163160
{{localVariablePrefix}}apiClient.executeAsync({{localVariablePrefix}}call, {{localVariablePrefix}}localVarReturnType, {{localVariablePrefix}}callback);{{/returnType}}{{^returnType}}{{localVariablePrefix}}apiClient.executeAsync({{localVariablePrefix}}call, {{localVariablePrefix}}callback);{{/returnType}}
164161
return {{localVariablePrefix}}call;

samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/FakeApi.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@
3636

3737
import com.google.gson.reflect.TypeToken;
3838

39-
import com.squareup.okhttp.Call;
40-
import com.squareup.okhttp.Interceptor;
41-
4239
import java.io.IOException;
4340

4441
import java.util.Date;
@@ -70,7 +67,7 @@ public void setApiClient(ApiClient apiClient) {
7067
}
7168

7269
/* Build call for testEndpointParameters */
73-
private Call testEndpointParametersCall(BigDecimal number, Double _double, String string, byte[] _byte, Integer integer, Integer int32, Long int64, Float _float, byte[] binary, Date date, Date dateTime, String password, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
70+
private com.squareup.okhttp.Call testEndpointParametersCall(BigDecimal number, Double _double, String string, byte[] _byte, Integer integer, Integer int32, Long int64, Float _float, byte[] binary, Date date, Date dateTime, String password, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
7471
Object localVarPostBody = null;
7572

7673
// verify the required parameter 'number' is set
@@ -140,9 +137,9 @@ private Call testEndpointParametersCall(BigDecimal number, Double _double, Strin
140137
localVarHeaderParams.put("Content-Type", localVarContentType);
141138

142139
if(progressListener != null) {
143-
apiClient.getHttpClient().networkInterceptors().add(new Interceptor() {
140+
apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
144141
@Override
145-
public com.squareup.okhttp.Response intercept(Interceptor.Chain chain) throws IOException {
142+
public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException {
146143
com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
147144
return originalResponse.newBuilder()
148145
.body(new ProgressResponseBody(originalResponse.body(), progressListener))
@@ -195,7 +192,7 @@ public void testEndpointParameters(BigDecimal number, Double _double, String str
195192
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
196193
*/
197194
public ApiResponse<Void> testEndpointParametersWithHttpInfo(BigDecimal number, Double _double, String string, byte[] _byte, Integer integer, Integer int32, Long int64, Float _float, byte[] binary, Date date, Date dateTime, String password) throws ApiException {
198-
Call call = testEndpointParametersCall(number, _double, string, _byte, integer, int32, int64, _float, binary, date, dateTime, password, null, null);
195+
com.squareup.okhttp.Call call = testEndpointParametersCall(number, _double, string, _byte, integer, int32, int64, _float, binary, date, dateTime, password, null, null);
199196
return apiClient.execute(call);
200197
}
201198

@@ -218,7 +215,7 @@ public ApiResponse<Void> testEndpointParametersWithHttpInfo(BigDecimal number, D
218215
* @return The request call
219216
* @throws ApiException If fail to process the API call, e.g. serializing the request body object
220217
*/
221-
public Call testEndpointParametersAsync(BigDecimal number, Double _double, String string, byte[] _byte, Integer integer, Integer int32, Long int64, Float _float, byte[] binary, Date date, Date dateTime, String password, final ApiCallback<Void> callback) throws ApiException {
218+
public com.squareup.okhttp.Call testEndpointParametersAsync(BigDecimal number, Double _double, String string, byte[] _byte, Integer integer, Integer int32, Long int64, Float _float, byte[] binary, Date date, Date dateTime, String password, final ApiCallback<Void> callback) throws ApiException {
222219

223220
ProgressResponseBody.ProgressListener progressListener = null;
224221
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
@@ -239,7 +236,7 @@ public void onRequestProgress(long bytesWritten, long contentLength, boolean don
239236
};
240237
}
241238

242-
Call call = testEndpointParametersCall(number, _double, string, _byte, integer, int32, int64, _float, binary, date, dateTime, password, progressListener, progressRequestListener);
239+
com.squareup.okhttp.Call call = testEndpointParametersCall(number, _double, string, _byte, integer, int32, int64, _float, binary, date, dateTime, password, progressListener, progressRequestListener);
243240
apiClient.executeAsync(call, callback);
244241
return call;
245242
}

0 commit comments

Comments
 (0)