Skip to content

Commit

Permalink
updated java okhttp-gson sample
Browse files Browse the repository at this point in the history
  • Loading branch information
HugoMario committed Oct 29, 2018
1 parent 354bd18 commit 2b17049
Show file tree
Hide file tree
Showing 3 changed files with 360 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.1-SNAPSHOT
3.0.3-SNAPSHOT
105 changes: 105 additions & 0 deletions samples/client/petstore/java/okhttp-gson/docs/PetApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,58 @@ null (empty response body)

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

### HTTP request headers

- **Content-Type**: application/x-www-form-urlencoded
- **Accept**: Not defined

<a name="updatePetWithForm"></a>
# **updatePetWithForm**
> updatePetWithForm(petId, body)
Updates a pet in the store with form data

### Example
```java
// Import classes:
//import io.swagger.client.ApiClient;
//import io.swagger.client.ApiException;
//import io.swagger.client.Configuration;
//import io.swagger.client.auth.*;
//import io.swagger.client.api.PetApi;

ApiClient defaultClient = Configuration.getDefaultApiClient();

// Configure OAuth2 access token for authorization: petstore_auth
OAuth petstore_auth = (OAuth) defaultClient.getAuthentication("petstore_auth");
petstore_auth.setAccessToken("YOUR ACCESS TOKEN");

PetApi apiInstance = new PetApi();
Integer petId = 56; // Integer | ID of pet that needs to be updated
Object body = null; // Object |
try {
apiInstance.updatePetWithForm(petId, body);
} catch (ApiException e) {
System.err.println("Exception when calling PetApi#updatePetWithForm");
e.printStackTrace();
}
```

### Parameters

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**petId** | [**Integer**](.md)| ID of pet that needs to be updated |
**body** | [**Object**](Object.md)| | [optional]

### Return type

null (empty response body)

### Authorization

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

### HTTP request headers

- **Content-Type**: application/x-www-form-urlencoded
Expand Down Expand Up @@ -435,3 +487,56 @@ Name | Type | Description | Notes
- **Content-Type**: multipart/form-data
- **Accept**: application/json

<a name="uploadFile"></a>
# **uploadFile**
> ModelApiResponse uploadFile(petId, body)
uploads an image

### Example
```java
// Import classes:
//import io.swagger.client.ApiClient;
//import io.swagger.client.ApiException;
//import io.swagger.client.Configuration;
//import io.swagger.client.auth.*;
//import io.swagger.client.api.PetApi;

ApiClient defaultClient = Configuration.getDefaultApiClient();

// Configure OAuth2 access token for authorization: petstore_auth
OAuth petstore_auth = (OAuth) defaultClient.getAuthentication("petstore_auth");
petstore_auth.setAccessToken("YOUR ACCESS TOKEN");

PetApi apiInstance = new PetApi();
Integer petId = 56; // Integer | ID of pet to update
Object body = null; // Object |
try {
ModelApiResponse result = apiInstance.uploadFile(petId, body);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling PetApi#uploadFile");
e.printStackTrace();
}
```

### Parameters

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**petId** | [**Integer**](.md)| ID of pet to update |
**body** | [**Object**](Object.md)| | [optional]

### Return type

[**ModelApiResponse**](ModelApiResponse.md)

### Authorization

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

### HTTP request headers

- **Content-Type**: multipart/form-data
- **Accept**: application/json

Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,131 @@ public void onRequestProgress(long bytesWritten, long contentLength, boolean don
apiClient.executeAsync(call, callback);
return call;
}
/**
* Build call for updatePetWithForm
* @param petId ID of pet that needs to be updated (required)
* @param body (optional)
* @param progressListener Progress listener
* @param progressRequestListener Progress request listener
* @return Call to execute
* @throws ApiException If fail to serialize the request body object
*/
public com.squareup.okhttp.Call updatePetWithFormCall(Integer petId, Object body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
Object localVarPostBody = body;

// create path and map variables
String localVarPath = "/pet/{petId}"
.replaceAll("\\{" + "petId" + "\\}", apiClient.escapeString(petId.toString()));

List<Pair> localVarQueryParams = new ArrayList<Pair>();
List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();

Map<String, String> localVarHeaderParams = new HashMap<String, String>();

Map<String, Object> localVarFormParams = new HashMap<String, Object>();

final String[] localVarAccepts = {

};
final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept);

final String[] localVarContentTypes = {
"application/x-www-form-urlencoded"
};
final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
localVarHeaderParams.put("Content-Type", localVarContentType);

if(progressListener != null) {
apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
@Override
public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException {
com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
return originalResponse.newBuilder()
.body(new ProgressResponseBody(originalResponse.body(), progressListener))
.build();
}
});
}

String[] localVarAuthNames = new String[] { "petstore_auth" };
return apiClient.buildCall(localVarPath, "POST", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
}

@SuppressWarnings("rawtypes")
private com.squareup.okhttp.Call updatePetWithFormValidateBeforeCall(Integer petId, Object body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
// verify the required parameter 'petId' is set
if (petId == null) {
throw new ApiException("Missing the required parameter 'petId' when calling updatePetWithForm(Async)");
}

com.squareup.okhttp.Call call = updatePetWithFormCall(petId, body, progressListener, progressRequestListener);
return call;





}

/**
* Updates a pet in the store with form data
*
* @param petId ID of pet that needs to be updated (required)
* @param body (optional)
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
*/
public void updatePetWithForm(Integer petId, Object body) throws ApiException {
updatePetWithFormWithHttpInfo(petId, body);
}

