diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java index 0aba8c2c9d15..67a746d4afbc 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java @@ -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 diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache index cef9a843347f..7b21d760f564 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache @@ -104,9 +104,6 @@ public class ApiClient { private Map authentications; - private int statusCode; - private Map> 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> getResponseHeaders() { - return responseHeaders; - } - public boolean isVerifyingSsl() { return verifyingSsl; } @@ -731,7 +710,7 @@ public class ApiClient { /** * @see #execute(Call, Type) */ - public T execute(Call call) throws ApiException { + public ApiResponse 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 The return type corresponding to (same with) returnType - * @return The Java object deserialized from response body. Returns null if returnType is null. + * @return ApiResponse 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 execute(Call call, Type returnType) throws ApiException { + public ApiResponse 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(response.code(), response.headers().toMultimap(), data); } catch (IOException e) { throw new ApiException(e); } diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/ApiResponse.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/ApiResponse.mustache new file mode 100644 index 000000000000..945de39da702 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/ApiResponse.mustache @@ -0,0 +1,32 @@ +package {{invokerPackage}}; + +import java.util.List; +import java.util.Map; + +public class ApiResponse { + final private int statusCode; + final private Map> headers; + final private T data; + + public ApiResponse(int statusCode, Map> headers) { + this(statusCode, headers, null); + } + + public ApiResponse(int statusCode, Map> headers, T data) { + this.statusCode = statusCode; + this.headers = headers; + this.data = data; + } + + public int getStatusCode() { + return statusCode; + } + + public Map> getHeaders() { + return headers; + } + + public T getData() { + return data; + } +} diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/api.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/api.mustache index a1a4c9f8fb4f..da145d08df22 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/api.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/api.mustache @@ -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}} } /** diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java index 8d38c18e907c..8a75219bb539 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java @@ -104,9 +104,6 @@ public class ApiClient { private Map authentications; - private int statusCode; - private Map> 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(); - 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> getResponseHeaders() { - return responseHeaders; - } - public boolean isVerifyingSsl() { return verifyingSsl; } @@ -730,7 +709,7 @@ public class ApiClient { /** * @see #execute(Call, Type) */ - public T execute(Call call) throws ApiException { + public ApiResponse 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 The return type corresponding to (same with) returnType - * @return The Java object deserialized from response body. Returns null if returnType is null. + * @return ApiResponse 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 execute(Call call, Type returnType) throws ApiException { + public ApiResponse 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(response.code(), response.headers().toMultimap(), data); } catch (IOException e) { throw new ApiException(e); } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiResponse.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiResponse.java new file mode 100644 index 000000000000..fbe22e077b84 --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiResponse.java @@ -0,0 +1,32 @@ +package io.swagger.client; + +import java.util.List; +import java.util.Map; + +public class ApiResponse { + final private int statusCode; + final private Map> headers; + final private T data; + + public ApiResponse(int statusCode, Map> headers) { + this(statusCode, headers, null); + } + + public ApiResponse(int statusCode, Map> headers, T data) { + this.statusCode = statusCode; + this.headers = headers; + this.data = data; + } + + public int getStatusCode() { + return statusCode; + } + + public Map> getHeaders() { + return headers; + } + + public T getData() { + return data; + } +} diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/PetApi.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/PetApi.java index cce05b29a3a7..e880e3f9fbf5 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/PetApi.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/PetApi.java @@ -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 + */ + public ApiResponse 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 + */ + public ApiResponse 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 */ public List findPetsByStatus(List status) throws ApiException { + ApiResponse> 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> + */ + public ApiResponse> findPetsByStatusWithHttpInfo(List status) throws ApiException { Call call = findPetsByStatusCall(status, null, null); Type returnType = new TypeToken>(){}.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 */ public List findPetsByTags(List tags) throws ApiException { + ApiResponse> 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> + */ + public ApiResponse> findPetsByTagsWithHttpInfo(List tags) throws ApiException { Call call = findPetsByTagsCall(tags, null, null); Type returnType = new TypeToken>(){}.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 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 + */ + public ApiResponse getPetByIdWithHttpInfo(Long petId) throws ApiException { Call call = getPetByIdCall(petId, null, null); Type returnType = new TypeToken(){}.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 + */ + public ApiResponse 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 + */ + public ApiResponse 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 + */ + public ApiResponse 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; } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/StoreApi.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/StoreApi.java index 551fe0fbfc2c..3e06890a81c5 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/StoreApi.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/StoreApi.java @@ -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 */ public Map getInventory() throws ApiException { - Call call = getInventoryCall( null, null); + ApiResponse> resp = getInventoryWithHttpInfo(); + return resp.getData(); + } + + /** + * Returns pet inventories by status + * Returns a map of status codes to quantities + * @return ApiResponse> + */ + public ApiResponse> getInventoryWithHttpInfo() throws ApiException { + Call call = getInventoryCall(null, null); Type returnType = new TypeToken>(){}.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>(){}.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 resp = placeOrderWithHttpInfo(body); + return resp.getData(); + } + + /** + * Place an order for a pet + * + * @param body order placed for purchasing the pet + * @return ApiResponse + */ + public ApiResponse placeOrderWithHttpInfo(Order body) throws ApiException { Call call = placeOrderCall(body, null, null); Type returnType = new TypeToken(){}.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 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 + */ + public ApiResponse getOrderByIdWithHttpInfo(String orderId) throws ApiException { Call call = getOrderByIdCall(orderId, null, null); Type returnType = new TypeToken(){}.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 + */ + public ApiResponse 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) { diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/UserApi.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/UserApi.java index 57aebd4a4d1b..ccb595525540 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/UserApi.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/UserApi.java @@ -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 + */ + public ApiResponse 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 body) throws ApiException { + createUsersWithArrayInputWithHttpInfo(body); + } + + /** + * Creates list of users with given input array + * + * @param body List of user object + * @return ApiResponse + */ + public ApiResponse createUsersWithArrayInputWithHttpInfo(List 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 body) throws ApiException { + createUsersWithListInputWithHttpInfo(body); + } + + /** + * Creates list of users with given input array + * + * @param body List of user object + * @return ApiResponse + */ + public ApiResponse createUsersWithListInputWithHttpInfo(List 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 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 + */ + public ApiResponse loginUserWithHttpInfo(String username, String password) throws ApiException { + Call call = loginUserCall(username, password, null, null); Type returnType = new TypeToken(){}.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(){}.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 + */ + public ApiResponse 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 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 + */ + public ApiResponse getUserByNameWithHttpInfo(String username) throws ApiException { Call call = getUserByNameCall(username, null, null); Type returnType = new TypeToken(){}.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 + */ + public ApiResponse 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 + */ + public ApiResponse 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) { diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/io/swagger/petstore/test/PetApiTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/io/swagger/petstore/test/PetApiTest.java index b6d8286d7efc..56cc80739848 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/io/swagger/petstore/test/PetApiTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/io/swagger/petstore/test/PetApiTest.java @@ -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 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();