Skip to content

Commit 2b17049

Browse files
committed
updated java okhttp-gson sample
1 parent 354bd18 commit 2b17049

File tree

3 files changed

+360
-1
lines changed

3 files changed

+360
-1
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0.1-SNAPSHOT
1+
3.0.3-SNAPSHOT

samples/client/petstore/java/okhttp-gson/docs/PetApi.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,58 @@ null (empty response body)
375375

376376
[petstore_auth](../README.md#petstore_auth)
377377

378+
### HTTP request headers
379+
380+
- **Content-Type**: application/x-www-form-urlencoded
381+
- **Accept**: Not defined
382+
383+
<a name="updatePetWithForm"></a>
384+
# **updatePetWithForm**
385+
> updatePetWithForm(petId, body)
386+
387+
Updates a pet in the store with form data
388+
389+
### Example
390+
```java
391+
// Import classes:
392+
//import io.swagger.client.ApiClient;
393+
//import io.swagger.client.ApiException;
394+
//import io.swagger.client.Configuration;
395+
//import io.swagger.client.auth.*;
396+
//import io.swagger.client.api.PetApi;
397+
398+
ApiClient defaultClient = Configuration.getDefaultApiClient();
399+
400+
// Configure OAuth2 access token for authorization: petstore_auth
401+
OAuth petstore_auth = (OAuth) defaultClient.getAuthentication("petstore_auth");
402+
petstore_auth.setAccessToken("YOUR ACCESS TOKEN");
403+
404+
PetApi apiInstance = new PetApi();
405+
Integer petId = 56; // Integer | ID of pet that needs to be updated
406+
Object body = null; // Object |
407+
try {
408+
apiInstance.updatePetWithForm(petId, body);
409+
} catch (ApiException e) {
410+
System.err.println("Exception when calling PetApi#updatePetWithForm");
411+
e.printStackTrace();
412+
}
413+
```
414+
415+
### Parameters
416+
417+
Name | Type | Description | Notes
418+
------------- | ------------- | ------------- | -------------
419+
**petId** | [**Integer**](.md)| ID of pet that needs to be updated |
420+
**body** | [**Object**](Object.md)| | [optional]
421+
422+
### Return type
423+
424+
null (empty response body)
425+
426+
### Authorization
427+
428+
[petstore_auth](../README.md#petstore_auth)
429+
378430
### HTTP request headers
379431

380432
- **Content-Type**: application/x-www-form-urlencoded
@@ -435,3 +487,56 @@ Name | Type | Description | Notes
435487
- **Content-Type**: multipart/form-data
436488
- **Accept**: application/json
437489

490+
<a name="uploadFile"></a>
491+
# **uploadFile**
492+
> ModelApiResponse uploadFile(petId, body)
493+
494+
uploads an image
495+
496+
### Example
497+
```java
498+
// Import classes:
499+
//import io.swagger.client.ApiClient;
500+
//import io.swagger.client.ApiException;
501+
//import io.swagger.client.Configuration;
502+
//import io.swagger.client.auth.*;
503+
//import io.swagger.client.api.PetApi;
504+
505+
ApiClient defaultClient = Configuration.getDefaultApiClient();
506+
507+
// Configure OAuth2 access token for authorization: petstore_auth
508+
OAuth petstore_auth = (OAuth) defaultClient.getAuthentication("petstore_auth");
509+
petstore_auth.setAccessToken("YOUR ACCESS TOKEN");
510+
511+
PetApi apiInstance = new PetApi();
512+
Integer petId = 56; // Integer | ID of pet to update
513+
Object body = null; // Object |
514+
try {
515+
ModelApiResponse result = apiInstance.uploadFile(petId, body);
516+
System.out.println(result);
517+
} catch (ApiException e) {
518+
System.err.println("Exception when calling PetApi#uploadFile");
519+
e.printStackTrace();
520+
}
521+
```
522+
523+
### Parameters
524+
525+
Name | Type | Description | Notes
526+
------------- | ------------- | ------------- | -------------
527+
**petId** | [**Integer**](.md)| ID of pet to update |
528+
**body** | [**Object**](Object.md)| | [optional]
529+
530+
### Return type
531+
532+
[**ModelApiResponse**](ModelApiResponse.md)
533+
534+
### Authorization
535+
536+
[petstore_auth](../README.md#petstore_auth)
537+
538+
### HTTP request headers
539+
540+
- **Content-Type**: multipart/form-data
541+
- **Accept**: application/json
542+

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

Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,131 @@ public void onRequestProgress(long bytesWritten, long contentLength, boolean don
932932
apiClient.executeAsync(call, callback);
933933
return call;
934934
}
935+
/**
936+
* Build call for updatePetWithForm
937+
* @param petId ID of pet that needs to be updated (required)
938+
* @param body (optional)
939+
* @param progressListener Progress listener
940+
* @param progressRequestListener Progress request listener
941+
* @return Call to execute
942+
* @throws ApiException If fail to serialize the request body object
943+
*/
944+
public com.squareup.okhttp.Call updatePetWithFormCall(Integer petId, Object body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
945+
Object localVarPostBody = body;
946+
947+
// create path and map variables
948+
String localVarPath = "/pet/{petId}"
949+
.replaceAll("\\{" + "petId" + "\\}", apiClient.escapeString(petId.toString()));
950+
951+
List<Pair> localVarQueryParams = new ArrayList<Pair>();
952+
List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();
953+
954+
Map<String, String> localVarHeaderParams = new HashMap<String, String>();
955+
956+
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
957+
958+
final String[] localVarAccepts = {
959+
960+
};
961+
final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
962+
if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept);
963+
964+
final String[] localVarContentTypes = {
965+
"application/x-www-form-urlencoded"
966+
};
967+
final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
968+
localVarHeaderParams.put("Content-Type", localVarContentType);
969+
970+
if(progressListener != null) {
971+
apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
972+
@Override
973+
public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException {
974+
com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
975+
return originalResponse.newBuilder()
976+
.body(new ProgressResponseBody(originalResponse.body(), progressListener))
977+
.build();
978+
}
979+
});
980+
}
981+
982+
String[] localVarAuthNames = new String[] { "petstore_auth" };
983+
return apiClient.buildCall(localVarPath, "POST", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
984+
}
985+
986+
@SuppressWarnings("rawtypes")
987+
private com.squareup.okhttp.Call updatePetWithFormValidateBeforeCall(Integer petId, Object body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
988+
// verify the required parameter 'petId' is set
989+
if (petId == null) {
990+
throw new ApiException("Missing the required parameter 'petId' when calling updatePetWithForm(Async)");
991+
}
992+
993+
com.squareup.okhttp.Call call = updatePetWithFormCall(petId, body, progressListener, progressRequestListener);
994+
return call;
995+
996+
997+
998+
999+
1000+
}
1001+
1002+
/**
1003+
* Updates a pet in the store with form data
1004+
*
1005+
* @param petId ID of pet that needs to be updated (required)
1006+
* @param body (optional)
1007+
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
1008+
*/
1009+
public void updatePetWithForm(Integer petId, Object body) throws ApiException {
1010+
updatePetWithFormWithHttpInfo(petId, body);
1011+
}
1012+
1013+
/**
1014+
* Updates a pet in the store with form data
1015+
*
1016+
* @param petId ID of pet that needs to be updated (required)
1017+
* @param body (optional)
1018+
* @return ApiResponse&lt;Void&gt;
1019+
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
1020+
*/
1021+
public ApiResponse<Void> updatePetWithFormWithHttpInfo(Integer petId, Object body) throws ApiException {
1022+
com.squareup.okhttp.Call call = updatePetWithFormValidateBeforeCall(petId, body, null, null);
1023+
return apiClient.execute(call);
1024+
}
1025+
1026+
/**
1027+
* Updates a pet in the store with form data (asynchronously)
1028+
*
1029+
* @param petId ID of pet that needs to be updated (required)
1030+
* @param body (optional)
1031+
* @param callback The callback to be executed when the API call finishes
1032+
* @return The request call
1033+
* @throws ApiException If fail to process the API call, e.g. serializing the request body object
1034+
*/
1035+
public com.squareup.okhttp.Call updatePetWithFormAsync(Integer petId, Object body, final ApiCallback<Void> callback) throws ApiException {
1036+
1037+
ProgressResponseBody.ProgressListener progressListener = null;
1038+
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
1039+
1040+
if (callback != null) {
1041+
progressListener = new ProgressResponseBody.ProgressListener() {
1042+
@Override
1043+
public void update(long bytesRead, long contentLength, boolean done) {
1044+
callback.onDownloadProgress(bytesRead, contentLength, done);
1045+
}
1046+
};
1047+
1048+
progressRequestListener = new ProgressRequestBody.ProgressRequestListener() {
1049+
@Override
1050+
public void onRequestProgress(long bytesWritten, long contentLength, boolean done) {
1051+
callback.onUploadProgress(bytesWritten, contentLength, done);
1052+
}
1053+
};
1054+
}
1055+
1056+
com.squareup.okhttp.Call call = updatePetWithFormValidateBeforeCall(petId, body, progressListener, progressRequestListener);
1057+
apiClient.executeAsync(call, callback);
1058+
return call;
1059+
}
9351060
/**
9361061
* Build call for uploadFile
9371062
* @param petId ID of pet to update (required)
@@ -1069,4 +1194,133 @@ public void onRequestProgress(long bytesWritten, long contentLength, boolean don
10691194
apiClient.executeAsync(call, localVarReturnType, callback);
10701195
return call;
10711196
}
1197+
/**
1198+
* Build call for uploadFile
1199+
* @param petId ID of pet to update (required)
1200+
* @param body (optional)
1201+
* @param progressListener Progress listener
1202+
* @param progressRequestListener Progress request listener
1203+
* @return Call to execute
1204+
* @throws ApiException If fail to serialize the request body object
1205+
*/
1206+
public com.squareup.okhttp.Call uploadFileCall(Integer petId, Object body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
1207+
Object localVarPostBody = body;
1208+
1209+
// create path and map variables
1210+
String localVarPath = "/pet/{petId}/uploadImage"
1211+
.replaceAll("\\{" + "petId" + "\\}", apiClient.escapeString(petId.toString()));
1212+
1213+
List<Pair> localVarQueryParams = new ArrayList<Pair>();
1214+
List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();
1215+
1216+
Map<String, String> localVarHeaderParams = new HashMap<String, String>();
1217+
1218+
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
1219+
1220+
final String[] localVarAccepts = {
1221+
"application/json"
1222+
};
1223+
final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
1224+
if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept);
1225+
1226+
final String[] localVarContentTypes = {
1227+
"multipart/form-data"
1228+
};
1229+
final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
1230+
localVarHeaderParams.put("Content-Type", localVarContentType);
1231+
1232+
if(progressListener != null) {
1233+
apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
1234+
@Override
1235+
public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException {
1236+
com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
1237+
return originalResponse.newBuilder()
1238+
.body(new ProgressResponseBody(originalResponse.body(), progressListener))
1239+
.build();
1240+
}
1241+
});
1242+
}
1243+
1244+
String[] localVarAuthNames = new String[] { "petstore_auth" };
1245+
return apiClient.buildCall(localVarPath, "POST", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
1246+
}
1247+
1248+
@SuppressWarnings("rawtypes")
1249+
private com.squareup.okhttp.Call uploadFileValidateBeforeCall(Integer petId, Object body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
1250+
// verify the required parameter 'petId' is set
1251+
if (petId == null) {
1252+
throw new ApiException("Missing the required parameter 'petId' when calling uploadFile(Async)");
1253+
}
1254+
1255+
com.squareup.okhttp.Call call = uploadFileCall(petId, body, progressListener, progressRequestListener);
1256+
return call;
1257+
1258+
1259+
1260+
1261+
1262+
}
1263+
1264+
/**
1265+
* uploads an image
1266+
*
1267+
* @param petId ID of pet to update (required)
1268+
* @param body (optional)
1269+
* @return ModelApiResponse
1270+
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
1271+
*/
1272+
public ModelApiResponse uploadFile(Integer petId, Object body) throws ApiException {
1273+
ApiResponse<ModelApiResponse> resp = uploadFileWithHttpInfo(petId, body);
1274+
return resp.getData();
1275+
}
1276+
1277+
/**
1278+
* uploads an image
1279+
*
1280+
* @param petId ID of pet to update (required)
1281+
* @param body (optional)
1282+
* @return ApiResponse&lt;ModelApiResponse&gt;
1283+
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
1284+
*/
1285+
public ApiResponse<ModelApiResponse> uploadFileWithHttpInfo(Integer petId, Object body) throws ApiException {
1286+
com.squareup.okhttp.Call call = uploadFileValidateBeforeCall(petId, body, null, null);
1287+
Type localVarReturnType = new TypeToken<ModelApiResponse>(){}.getType();
1288+
return apiClient.execute(call, localVarReturnType);
1289+
}
1290+
1291+
/**
1292+
* uploads an image (asynchronously)
1293+
*
1294+
* @param petId ID of pet to update (required)
1295+
* @param body (optional)
1296+
* @param callback The callback to be executed when the API call finishes
1297+
* @return The request call
1298+
* @throws ApiException If fail to process the API call, e.g. serializing the request body object
1299+
*/
1300+
public com.squareup.okhttp.Call uploadFileAsync(Integer petId, Object body, final ApiCallback<ModelApiResponse> callback) throws ApiException {
1301+
1302+
ProgressResponseBody.ProgressListener progressListener = null;
1303+
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
1304+
1305+
if (callback != null) {
1306+
progressListener = new ProgressResponseBody.ProgressListener() {
1307+
@Override
1308+
public void update(long bytesRead, long contentLength, boolean done) {
1309+
callback.onDownloadProgress(bytesRead, contentLength, done);
1310+
}
1311+
};
1312+
1313+
progressRequestListener = new ProgressRequestBody.ProgressRequestListener() {
1314+
@Override
1315+
public void onRequestProgress(long bytesWritten, long contentLength, boolean done) {
1316+
callback.onUploadProgress(bytesWritten, contentLength, done);
1317+
}
1318+
};
1319+
}
1320+
1321+
com.squareup.okhttp.Call call = uploadFileValidateBeforeCall(petId, body, progressListener, progressRequestListener);
1322+
Type localVarReturnType = new TypeToken<ModelApiResponse>(){}.getType();
1323+
apiClient.executeAsync(call, localVarReturnType, callback);
1324+
return call;
1325+
}
10721326
}

0 commit comments

Comments
 (0)