/**
* Updates a pet in the store with form data
*
* @param petId ID of pet that needs to be updated (required)
* @param body (optional)
* @return ApiResponse&lt;Void&gt;
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
*/
public ApiResponse<Void> updatePetWithFormWithHttpInfo(Integer petId, Object body) throws ApiException {
com.squareup.okhttp.Call call = updatePetWithFormValidateBeforeCall(petId, body, null, null);
return apiClient.execute(call);
}

/**
* Updates a pet in the store with form data (asynchronously)
*
* @param petId ID of pet that needs to be updated (required)
* @param body (optional)
* @param callback The callback to be executed when the API call finishes
* @return The request call
* @throws ApiException If fail to process the API call, e.g. serializing the request body object
*/
public com.squareup.okhttp.Call updatePetWithFormAsync(Integer petId, Object body, final ApiCallback<Void> callback) throws ApiException {

ProgressResponseBody.ProgressListener progressListener = null;
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;

if (callback != null) {
progressListener = new ProgressResponseBody.ProgressListener() {
@Override
public void update(long bytesRead, long contentLength, boolean done) {
callback.onDownloadProgress(bytesRead, contentLength, done);
}
};

progressRequestListener = new ProgressRequestBody.ProgressRequestListener() {
@Override
public void onRequestProgress(long bytesWritten, long contentLength, boolean done) {
callback.onUploadProgress(bytesWritten, contentLength, done);
}
};
}

com.squareup.okhttp.Call call = updatePetWithFormValidateBeforeCall(petId, body, progressListener, progressRequestListener);
apiClient.executeAsync(call, callback);
return call;
}
/**
* Build call for uploadFile
* @param petId ID of pet to update (required)
Expand Down Expand Up @@ -1069,4 +1194,133 @@ public void onRequestProgress(long bytesWritten, long contentLength, boolean don
apiClient.executeAsync(call, localVarReturnType, callback);
return call;
}
/**
* Build call for uploadFile
* @param petId ID of pet to update (required)
* @param body (optional)
* @param progressListener Progress listener
* @param progressRequestListener Progress request listener
* @return Call to execute
* @throws ApiException If fail to serialize the request body object
*/
public com.squareup.okhttp.Call uploadFileCall(Integer petId, Object body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
Object localVarPostBody = body;

// create path and map variables
String localVarPath = "/pet/{petId}/uploadImage"
.replaceAll("\\{" + "petId" + "\\}", apiClient.escapeString(petId.toString()));

List<Pair> localVarQueryParams = new ArrayList<Pair>();
List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();

Map<String, String> localVarHeaderParams = new HashMap<String, String>();

Map<String, Object> localVarFormParams = new HashMap<String, Object>();

final String[] localVarAccepts = {
"application/json"
};
final String localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept);

final String[] localVarContentTypes = {
"multipart/form-data"
};
final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
localVarHeaderParams.put("Content-Type", localVarContentType);

if(progressListener != null) {
apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
@Override
public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException {
com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
return originalResponse.newBuilder()
.body(new ProgressResponseBody(originalResponse.body(), progressListener))
.build();
}
});
}

String[] localVarAuthNames = new String[] { "petstore_auth" };
return apiClient.buildCall(localVarPath, "POST", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarAuthNames, progressRequestListener);
}

@SuppressWarnings("rawtypes")
private com.squareup.okhttp.Call uploadFileValidateBeforeCall(Integer petId, Object body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
// verify the required parameter 'petId' is set
if (petId == null) {
throw new ApiException("Missing the required parameter 'petId' when calling uploadFile(Async)");
}

com.squareup.okhttp.Call call = uploadFileCall(petId, body, progressListener, progressRequestListener);
return call;





}

/**
* uploads an image
*
* @param petId ID of pet to update (required)
* @param body (optional)
* @return ModelApiResponse
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
*/
public ModelApiResponse uploadFile(Integer petId, Object body) throws ApiException {
ApiResponse<ModelApiResponse> resp = uploadFileWithHttpInfo(petId, body);
return resp.getData();
}

/**
* uploads an image
*
* @param petId ID of pet to update (required)
* @param body (optional)
* @return ApiResponse&lt;ModelApiResponse&gt;
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
*/
public ApiResponse<ModelApiResponse> uploadFileWithHttpInfo(Integer petId, Object body) throws ApiException {
com.squareup.okhttp.Call call = uploadFileValidateBeforeCall(petId, body, null, null);
Type localVarReturnType = new TypeToken<ModelApiResponse>(){}.getType();
return apiClient.execute(call, localVarReturnType);
}

/**
* uploads an image (asynchronously)
*
* @param petId ID of pet to update (required)
* @param body (optional)
* @param callback The callback to be executed when the API call finishes
* @return The request call
* @throws ApiException If fail to process the API call, e.g. serializing the request body object
*/
public com.squareup.okhttp.Call uploadFileAsync(Integer petId, Object body, final ApiCallback<ModelApiResponse> callback) throws ApiException {

ProgressResponseBody.ProgressListener progressListener = null;
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;

if (callback != null) {
progressListener = new ProgressResponseBody.ProgressListener() {
@Override
public void update(long bytesRead, long contentLength, boolean done) {
callback.onDownloadProgress(bytesRead, contentLength, done);
}
};

progressRequestListener = new ProgressRequestBody.ProgressRequestListener() {
@Override
public void onRequestProgress(long bytesWritten, long contentLength, boolean done) {
callback.onUploadProgress(bytesWritten, contentLength, done);
}
};
}

com.squareup.okhttp.Call call = uploadFileValidateBeforeCall(petId, body, progressListener, progressRequestListener);
Type localVarReturnType = new TypeToken<ModelApiResponse>(){}.getType();
apiClient.executeAsync(call, localVarReturnType, callback);
return call;
}
}

0 comments on commit 2b17049

Please sign in to comment.