forked from loafle/openapi-generator-original
Add WithHttpInfo API methods to Java okhttp-gson client
to allow accessing response status code and headers and removed the methods of recording last response info from ApiClient.
This commit is contained in:
parent
c5a48d9891
commit
b1bc75189a
@ -232,6 +232,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
if ("okhttp-gson".equals(getLibrary())) {
|
||||
// the "okhttp-gson" library template requires "ApiCallback.mustache" for async call
|
||||
supportingFiles.add(new SupportingFile("ApiCallback.mustache", invokerFolder, "ApiCallback.java"));
|
||||
supportingFiles.add(new SupportingFile("ApiResponse.mustache", invokerFolder, "ApiResponse.java"));
|
||||
supportingFiles.add(new SupportingFile("ProgressRequestBody.mustache", invokerFolder, "ProgressRequestBody.java"));
|
||||
supportingFiles.add(new SupportingFile("ProgressResponseBody.mustache", invokerFolder, "ProgressResponseBody.java"));
|
||||
// "build.sbt" is for development with SBT
|
||||
|
@ -104,9 +104,6 @@ public class ApiClient {
|
||||
|
||||
private Map<String, Authentication> authentications;
|
||||
|
||||
private int statusCode;
|
||||
private Map<String, List<String>> responseHeaders;
|
||||
|
||||
private DateFormat dateFormat;
|
||||
private DateFormat datetimeFormat;
|
||||
private boolean lenientDatetimeFormat;
|
||||
@ -177,24 +174,6 @@ public class ApiClient {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the status code of the previous request.
|
||||
* NOTE: Status code of last async response is not recorded here, it is
|
||||
* passed to the callback methods instead.
|
||||
*/
|
||||
public int getStatusCode() {
|
||||
return statusCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the response headers of the previous request.
|
||||
* NOTE: Headers of last async response is not recorded here, it is passed
|
||||
* to callback methods instead.
|
||||
*/
|
||||
public Map<String, List<String>> getResponseHeaders() {
|
||||
return responseHeaders;
|
||||
}
|
||||
|
||||
public boolean isVerifyingSsl() {
|
||||
return verifyingSsl;
|
||||
}
|
||||
@ -731,7 +710,7 @@ public class ApiClient {
|
||||
/**
|
||||
* @see #execute(Call, Type)
|
||||
*/
|
||||
public <T> T execute(Call call) throws ApiException {
|
||||
public <T> ApiResponse<T> execute(Call call) throws ApiException {
|
||||
return execute(call, null);
|
||||
}
|
||||
|
||||
@ -740,14 +719,15 @@ public class ApiClient {
|
||||
*
|
||||
* @param returnType The return type used to deserialize HTTP response body
|
||||
* @param <T> The return type corresponding to (same with) returnType
|
||||
* @return The Java object deserialized from response body. Returns null if returnType is null.
|
||||
* @return <code>ApiResponse</code> object containing response status, headers and
|
||||
* data, which is a Java object deserialized from response body and would be null
|
||||
* when returnType is null.
|
||||
*/
|
||||
public <T> T execute(Call call, Type returnType) throws ApiException {
|
||||
public <T> ApiResponse<T> execute(Call call, Type returnType) throws ApiException {
|
||||
try {
|
||||
Response response = call.execute();
|
||||
this.statusCode = response.code();
|
||||
this.responseHeaders = response.headers().toMultimap();
|
||||
return handleResponse(response, returnType);
|
||||
T data = handleResponse(response, returnType);
|
||||
return new ApiResponse<T>(response.code(), response.headers().toMultimap(), data);
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
}
|
||||
|
@ -0,0 +1,32 @@
|
||||
package {{invokerPackage}};
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ApiResponse<T> {
|
||||
final private int statusCode;
|
||||
final private Map<String, List<String>> headers;
|
||||
final private T data;
|
||||
|
||||
public ApiResponse(int statusCode, Map<String, List<String>> headers) {
|
||||
this(statusCode, headers, null);
|
||||
}
|
||||
|
||||
public ApiResponse(int statusCode, Map<String, List<String>> headers, T data) {
|
||||
this.statusCode = statusCode;
|
||||
this.headers = headers;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public int getStatusCode() {
|
||||
return statusCode;
|
||||
}
|
||||
|
||||
public Map<String, List<String>> getHeaders() {
|
||||
return headers;
|
||||
}
|
||||
|
||||
public T getData() {
|
||||
return data;
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ package {{package}};
|
||||
import {{invokerPackage}}.ApiCallback;
|
||||
import {{invokerPackage}}.ApiClient;
|
||||
import {{invokerPackage}}.ApiException;
|
||||
import {{invokerPackage}}.ApiResponse;
|
||||
import {{invokerPackage}}.Configuration;
|
||||
import {{invokerPackage}}.Pair;
|
||||
import {{invokerPackage}}.ProgressRequestBody;
|
||||
@ -106,9 +107,20 @@ public class {{classname}} {
|
||||
* @return {{{returnType}}}{{/returnType}}
|
||||
*/
|
||||
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{operationId}}({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException {
|
||||
{{#returnType}}ApiResponse<{{{returnType}}}> {{localVariablePrefix}}resp = {{/returnType}}{{operationId}}WithHttpInfo({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{#returnType}}
|
||||
return {{localVariablePrefix}}resp.getData();{{/returnType}}
|
||||
}
|
||||
|
||||
/**
|
||||
* {{summary}}
|
||||
* {{notes}}{{#allParams}}
|
||||
* @param {{paramName}} {{description}}{{/allParams}}
|
||||
* @return ApiResponse<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}>
|
||||
*/
|
||||
public ApiResponse<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}> {{operationId}}WithHttpInfo({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException {
|
||||
Call {{localVariablePrefix}}call = {{operationId}}Call({{#allParams}}{{paramName}}, {{/allParams}}null, null);
|
||||
{{#returnType}}Type {{localVariablePrefix}}returnType = new TypeToken<{{{returnType}}}>(){}.getType();
|
||||
return {{localVariablePrefix}}apiClient.execute({{localVariablePrefix}}call, {{localVariablePrefix}}returnType);{{/returnType}}{{^returnType}}{{localVariablePrefix}}apiClient.execute({{localVariablePrefix}}call);{{/returnType}}
|
||||
return {{localVariablePrefix}}apiClient.execute({{localVariablePrefix}}call, {{localVariablePrefix}}returnType);{{/returnType}}{{^returnType}}return {{localVariablePrefix}}apiClient.execute({{localVariablePrefix}}call);{{/returnType}}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -104,9 +104,6 @@ public class ApiClient {
|
||||
|
||||
private Map<String, Authentication> authentications;
|
||||
|
||||
private int statusCode;
|
||||
private Map<String, List<String>> responseHeaders;
|
||||
|
||||
private DateFormat dateFormat;
|
||||
private DateFormat datetimeFormat;
|
||||
private boolean lenientDatetimeFormat;
|
||||
@ -143,8 +140,8 @@ public class ApiClient {
|
||||
|
||||
// Setup authentications (key: authentication name, value: authentication).
|
||||
authentications = new HashMap<String, Authentication>();
|
||||
authentications.put("api_key", new ApiKeyAuth("header", "api_key"));
|
||||
authentications.put("petstore_auth", new OAuth());
|
||||
authentications.put("api_key", new ApiKeyAuth("header", "api_key"));
|
||||
// Prevent the authentications from being modified.
|
||||
authentications = Collections.unmodifiableMap(authentications);
|
||||
}
|
||||
@ -176,24 +173,6 @@ public class ApiClient {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the status code of the previous request.
|
||||
* NOTE: Status code of last async response is not recorded here, it is
|
||||
* passed to the callback methods instead.
|
||||
*/
|
||||
public int getStatusCode() {
|
||||
return statusCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the response headers of the previous request.
|
||||
* NOTE: Headers of last async response is not recorded here, it is passed
|
||||
* to callback methods instead.
|
||||
*/
|
||||
public Map<String, List<String>> getResponseHeaders() {
|
||||
return responseHeaders;
|
||||
}
|
||||
|
||||
public boolean isVerifyingSsl() {
|
||||
return verifyingSsl;
|
||||
}
|
||||
@ -730,7 +709,7 @@ public class ApiClient {
|
||||
/**
|
||||
* @see #execute(Call, Type)
|
||||
*/
|
||||
public <T> T execute(Call call) throws ApiException {
|
||||
public <T> ApiResponse<T> execute(Call call) throws ApiException {
|
||||
return execute(call, null);
|
||||
}
|
||||
|
||||
@ -739,14 +718,15 @@ public class ApiClient {
|
||||
*
|
||||
* @param returnType The return type used to deserialize HTTP response body
|
||||
* @param <T> The return type corresponding to (same with) returnType
|
||||
* @return The Java object deserialized from response body. Returns null if returnType is null.
|
||||
* @return <code>ApiResponse</code> object containing response status, headers and
|
||||
* data, which is a Java object deserialized from response body and would be null
|
||||
* when returnType is null.
|
||||
*/
|
||||
public <T> T execute(Call call, Type returnType) throws ApiException {
|
||||
public <T> ApiResponse<T> execute(Call call, Type returnType) throws ApiException {
|
||||
try {
|
||||
Response response = call.execute();
|
||||
this.statusCode = response.code();
|
||||
this.responseHeaders = response.headers().toMultimap();
|
||||
return handleResponse(response, returnType);
|
||||
T data = handleResponse(response, returnType);
|
||||
return new ApiResponse<T>(response.code(), response.headers().toMultimap(), data);
|
||||
} catch (IOException e) {
|
||||
throw new ApiException(e);
|
||||
}
|
||||
|
@ -0,0 +1,32 @@
|
||||
package io.swagger.client;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ApiResponse<T> {
|
||||
final private int statusCode;
|
||||
final private Map<String, List<String>> headers;
|
||||
final private T data;
|
||||
|
||||
public ApiResponse(int statusCode, Map<String, List<String>> headers) {
|
||||
this(statusCode, headers, null);
|
||||
}
|
||||
|
||||
public ApiResponse(int statusCode, Map<String, List<String>> headers, T data) {
|
||||
this.statusCode = statusCode;
|
||||
this.headers = headers;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public int getStatusCode() {
|
||||
return statusCode;
|
||||
}
|
||||
|
||||
public Map<String, List<String>> getHeaders() {
|
||||
return headers;
|
||||
}
|
||||
|
||||
public T getData() {
|
||||
return data;
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ package io.swagger.client.api;
|
||||
import io.swagger.client.ApiCallback;
|
||||
import io.swagger.client.ApiClient;
|
||||
import io.swagger.client.ApiException;
|
||||
import io.swagger.client.ApiResponse;
|
||||
import io.swagger.client.Configuration;
|
||||
import io.swagger.client.Pair;
|
||||
import io.swagger.client.ProgressRequestBody;
|
||||
@ -90,8 +91,18 @@ public class PetApi {
|
||||
* @param body Pet object that needs to be added to the store
|
||||
*/
|
||||
public void updatePet(Pet body) throws ApiException {
|
||||
updatePetWithHttpInfo(body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing pet
|
||||
*
|
||||
* @param body Pet object that needs to be added to the store
|
||||
* @return ApiResponse<Void>
|
||||
*/
|
||||
public ApiResponse<Void> updatePetWithHttpInfo(Pet body) throws ApiException {
|
||||
Call call = updatePetCall(body, null, null);
|
||||
apiClient.execute(call);
|
||||
return apiClient.execute(call);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -106,7 +117,7 @@ public class PetApi {
|
||||
ProgressResponseBody.ProgressListener progressListener = null;
|
||||
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
|
||||
|
||||
if(callback != null) {
|
||||
if (callback != null) {
|
||||
progressListener = new ProgressResponseBody.ProgressListener() {
|
||||
@Override
|
||||
public void update(long bytesRead, long contentLength, boolean done) {
|
||||
@ -175,8 +186,18 @@ public class PetApi {
|
||||
* @param body Pet object that needs to be added to the store
|
||||
*/
|
||||
public void addPet(Pet body) throws ApiException {
|
||||
addPetWithHttpInfo(body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new pet to the store
|
||||
*
|
||||
* @param body Pet object that needs to be added to the store
|
||||
* @return ApiResponse<Void>
|
||||
*/
|
||||
public ApiResponse<Void> addPetWithHttpInfo(Pet body) throws ApiException {
|
||||
Call call = addPetCall(body, null, null);
|
||||
apiClient.execute(call);
|
||||
return apiClient.execute(call);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -191,7 +212,7 @@ public class PetApi {
|
||||
ProgressResponseBody.ProgressListener progressListener = null;
|
||||
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
|
||||
|
||||
if(callback != null) {
|
||||
if (callback != null) {
|
||||
progressListener = new ProgressResponseBody.ProgressListener() {
|
||||
@Override
|
||||
public void update(long bytesRead, long contentLength, boolean done) {
|
||||
@ -263,6 +284,17 @@ public class PetApi {
|
||||
* @return List<Pet>
|
||||
*/
|
||||
public List<Pet> findPetsByStatus(List<String> status) throws ApiException {
|
||||
ApiResponse<List<Pet>> resp = findPetsByStatusWithHttpInfo(status);
|
||||
return resp.getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds Pets by status
|
||||
* Multiple status values can be provided with comma seperated strings
|
||||
* @param status Status values that need to be considered for filter
|
||||
* @return ApiResponse<List<Pet>>
|
||||
*/
|
||||
public ApiResponse<List<Pet>> findPetsByStatusWithHttpInfo(List<String> status) throws ApiException {
|
||||
Call call = findPetsByStatusCall(status, null, null);
|
||||
Type returnType = new TypeToken<List<Pet>>(){}.getType();
|
||||
return apiClient.execute(call, returnType);
|
||||
@ -280,7 +312,7 @@ public class PetApi {
|
||||
ProgressResponseBody.ProgressListener progressListener = null;
|
||||
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
|
||||
|
||||
if(callback != null) {
|
||||
if (callback != null) {
|
||||
progressListener = new ProgressResponseBody.ProgressListener() {
|
||||
@Override
|
||||
public void update(long bytesRead, long contentLength, boolean done) {
|
||||
@ -353,6 +385,17 @@ public class PetApi {
|
||||
* @return List<Pet>
|
||||
*/
|
||||
public List<Pet> findPetsByTags(List<String> tags) throws ApiException {
|
||||
ApiResponse<List<Pet>> resp = findPetsByTagsWithHttpInfo(tags);
|
||||
return resp.getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds Pets by tags
|
||||
* Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.
|
||||
* @param tags Tags to filter by
|
||||
* @return ApiResponse<List<Pet>>
|
||||
*/
|
||||
public ApiResponse<List<Pet>> findPetsByTagsWithHttpInfo(List<String> tags) throws ApiException {
|
||||
Call call = findPetsByTagsCall(tags, null, null);
|
||||
Type returnType = new TypeToken<List<Pet>>(){}.getType();
|
||||
return apiClient.execute(call, returnType);
|
||||
@ -370,7 +413,7 @@ public class PetApi {
|
||||
ProgressResponseBody.ProgressListener progressListener = null;
|
||||
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
|
||||
|
||||
if(callback != null) {
|
||||
if (callback != null) {
|
||||
progressListener = new ProgressResponseBody.ProgressListener() {
|
||||
@Override
|
||||
public void update(long bytesRead, long contentLength, boolean done) {
|
||||
@ -447,6 +490,17 @@ public class PetApi {
|
||||
* @return Pet
|
||||
*/
|
||||
public Pet getPetById(Long petId) throws ApiException {
|
||||
ApiResponse<Pet> resp = getPetByIdWithHttpInfo(petId);
|
||||
return resp.getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find pet by ID
|
||||
* Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
|
||||
* @param petId ID of pet that needs to be fetched
|
||||
* @return ApiResponse<Pet>
|
||||
*/
|
||||
public ApiResponse<Pet> getPetByIdWithHttpInfo(Long petId) throws ApiException {
|
||||
Call call = getPetByIdCall(petId, null, null);
|
||||
Type returnType = new TypeToken<Pet>(){}.getType();
|
||||
return apiClient.execute(call, returnType);
|
||||
@ -464,7 +518,7 @@ public class PetApi {
|
||||
ProgressResponseBody.ProgressListener progressListener = null;
|
||||
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
|
||||
|
||||
if(callback != null) {
|
||||
if (callback != null) {
|
||||
progressListener = new ProgressResponseBody.ProgressListener() {
|
||||
@Override
|
||||
public void update(long bytesRead, long contentLength, boolean done) {
|
||||
@ -487,7 +541,7 @@ public class PetApi {
|
||||
}
|
||||
|
||||
/* Build call for updatePetWithForm */
|
||||
private Call updatePetWithFormCall(String petId,String name,String status, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
|
||||
private Call updatePetWithFormCall(String petId, String name, String status, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
|
||||
Object postBody = null;
|
||||
|
||||
// verify the required parameter 'petId' is set
|
||||
@ -546,8 +600,20 @@ public class PetApi {
|
||||
* @param status Updated status of the pet
|
||||
*/
|
||||
public void updatePetWithForm(String petId, String name, String status) throws ApiException {
|
||||
Call call = updatePetWithFormCall(petId,name,status, null, null);
|
||||
apiClient.execute(call);
|
||||
updatePetWithFormWithHttpInfo(petId, name, status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a pet in the store with form data
|
||||
*
|
||||
* @param petId ID of pet that needs to be updated
|
||||
* @param name Updated name of the pet
|
||||
* @param status Updated status of the pet
|
||||
* @return ApiResponse<Void>
|
||||
*/
|
||||
public ApiResponse<Void> updatePetWithFormWithHttpInfo(String petId, String name, String status) throws ApiException {
|
||||
Call call = updatePetWithFormCall(petId, name, status, null, null);
|
||||
return apiClient.execute(call);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -564,7 +630,7 @@ public class PetApi {
|
||||
ProgressResponseBody.ProgressListener progressListener = null;
|
||||
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
|
||||
|
||||
if(callback != null) {
|
||||
if (callback != null) {
|
||||
progressListener = new ProgressResponseBody.ProgressListener() {
|
||||
@Override
|
||||
public void update(long bytesRead, long contentLength, boolean done) {
|
||||
@ -580,13 +646,13 @@ public class PetApi {
|
||||
};
|
||||
}
|
||||
|
||||
Call call = updatePetWithFormCall(petId,name,status, progressListener, progressRequestListener);
|
||||
Call call = updatePetWithFormCall(petId, name, status, progressListener, progressRequestListener);
|
||||
apiClient.executeAsync(call, callback);
|
||||
return call;
|
||||
}
|
||||
|
||||
/* Build call for deletePet */
|
||||
private Call deletePetCall(Long petId,String apiKey, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
|
||||
private Call deletePetCall(Long petId, String apiKey, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
|
||||
Object postBody = null;
|
||||
|
||||
// verify the required parameter 'petId' is set
|
||||
@ -642,8 +708,19 @@ public class PetApi {
|
||||
* @param apiKey
|
||||
*/
|
||||
public void deletePet(Long petId, String apiKey) throws ApiException {
|
||||
Call call = deletePetCall(petId,apiKey, null, null);
|
||||
apiClient.execute(call);
|
||||
deletePetWithHttpInfo(petId, apiKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a pet
|
||||
*
|
||||
* @param petId Pet id to delete
|
||||
* @param apiKey
|
||||
* @return ApiResponse<Void>
|
||||
*/
|
||||
public ApiResponse<Void> deletePetWithHttpInfo(Long petId, String apiKey) throws ApiException {
|
||||
Call call = deletePetCall(petId, apiKey, null, null);
|
||||
return apiClient.execute(call);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -659,7 +736,7 @@ public class PetApi {
|
||||
ProgressResponseBody.ProgressListener progressListener = null;
|
||||
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
|
||||
|
||||
if(callback != null) {
|
||||
if (callback != null) {
|
||||
progressListener = new ProgressResponseBody.ProgressListener() {
|
||||
@Override
|
||||
public void update(long bytesRead, long contentLength, boolean done) {
|
||||
@ -675,13 +752,13 @@ public class PetApi {
|
||||
};
|
||||
}
|
||||
|
||||
Call call = deletePetCall(petId,apiKey, progressListener, progressRequestListener);
|
||||
Call call = deletePetCall(petId, apiKey, progressListener, progressRequestListener);
|
||||
apiClient.executeAsync(call, callback);
|
||||
return call;
|
||||
}
|
||||
|
||||
/* Build call for uploadFile */
|
||||
private Call uploadFileCall(Long petId,String additionalMetadata,File file, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
|
||||
private Call uploadFileCall(Long petId, String additionalMetadata, File file, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
|
||||
Object postBody = null;
|
||||
|
||||
// verify the required parameter 'petId' is set
|
||||
@ -740,8 +817,20 @@ public class PetApi {
|
||||
* @param file file to upload
|
||||
*/
|
||||
public void uploadFile(Long petId, String additionalMetadata, File file) throws ApiException {
|
||||
Call call = uploadFileCall(petId,additionalMetadata,file, null, null);
|
||||
apiClient.execute(call);
|
||||
uploadFileWithHttpInfo(petId, additionalMetadata, file);
|
||||
}
|
||||
|
||||
/**
|
||||
* uploads an image
|
||||
*
|
||||
* @param petId ID of pet to update
|
||||
* @param additionalMetadata Additional data to pass to server
|
||||
* @param file file to upload
|
||||
* @return ApiResponse<Void>
|
||||
*/
|
||||
public ApiResponse<Void> uploadFileWithHttpInfo(Long petId, String additionalMetadata, File file) throws ApiException {
|
||||
Call call = uploadFileCall(petId, additionalMetadata, file, null, null);
|
||||
return apiClient.execute(call);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -758,7 +847,7 @@ public class PetApi {
|
||||
ProgressResponseBody.ProgressListener progressListener = null;
|
||||
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
|
||||
|
||||
if(callback != null) {
|
||||
if (callback != null) {
|
||||
progressListener = new ProgressResponseBody.ProgressListener() {
|
||||
@Override
|
||||
public void update(long bytesRead, long contentLength, boolean done) {
|
||||
@ -774,7 +863,7 @@ public class PetApi {
|
||||
};
|
||||
}
|
||||
|
||||
Call call = uploadFileCall(petId,additionalMetadata,file, progressListener, progressRequestListener);
|
||||
Call call = uploadFileCall(petId, additionalMetadata, file, progressListener, progressRequestListener);
|
||||
apiClient.executeAsync(call, callback);
|
||||
return call;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package io.swagger.client.api;
|
||||
import io.swagger.client.ApiCallback;
|
||||
import io.swagger.client.ApiClient;
|
||||
import io.swagger.client.ApiException;
|
||||
import io.swagger.client.ApiResponse;
|
||||
import io.swagger.client.Configuration;
|
||||
import io.swagger.client.Pair;
|
||||
import io.swagger.client.ProgressRequestBody;
|
||||
@ -43,7 +44,7 @@ public class StoreApi {
|
||||
|
||||
|
||||
/* Build call for getInventory */
|
||||
private Call getInventoryCall( final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
|
||||
private Call getInventoryCall(final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
|
||||
Object postBody = null;
|
||||
|
||||
|
||||
@ -90,7 +91,17 @@ public class StoreApi {
|
||||
* @return Map<String, Integer>
|
||||
*/
|
||||
public Map<String, Integer> getInventory() throws ApiException {
|
||||
Call call = getInventoryCall( null, null);
|
||||
ApiResponse<Map<String, Integer>> resp = getInventoryWithHttpInfo();
|
||||
return resp.getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns pet inventories by status
|
||||
* Returns a map of status codes to quantities
|
||||
* @return ApiResponse<Map<String, Integer>>
|
||||
*/
|
||||
public ApiResponse<Map<String, Integer>> getInventoryWithHttpInfo() throws ApiException {
|
||||
Call call = getInventoryCall(null, null);
|
||||
Type returnType = new TypeToken<Map<String, Integer>>(){}.getType();
|
||||
return apiClient.execute(call, returnType);
|
||||
}
|
||||
@ -106,7 +117,7 @@ public class StoreApi {
|
||||
ProgressResponseBody.ProgressListener progressListener = null;
|
||||
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
|
||||
|
||||
if(callback != null) {
|
||||
if (callback != null) {
|
||||
progressListener = new ProgressResponseBody.ProgressListener() {
|
||||
@Override
|
||||
public void update(long bytesRead, long contentLength, boolean done) {
|
||||
@ -122,7 +133,7 @@ public class StoreApi {
|
||||
};
|
||||
}
|
||||
|
||||
Call call = getInventoryCall( progressListener, progressRequestListener);
|
||||
Call call = getInventoryCall(progressListener, progressRequestListener);
|
||||
Type returnType = new TypeToken<Map<String, Integer>>(){}.getType();
|
||||
apiClient.executeAsync(call, returnType, callback);
|
||||
return call;
|
||||
@ -177,6 +188,17 @@ public class StoreApi {
|
||||
* @return Order
|
||||
*/
|
||||
public Order placeOrder(Order body) throws ApiException {
|
||||
ApiResponse<Order> resp = placeOrderWithHttpInfo(body);
|
||||
return resp.getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Place an order for a pet
|
||||
*
|
||||
* @param body order placed for purchasing the pet
|
||||
* @return ApiResponse<Order>
|
||||
*/
|
||||
public ApiResponse<Order> placeOrderWithHttpInfo(Order body) throws ApiException {
|
||||
Call call = placeOrderCall(body, null, null);
|
||||
Type returnType = new TypeToken<Order>(){}.getType();
|
||||
return apiClient.execute(call, returnType);
|
||||
@ -194,7 +216,7 @@ public class StoreApi {
|
||||
ProgressResponseBody.ProgressListener progressListener = null;
|
||||
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
|
||||
|
||||
if(callback != null) {
|
||||
if (callback != null) {
|
||||
progressListener = new ProgressResponseBody.ProgressListener() {
|
||||
@Override
|
||||
public void update(long bytesRead, long contentLength, boolean done) {
|
||||
@ -271,6 +293,17 @@ public class StoreApi {
|
||||
* @return Order
|
||||
*/
|
||||
public Order getOrderById(String orderId) throws ApiException {
|
||||
ApiResponse<Order> resp = getOrderByIdWithHttpInfo(orderId);
|
||||
return resp.getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find purchase order by ID
|
||||
* For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
* @param orderId ID of pet that needs to be fetched
|
||||
* @return ApiResponse<Order>
|
||||
*/
|
||||
public ApiResponse<Order> getOrderByIdWithHttpInfo(String orderId) throws ApiException {
|
||||
Call call = getOrderByIdCall(orderId, null, null);
|
||||
Type returnType = new TypeToken<Order>(){}.getType();
|
||||
return apiClient.execute(call, returnType);
|
||||
@ -288,7 +321,7 @@ public class StoreApi {
|
||||
ProgressResponseBody.ProgressListener progressListener = null;
|
||||
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
|
||||
|
||||
if(callback != null) {
|
||||
if (callback != null) {
|
||||
progressListener = new ProgressResponseBody.ProgressListener() {
|
||||
@Override
|
||||
public void update(long bytesRead, long contentLength, boolean done) {
|
||||
@ -364,8 +397,18 @@ public class StoreApi {
|
||||
* @param orderId ID of the order that needs to be deleted
|
||||
*/
|
||||
public void deleteOrder(String orderId) throws ApiException {
|
||||
deleteOrderWithHttpInfo(orderId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete purchase order by ID
|
||||
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
* @param orderId ID of the order that needs to be deleted
|
||||
* @return ApiResponse<Void>
|
||||
*/
|
||||
public ApiResponse<Void> deleteOrderWithHttpInfo(String orderId) throws ApiException {
|
||||
Call call = deleteOrderCall(orderId, null, null);
|
||||
apiClient.execute(call);
|
||||
return apiClient.execute(call);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -380,7 +423,7 @@ public class StoreApi {
|
||||
ProgressResponseBody.ProgressListener progressListener = null;
|
||||
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
|
||||
|
||||
if(callback != null) {
|
||||
if (callback != null) {
|
||||
progressListener = new ProgressResponseBody.ProgressListener() {
|
||||
@Override
|
||||
public void update(long bytesRead, long contentLength, boolean done) {
|
||||
|
@ -3,6 +3,7 @@ package io.swagger.client.api;
|
||||
import io.swagger.client.ApiCallback;
|
||||
import io.swagger.client.ApiClient;
|
||||
import io.swagger.client.ApiException;
|
||||
import io.swagger.client.ApiResponse;
|
||||
import io.swagger.client.Configuration;
|
||||
import io.swagger.client.Pair;
|
||||
import io.swagger.client.ProgressRequestBody;
|
||||
@ -90,8 +91,18 @@ public class UserApi {
|
||||
* @param body Created user object
|
||||
*/
|
||||
public void createUser(User body) throws ApiException {
|
||||
createUserWithHttpInfo(body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create user
|
||||
* This can only be done by the logged in user.
|
||||
* @param body Created user object
|
||||
* @return ApiResponse<Void>
|
||||
*/
|
||||
public ApiResponse<Void> createUserWithHttpInfo(User body) throws ApiException {
|
||||
Call call = createUserCall(body, null, null);
|
||||
apiClient.execute(call);
|
||||
return apiClient.execute(call);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -106,7 +117,7 @@ public class UserApi {
|
||||
ProgressResponseBody.ProgressListener progressListener = null;
|
||||
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
|
||||
|
||||
if(callback != null) {
|
||||
if (callback != null) {
|
||||
progressListener = new ProgressResponseBody.ProgressListener() {
|
||||
@Override
|
||||
public void update(long bytesRead, long contentLength, boolean done) {
|
||||
@ -175,8 +186,18 @@ public class UserApi {
|
||||
* @param body List of user object
|
||||
*/
|
||||
public void createUsersWithArrayInput(List<User> body) throws ApiException {
|
||||
createUsersWithArrayInputWithHttpInfo(body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates list of users with given input array
|
||||
*
|
||||
* @param body List of user object
|
||||
* @return ApiResponse<Void>
|
||||
*/
|
||||
public ApiResponse<Void> createUsersWithArrayInputWithHttpInfo(List<User> body) throws ApiException {
|
||||
Call call = createUsersWithArrayInputCall(body, null, null);
|
||||
apiClient.execute(call);
|
||||
return apiClient.execute(call);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -191,7 +212,7 @@ public class UserApi {
|
||||
ProgressResponseBody.ProgressListener progressListener = null;
|
||||
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
|
||||
|
||||
if(callback != null) {
|
||||
if (callback != null) {
|
||||
progressListener = new ProgressResponseBody.ProgressListener() {
|
||||
@Override
|
||||
public void update(long bytesRead, long contentLength, boolean done) {
|
||||
@ -260,8 +281,18 @@ public class UserApi {
|
||||
* @param body List of user object
|
||||
*/
|
||||
public void createUsersWithListInput(List<User> body) throws ApiException {
|
||||
createUsersWithListInputWithHttpInfo(body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates list of users with given input array
|
||||
*
|
||||
* @param body List of user object
|
||||
* @return ApiResponse<Void>
|
||||
*/
|
||||
public ApiResponse<Void> createUsersWithListInputWithHttpInfo(List<User> body) throws ApiException {
|
||||
Call call = createUsersWithListInputCall(body, null, null);
|
||||
apiClient.execute(call);
|
||||
return apiClient.execute(call);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -276,7 +307,7 @@ public class UserApi {
|
||||
ProgressResponseBody.ProgressListener progressListener = null;
|
||||
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
|
||||
|
||||
if(callback != null) {
|
||||
if (callback != null) {
|
||||
progressListener = new ProgressResponseBody.ProgressListener() {
|
||||
@Override
|
||||
public void update(long bytesRead, long contentLength, boolean done) {
|
||||
@ -298,7 +329,7 @@ public class UserApi {
|
||||
}
|
||||
|
||||
/* Build call for loginUser */
|
||||
private Call loginUserCall(String username,String password, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
|
||||
private Call loginUserCall(String username, String password, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
|
||||
Object postBody = null;
|
||||
|
||||
|
||||
@ -351,7 +382,19 @@ public class UserApi {
|
||||
* @return String
|
||||
*/
|
||||
public String loginUser(String username, String password) throws ApiException {
|
||||
Call call = loginUserCall(username,password, null, null);
|
||||
ApiResponse<String> resp = loginUserWithHttpInfo(username, password);
|
||||
return resp.getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs user into the system
|
||||
*
|
||||
* @param username The user name for login
|
||||
* @param password The password for login in clear text
|
||||
* @return ApiResponse<String>
|
||||
*/
|
||||
public ApiResponse<String> loginUserWithHttpInfo(String username, String password) throws ApiException {
|
||||
Call call = loginUserCall(username, password, null, null);
|
||||
Type returnType = new TypeToken<String>(){}.getType();
|
||||
return apiClient.execute(call, returnType);
|
||||
}
|
||||
@ -369,7 +412,7 @@ public class UserApi {
|
||||
ProgressResponseBody.ProgressListener progressListener = null;
|
||||
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
|
||||
|
||||
if(callback != null) {
|
||||
if (callback != null) {
|
||||
progressListener = new ProgressResponseBody.ProgressListener() {
|
||||
@Override
|
||||
public void update(long bytesRead, long contentLength, boolean done) {
|
||||
@ -385,14 +428,14 @@ public class UserApi {
|
||||
};
|
||||
}
|
||||
|
||||
Call call = loginUserCall(username,password, progressListener, progressRequestListener);
|
||||
Call call = loginUserCall(username, password, progressListener, progressRequestListener);
|
||||
Type returnType = new TypeToken<String>(){}.getType();
|
||||
apiClient.executeAsync(call, returnType, callback);
|
||||
return call;
|
||||
}
|
||||
|
||||
/* Build call for logoutUser */
|
||||
private Call logoutUserCall( final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
|
||||
private Call logoutUserCall(final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
|
||||
Object postBody = null;
|
||||
|
||||
|
||||
@ -438,8 +481,17 @@ public class UserApi {
|
||||
*
|
||||
*/
|
||||
public void logoutUser() throws ApiException {
|
||||
Call call = logoutUserCall( null, null);
|
||||
apiClient.execute(call);
|
||||
logoutUserWithHttpInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs out current logged in user session
|
||||
*
|
||||
* @return ApiResponse<Void>
|
||||
*/
|
||||
public ApiResponse<Void> logoutUserWithHttpInfo() throws ApiException {
|
||||
Call call = logoutUserCall(null, null);
|
||||
return apiClient.execute(call);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -453,7 +505,7 @@ public class UserApi {
|
||||
ProgressResponseBody.ProgressListener progressListener = null;
|
||||
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
|
||||
|
||||
if(callback != null) {
|
||||
if (callback != null) {
|
||||
progressListener = new ProgressResponseBody.ProgressListener() {
|
||||
@Override
|
||||
public void update(long bytesRead, long contentLength, boolean done) {
|
||||
@ -469,7 +521,7 @@ public class UserApi {
|
||||
};
|
||||
}
|
||||
|
||||
Call call = logoutUserCall( progressListener, progressRequestListener);
|
||||
Call call = logoutUserCall(progressListener, progressRequestListener);
|
||||
apiClient.executeAsync(call, callback);
|
||||
return call;
|
||||
}
|
||||
@ -529,6 +581,17 @@ public class UserApi {
|
||||
* @return User
|
||||
*/
|
||||
public User getUserByName(String username) throws ApiException {
|
||||
ApiResponse<User> resp = getUserByNameWithHttpInfo(username);
|
||||
return resp.getData();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user by user name
|
||||
*
|
||||
* @param username The name that needs to be fetched. Use user1 for testing.
|
||||
* @return ApiResponse<User>
|
||||
*/
|
||||
public ApiResponse<User> getUserByNameWithHttpInfo(String username) throws ApiException {
|
||||
Call call = getUserByNameCall(username, null, null);
|
||||
Type returnType = new TypeToken<User>(){}.getType();
|
||||
return apiClient.execute(call, returnType);
|
||||
@ -546,7 +609,7 @@ public class UserApi {
|
||||
ProgressResponseBody.ProgressListener progressListener = null;
|
||||
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
|
||||
|
||||
if(callback != null) {
|
||||
if (callback != null) {
|
||||
progressListener = new ProgressResponseBody.ProgressListener() {
|
||||
@Override
|
||||
public void update(long bytesRead, long contentLength, boolean done) {
|
||||
@ -569,7 +632,7 @@ public class UserApi {
|
||||
}
|
||||
|
||||
/* Build call for updateUser */
|
||||
private Call updateUserCall(String username,User body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
|
||||
private Call updateUserCall(String username, User body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
|
||||
Object postBody = body;
|
||||
|
||||
// verify the required parameter 'username' is set
|
||||
@ -623,8 +686,19 @@ public class UserApi {
|
||||
* @param body Updated user object
|
||||
*/
|
||||
public void updateUser(String username, User body) throws ApiException {
|
||||
Call call = updateUserCall(username,body, null, null);
|
||||
apiClient.execute(call);
|
||||
updateUserWithHttpInfo(username, body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updated user
|
||||
* This can only be done by the logged in user.
|
||||
* @param username name that need to be deleted
|
||||
* @param body Updated user object
|
||||
* @return ApiResponse<Void>
|
||||
*/
|
||||
public ApiResponse<Void> updateUserWithHttpInfo(String username, User body) throws ApiException {
|
||||
Call call = updateUserCall(username, body, null, null);
|
||||
return apiClient.execute(call);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -640,7 +714,7 @@ public class UserApi {
|
||||
ProgressResponseBody.ProgressListener progressListener = null;
|
||||
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
|
||||
|
||||
if(callback != null) {
|
||||
if (callback != null) {
|
||||
progressListener = new ProgressResponseBody.ProgressListener() {
|
||||
@Override
|
||||
public void update(long bytesRead, long contentLength, boolean done) {
|
||||
@ -656,7 +730,7 @@ public class UserApi {
|
||||
};
|
||||
}
|
||||
|
||||
Call call = updateUserCall(username,body, progressListener, progressRequestListener);
|
||||
Call call = updateUserCall(username, body, progressListener, progressRequestListener);
|
||||
apiClient.executeAsync(call, callback);
|
||||
return call;
|
||||
}
|
||||
@ -715,8 +789,18 @@ public class UserApi {
|
||||
* @param username The name that needs to be deleted
|
||||
*/
|
||||
public void deleteUser(String username) throws ApiException {
|
||||
deleteUserWithHttpInfo(username);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete user
|
||||
* This can only be done by the logged in user.
|
||||
* @param username The name that needs to be deleted
|
||||
* @return ApiResponse<Void>
|
||||
*/
|
||||
public ApiResponse<Void> deleteUserWithHttpInfo(String username) throws ApiException {
|
||||
Call call = deleteUserCall(username, null, null);
|
||||
apiClient.execute(call);
|
||||
return apiClient.execute(call);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -731,7 +815,7 @@ public class UserApi {
|
||||
ProgressResponseBody.ProgressListener progressListener = null;
|
||||
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
|
||||
|
||||
if(callback != null) {
|
||||
if (callback != null) {
|
||||
progressListener = new ProgressResponseBody.ProgressListener() {
|
||||
@Override
|
||||
public void update(long bytesRead, long contentLength, boolean done) {
|
||||
|
@ -1,10 +1,6 @@
|
||||
package io.swagger.petstore.test;
|
||||
|
||||
import io.swagger.client.ApiClient;
|
||||
import io.swagger.client.ApiException;
|
||||
import io.swagger.client.Configuration;
|
||||
|
||||
import io.swagger.client.ApiCallback;
|
||||
import io.swagger.client.*;
|
||||
import io.swagger.client.api.*;
|
||||
import io.swagger.client.auth.*;
|
||||
import io.swagger.client.model.*;
|
||||
@ -71,6 +67,21 @@ public class PetApiTest {
|
||||
assertEquals(fetched.getCategory().getName(), pet.getCategory().getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateAndGetPetWithHttpInfo() throws Exception {
|
||||
Pet pet = createRandomPet();
|
||||
api.addPetWithHttpInfo(pet);
|
||||
|
||||
ApiResponse<Pet> resp = api.getPetByIdWithHttpInfo(pet.getId());
|
||||
assertEquals(200, resp.getStatusCode());
|
||||
assertEquals("application/json", resp.getHeaders().get("Content-Type").get(0));
|
||||
Pet fetched = resp.getData();
|
||||
assertNotNull(fetched);
|
||||
assertEquals(pet.getId(), fetched.getId());
|
||||
assertNotNull(fetched.getCategory());
|
||||
assertEquals(fetched.getCategory().getName(), pet.getCategory().getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateAndGetPetAsync() throws Exception {
|
||||
Pet pet = createRandomPet();
|
||||
|
Loading…
x
Reference in New Issue
Block a user