Skip to content

Commit f409fb6

Browse files
authored
various improvements to java okhttp-gson client (#13794)
1 parent 232f354 commit f409fb6

File tree

97 files changed

+860
-1682
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+860
-1682
lines changed

modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ public class ApiClient {
179179
this.basePath = basePath;
180180
}
181181

182-
{{#hasOAuthMethods}}
183182
String tokenUrl = "{{{tokenUrl}}}";
184183
if (!"".equals(tokenUrl) && !URI.create(tokenUrl).isAbsolute()) {
185184
URI uri = URI.create(getBasePath());
@@ -196,7 +195,6 @@ public class ApiClient {
196195
retryingOAuth
197196
);
198197
initHttpClient(Collections.<Interceptor>singletonList(retryingOAuth));
199-
{{/hasOAuthMethods}}
200198
// Setup authentications (key: authentication name, value: authentication).{{#authMethods}}{{#isBasic}}{{#isBasicBasic}}
201199
authentications.put("{{name}}", new HttpBasicAuth());{{/isBasicBasic}}{{^isBasicBasic}}
202200
authentications.put("{{name}}", new HttpBearerAuth("{{scheme}}"));{{/isBasicBasic}}{{/isBasic}}{{#isApiKey}}

modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/additional_properties.mustache

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
/**
1010
* Set the additional (undeclared) property with the specified name and value.
1111
* If the property does not already exist, create it otherwise replace it.
12+
*
13+
* @param key name of the property
14+
* @param value value of the property
15+
* @return the {{classname}} instance itself
1216
*/
1317
public {{classname}} putAdditionalProperty(String key, Object value) {
1418
if (this.additionalProperties == null) {
@@ -20,13 +24,18 @@
2024

2125
/**
2226
* Return the additional (undeclared) property.
27+
*
28+
* @return a map of objects
2329
*/
2430
public Map<String, Object> getAdditionalProperties() {
2531
return additionalProperties;
2632
}
2733

2834
/**
2935
* Return the additional (undeclared) property with the specified name.
36+
*
37+
* @param key name of the property
38+
* @return an object
3039
*/
3140
public Object getAdditionalProperty(String key) {
3241
if (this.additionalProperties == null) {

modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/api.mustache

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,19 @@ public class {{classname}} {
193193

194194
{{/dynamicOperations}}
195195
final String[] localVarAccepts = {
196-
{{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}}
196+
{{#produces}}
197+
"{{{mediaType}}}"{{^-last}},{{/-last}}
198+
{{/produces}}
197199
};
198200
final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts);
199201
if (localVarAccept != null) {
200202
localVarHeaderParams.put("Accept", localVarAccept);
201203
}
202204

203205
final String[] localVarContentTypes = {
204-
{{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}}
206+
{{#consumes}}
207+
"{{{mediaType}}}"{{^-last}},{{/-last}}
208+
{{/consumes}}
205209
};
206210
final String localVarContentType = localVarApiClient.selectHeaderContentType(localVarContentTypes);
207211
if (localVarContentType != null) {
@@ -218,15 +222,16 @@ public class {{classname}} {
218222
@SuppressWarnings("rawtypes")
219223
private okhttp3.Call {{operationId}}ValidateBeforeCall({{#allParams}}{{{dataType}}} {{paramName}}, {{/allParams}}final ApiCallback _callback) throws ApiException {
220224
{{^performBeanValidation}}
221-
{{#allParams}}{{#required}}
225+
{{#allParams}}
226+
{{#required}}
222227
// verify the required parameter '{{paramName}}' is set
223228
if ({{paramName}} == null) {
224229
throw new ApiException("Missing the required parameter '{{paramName}}' when calling {{operationId}}(Async)");
225230
}
226-
{{/required}}{{/allParams}}
227231

228-
okhttp3.Call localVarCall = {{operationId}}Call({{#allParams}}{{paramName}}, {{/allParams}}_callback);
229-
return localVarCall;
232+
{{/required}}
233+
{{/allParams}}
234+
return {{operationId}}Call({{#allParams}}{{paramName}}, {{/allParams}}_callback);
230235

231236
{{/performBeanValidation}}
232237
{{#performBeanValidation}}
@@ -240,9 +245,7 @@ public class {{classname}} {
240245
parameterValues);
241246

242247
if (violations.size() == 0) {
243-
okhttp3.Call localVarCall = {{operationId}}Call({{#allParams}}{{paramName}}, {{/allParams}}_callback);
244-
return localVarCall;
245-
248+
return {{operationId}}Call({{#allParams}}{{paramName}}, {{/allParams}}_callback);
246249
} else {
247250
throw new BeanValidationException((Set) violations);
248251
}
@@ -253,7 +256,6 @@ public class {{classname}} {
253256
e.printStackTrace();
254257
throw new ApiException(e.getMessage());
255258
}
256-
257259
{{/performBeanValidation}}
258260
}
259261

samples/client/others/java/okhttp-gson-streaming/src/main/java/org/openapitools/client/api/PingApi.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,12 @@ private okhttp3.Call getPingCall(Long petId, String name, String status, final A
133133

134134
@SuppressWarnings("rawtypes")
135135
private okhttp3.Call getPingValidateBeforeCall(Long petId, String name, String status, final ApiCallback _callback) throws ApiException {
136-
137136
// verify the required parameter 'petId' is set
138137
if (petId == null) {
139138
throw new ApiException("Missing the required parameter 'petId' when calling getPing(Async)");
140139
}
141-
142140

143-
okhttp3.Call localVarCall = getPingCall(petId, name, status, _callback);
144-
return localVarCall;
141+
return getPingCall(petId, name, status, _callback);
145142

146143
}
147144

@@ -321,10 +318,7 @@ public okhttp3.Call postPingCall(SomeObj someObj, final ApiCallback _callback) t
321318

322319
@SuppressWarnings("rawtypes")
323320
private okhttp3.Call postPingValidateBeforeCall(SomeObj someObj, final ApiCallback _callback) throws ApiException {
324-
325-
326-
okhttp3.Call localVarCall = postPingCall(someObj, _callback);
327-
return localVarCall;
321+
return postPingCall(someObj, _callback);
328322

329323
}
330324

samples/client/petstore/java/okhttp-gson-dynamicOperations/src/main/java/org/openapitools/client/api/AnotherFakeApi.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,12 @@ public okhttp3.Call call123testSpecialTagsCall(Client body, final ApiCallback _c
143143

144144
@SuppressWarnings("rawtypes")
145145
private okhttp3.Call call123testSpecialTagsValidateBeforeCall(Client body, final ApiCallback _callback) throws ApiException {
146-
147146
// verify the required parameter 'body' is set
148147
if (body == null) {
149148
throw new ApiException("Missing the required parameter 'body' when calling call123testSpecialTags(Async)");
150149
}
151-
152150

153-
okhttp3.Call localVarCall = call123testSpecialTagsCall(body, _callback);
154-
return localVarCall;
151+
return call123testSpecialTagsCall(body, _callback);
155152

156153
}
157154

0 commit comments

Comments
 (0)