From 60e5a3453442795e371f6b64ee4411759efb39c2 Mon Sep 17 00:00:00 2001 From: xhh Date: Fri, 11 Sep 2015 10:46:56 +0800 Subject: [PATCH 1/4] Update Java-jersey2 client to skip binary support Binary parameter/response support was added to the default Java client codegen which changed the signature of the `invokeAPI` method in "api.mustache", causing the "jersey2" client fail to compile. Here an separate version of `api.mustache` is added for "jersey2" client which does not handle binary support (for now). --- .../Java/libraries/jersey2/api.mustache | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/api.mustache diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/api.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/api.mustache new file mode 100644 index 00000000000..d525db8a28d --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/api.mustache @@ -0,0 +1,98 @@ +package {{package}}; + +import {{invokerPackage}}.ApiException; +import {{invokerPackage}}.ApiClient; +import {{invokerPackage}}.Configuration; +import {{invokerPackage}}.Pair; +import {{invokerPackage}}.TypeRef; + +import {{modelPackage}}.*; + +import java.util.*; + +{{#imports}}import {{import}}; +{{/imports}} + +import java.io.File; +import java.util.Map; +import java.util.HashMap; + +{{>generatedAnnotation}} +{{#operations}} +public class {{classname}} { + private ApiClient {{localVariablePrefix}}apiClient; + + public {{classname}}() { + this(Configuration.getDefaultApiClient()); + } + + public {{classname}}(ApiClient apiClient) { + this.{{localVariablePrefix}}apiClient = apiClient; + } + + public ApiClient getApiClient() { + return {{localVariablePrefix}}apiClient; + } + + public void setApiClient(ApiClient apiClient) { + this.{{localVariablePrefix}}apiClient = apiClient; + } + + {{#operation}} + /** + * {{summary}} + * {{notes}} +{{#allParams}} * @param {{paramName}} {{description}} +{{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} + */ + public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException { + Object {{localVariablePrefix}}postBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}; + {{#allParams}}{{#required}} + // verify the required parameter '{{paramName}}' is set + if ({{paramName}} == null) { + throw new ApiException(400, "Missing the required parameter '{{paramName}}' when calling {{nickname}}"); + } + {{/required}}{{/allParams}} + // create path and map variables + String {{localVariablePrefix}}path = "{{{path}}}".replaceAll("\\{format\\}","json"){{#pathParams}} + .replaceAll("\\{" + "{{baseName}}" + "\\}", {{localVariablePrefix}}apiClient.escapeString({{{paramName}}}.toString())){{/pathParams}}; + + // query params + List {{localVariablePrefix}}queryParams = new ArrayList(); + Map {{localVariablePrefix}}headerParams = new HashMap(); + Map {{localVariablePrefix}}formParams = new HashMap(); + + {{#queryParams}} + {{localVariablePrefix}}queryParams.addAll({{localVariablePrefix}}apiClient.parameterToPairs("{{#collectionFormat}}{{{collectionFormat}}}{{/collectionFormat}}", "{{baseName}}", {{paramName}})); + {{/queryParams}} + + {{#headerParams}}if ({{paramName}} != null) + {{localVariablePrefix}}headerParams.put("{{baseName}}", {{localVariablePrefix}}apiClient.parameterToString({{paramName}})); + {{/headerParams}} + + {{#formParams}}if ({{paramName}} != null) + {{localVariablePrefix}}formParams.put("{{baseName}}", {{paramName}}); + {{/formParams}} + + final String[] {{localVariablePrefix}}accepts = { + {{#produces}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}} + }; + final String {{localVariablePrefix}}accept = {{localVariablePrefix}}apiClient.selectHeaderAccept({{localVariablePrefix}}accepts); + + final String[] {{localVariablePrefix}}contentTypes = { + {{#consumes}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/consumes}} + }; + final String {{localVariablePrefix}}contentType = {{localVariablePrefix}}apiClient.selectHeaderContentType({{localVariablePrefix}}contentTypes); + + String[] {{localVariablePrefix}}authNames = new String[] { {{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}} }; + + {{#returnType}} + TypeRef {{localVariablePrefix}}returnType = new TypeRef<{{{returnType}}}>() {}; + return {{localVariablePrefix}}apiClient.invokeAPI({{localVariablePrefix}}path, "{{httpMethod}}", {{localVariablePrefix}}queryParams, {{localVariablePrefix}}postBody, {{localVariablePrefix}}headerParams, {{localVariablePrefix}}formParams, {{localVariablePrefix}}accept, {{localVariablePrefix}}contentType, {{localVariablePrefix}}authNames, {{localVariablePrefix}}returnType); + {{/returnType}}{{^returnType}} + {{localVariablePrefix}}apiClient.invokeAPI({{localVariablePrefix}}path, "{{httpMethod}}", {{localVariablePrefix}}queryParams, {{localVariablePrefix}}postBody, {{localVariablePrefix}}headerParams, {{localVariablePrefix}}formParams, {{localVariablePrefix}}accept, {{localVariablePrefix}}contentType, {{localVariablePrefix}}authNames, null); + {{/returnType}} + } + {{/operation}} +} +{{/operations}} From def3f5b3fb651affa80da4b6592701335ee12cba Mon Sep 17 00:00:00 2001 From: xhh Date: Fri, 11 Sep 2015 11:48:09 +0800 Subject: [PATCH 2/4] Java-jersey2: record status code and response headers of last request --- .../Java/libraries/jersey2/ApiClient.mustache | 44 ++++++++++++++----- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/ApiClient.mustache index fb5f6b0d107..5033c1986f8 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/ApiClient.mustache @@ -53,6 +53,9 @@ public class ApiClient { private Map authentications; + private int statusCode; + private Map> responseHeaders; + private DateFormat dateFormat; public ApiClient() { @@ -84,6 +87,20 @@ public class ApiClient { return this; } + /** + * Gets the status code of the previous request + */ + public int getStatusCode() { + return statusCode; + } + + /** + * Gets the response headers of the previous request + */ + public Map> getResponseHeaders() { + return responseHeaders; + } + /** * Get authentications (key: authentication name, value: authentication). */ @@ -484,6 +501,9 @@ public class ApiClient { throw new ApiException(500, "unknown method type " + method); } + statusCode = response.getStatusInfo().getStatusCode(); + responseHeaders = buildResponseHeaders(response); + if (response.getStatus() == Status.NO_CONTENT.getStatusCode()) { return null; } else if (response.getStatusInfo().getFamily().equals(Status.Family.SUCCESSFUL)) { @@ -502,23 +522,27 @@ public class ApiClient { // e.printStackTrace(); } } - Map> responseHeaders = new HashMap>(); - for (String key: response.getHeaders().keySet()) { - List values = response.getHeaders().get(key); - List headers = new ArrayList(); - for (Object o : values) { - headers.add(String.valueOf(o)); - } - responseHeaders.put(key, headers); - } throw new ApiException( response.getStatus(), message, - responseHeaders, + buildResponseHeaders(response), respBody); } } + private Map> buildResponseHeaders(Response response) { + Map> responseHeaders = new HashMap>(); + for (Entry> entry: response.getHeaders().entrySet()) { + List values = entry.getValue(); + List headers = new ArrayList(); + for (Object o : values) { + headers.add(String.valueOf(o)); + } + responseHeaders.put(entry.getKey(), headers); + } + return responseHeaders; + } + /** * Update query and header parameters based on authentication settings. * From 34f196a144a3cb705ead9d5474320c0ee5b32fdd Mon Sep 17 00:00:00 2001 From: xhh Date: Fri, 11 Sep 2015 13:15:55 +0800 Subject: [PATCH 3/4] Java-okhttp-gson: allow access to status code and response headers of last (async) request --- .../okhttp-gson/ApiCallback.mustache | 13 +++++++-- .../libraries/okhttp-gson/ApiClient.mustache | 29 +++++++++++++++++-- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/ApiCallback.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/ApiCallback.mustache index 4af16c9faa9..6eee875bdcc 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/ApiCallback.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/ApiCallback.mustache @@ -2,6 +2,9 @@ package {{invokerPackage}}; import java.io.IOException; +import java.util.Map; +import java.util.List; + /** * Callback for asynchronous API call. * @@ -10,13 +13,19 @@ import java.io.IOException; public interface ApiCallback { /** * This is called when the API call fails. + * + * @param e The exception causing the failure + * @param statusCode Status code of the response if available, otherwise it would be 0 + * @param responseHeaders Headers of the response if available, otherwise it would be null */ - void onFailure(ApiException e); + void onFailure(ApiException e, int statusCode, Map> responseHeaders); /** * This is called when the API call succeeded. * * @param result The result deserialized from response + * @param statusCode Status code of the response + * @param responseHeaders Headers of the response */ - void onSuccess(T result); + void onSuccess(T result, int statusCode, Map> responseHeaders); } 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 069aa273b14..f8d7fad3849 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 @@ -48,6 +48,9 @@ public class ApiClient { private Map authentications; + private int statusCode; + private Map> responseHeaders; + private String dateFormat; private DateFormat dateFormatter; private int dateLength; @@ -107,6 +110,24 @@ 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 String getDateFormat() { return dateFormat; } @@ -534,6 +555,8 @@ public class ApiClient { public 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); } catch (IOException e) { throw new ApiException(e); @@ -557,7 +580,7 @@ public class ApiClient { call.enqueue(new Callback() { @Override public void onFailure(Request request, IOException e) { - callback.onFailure(new ApiException(e)); + callback.onFailure(new ApiException(e), 0, null); } @Override @@ -566,10 +589,10 @@ public class ApiClient { try { result = (T) handleResponse(response, returnType); } catch (ApiException e) { - callback.onFailure(e); + callback.onFailure(e, response.code(), response.headers().toMultimap()); return; } - callback.onSuccess(result); + callback.onSuccess(result, response.code(), response.headers().toMultimap()); } }); } From 2e402bba977a664efcb5a725567e0c25b02be5c3 Mon Sep 17 00:00:00 2001 From: xhh Date: Fri, 11 Sep 2015 13:19:23 +0800 Subject: [PATCH 4/4] Rebuild Java clients for the petstore sample --- .../java/io/swagger/client/ApiClient.java | 135 +++++++++++++++--- .../java/io/swagger/client/ApiException.java | 39 +++-- .../java/io/swagger/client/Configuration.java | 2 +- .../src/main/java/io/swagger/client/JSON.java | 2 +- .../src/main/java/io/swagger/client/Pair.java | 2 +- .../java/io/swagger/client/StringUtil.java | 11 +- .../main/java/io/swagger/client/TypeRef.java | 2 +- .../java/io/swagger/client/api/PetApi.java | 132 ++++++++++++----- .../java/io/swagger/client/api/StoreApi.java | 66 ++++++--- .../java/io/swagger/client/api/UserApi.java | 122 +++++++++++----- .../io/swagger/client/auth/ApiKeyAuth.java | 2 +- .../swagger/client/auth/Authentication.java | 2 +- .../io/swagger/client/auth/HttpBasicAuth.java | 2 +- .../java/io/swagger/client/auth/OAuth.java | 2 +- .../io/swagger/client/model/Category.java | 9 +- .../java/io/swagger/client/model/Order.java | 17 +-- .../java/io/swagger/client/model/Pet.java | 17 +-- .../java/io/swagger/client/model/Tag.java | 9 +- .../java/io/swagger/client/model/User.java | 21 +-- .../client/petstore/java/jersey2/hello.txt | 1 + .../java/io/swagger/client/ApiClient.java | 46 ++++-- .../java/io/swagger/client/ApiException.java | 39 +++-- .../java/io/swagger/client/Configuration.java | 2 +- .../src/main/java/io/swagger/client/JSON.java | 2 +- .../src/main/java/io/swagger/client/Pair.java | 2 +- .../java/io/swagger/client/StringUtil.java | 11 +- .../main/java/io/swagger/client/TypeRef.java | 2 +- .../java/io/swagger/client/api/PetApi.java | 26 ++-- .../java/io/swagger/client/api/StoreApi.java | 14 +- .../java/io/swagger/client/api/UserApi.java | 26 ++-- .../io/swagger/client/auth/ApiKeyAuth.java | 2 +- .../swagger/client/auth/Authentication.java | 2 +- .../io/swagger/client/auth/HttpBasicAuth.java | 2 +- .../java/io/swagger/client/auth/OAuth.java | 2 +- .../io/swagger/client/model/Category.java | 13 +- .../java/io/swagger/client/model/Order.java | 17 +-- .../java/io/swagger/client/model/Pet.java | 17 +-- .../java/io/swagger/client/model/Tag.java | 13 +- .../java/io/swagger/client/model/User.java | 25 ++-- .../java/io/swagger/client/ApiCallback.java | 13 +- .../java/io/swagger/client/ApiClient.java | 29 +++- .../java/io/swagger/client/ApiException.java | 2 +- .../java/io/swagger/client/Configuration.java | 2 +- .../src/main/java/io/swagger/client/Pair.java | 2 +- .../java/io/swagger/client/StringUtil.java | 2 +- .../java/io/swagger/client/api/UserApi.java | 4 +- .../io/swagger/client/auth/ApiKeyAuth.java | 2 +- .../swagger/client/auth/Authentication.java | 2 +- .../java/io/swagger/client/auth/OAuth.java | 2 +- .../io/swagger/petstore/test/PetApiTest.java | 78 ++++++++++ 50 files changed, 720 insertions(+), 276 deletions(-) create mode 100644 samples/client/petstore/java/jersey2/hello.txt diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/ApiClient.java index bc2dab2e8a8..0d531986afa 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/ApiClient.java @@ -28,6 +28,7 @@ import java.io.IOException; import java.io.File; import java.io.UnsupportedEncodingException; +import java.io.DataInputStream; import java.text.DateFormat; import java.text.SimpleDateFormat; @@ -38,7 +39,7 @@ import io.swagger.client.auth.ApiKeyAuth; import io.swagger.client.auth.OAuth; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-24T11:46:58.447+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:58.351+08:00") public class ApiClient { private Map hostMap = new HashMap(); private Map defaultHeaderMap = new HashMap(); @@ -48,6 +49,9 @@ public class ApiClient { private Map authentications; + private int statusCode; + private Map> responseHeaders; + private DateFormat dateFormat; public ApiClient() { @@ -78,6 +82,20 @@ public ApiClient setBasePath(String basePath) { return this; } + /** + * Gets the status code of the previous request + */ + public int getStatusCode() { + return statusCode; + } + + /** + * Gets the response headers of the previous request + */ + public Map> getResponseHeaders() { + return responseHeaders; + } + /** * Get authentications (key: authentication name, value: authentication). */ @@ -371,22 +389,12 @@ public T deserialize(ClientResponse response, TypeRef returnType) throws Api } } - /** - * Invoke API by sending HTTP request with the given options. - * - * @param path The sub-path of the HTTP URL - * @param method The request method, one of "GET", "POST", "PUT", and "DELETE" - * @param queryParams The query parameters - * @param body The request body object - * @param headerParams The header parameters - * @param formParams The form parameters - * @param accept The request's Accept header - * @param contentType The request's Content-Type header - * @param authNames The authentications to apply - * @param returnType The return type into which to deserialize the response - * @return The response body in type of string - */ - public T invokeAPI(String path, String method, List queryParams, Object body, Map headerParams, Map formParams, String accept, String contentType, String[] authNames, TypeRef returnType) throws ApiException { + private ClientResponse getAPIResponse(String path, String method, List queryParams, Object body, byte[] binaryBody, Map headerParams, Map formParams, String accept, String contentType, String[] authNames) throws ApiException { + + if (body != null && binaryBody != null){ + throw new ApiException(500, "either body or binaryBody must be null"); + } + updateParamsForAuth(authNames, queryParams, headerParams); Client client = getClient(); @@ -446,7 +454,10 @@ public T invokeAPI(String path, String method, List queryParams, Objec if (encodedFormParams != null) { response = builder.type(contentType).post(ClientResponse.class, encodedFormParams); } else if (body == null) { - response = builder.post(ClientResponse.class, null); + if(binaryBody == null) + response = builder.post(ClientResponse.class, null); + else + response = builder.type(contentType).post(ClientResponse.class, binaryBody); } else if (body instanceof FormDataMultiPart) { response = builder.type(contentType).post(ClientResponse.class, body); } else { @@ -456,7 +467,10 @@ public T invokeAPI(String path, String method, List queryParams, Objec if (encodedFormParams != null) { response = builder.type(contentType).put(ClientResponse.class, encodedFormParams); } else if(body == null) { - response = builder.put(ClientResponse.class, serialize(body, contentType)); + if(binaryBody == null) + response = builder.put(ClientResponse.class, null); + else + response = builder.type(contentType).put(ClientResponse.class, binaryBody); } else { response = builder.type(contentType).put(ClientResponse.class, serialize(body, contentType)); } @@ -464,15 +478,42 @@ public T invokeAPI(String path, String method, List queryParams, Objec if (encodedFormParams != null) { response = builder.type(contentType).delete(ClientResponse.class, encodedFormParams); } else if(body == null) { - response = builder.delete(ClientResponse.class); + if(binaryBody == null) + response = builder.delete(ClientResponse.class); + else + response = builder.type(contentType).delete(ClientResponse.class, binaryBody); } else { response = builder.type(contentType).delete(ClientResponse.class, serialize(body, contentType)); } } else { throw new ApiException(500, "unknown method type " + method); } + return response; + } + + /** + * Invoke API by sending HTTP request with the given options. + * + * @param path The sub-path of the HTTP URL + * @param method The request method, one of "GET", "POST", "PUT", and "DELETE" + * @param queryParams The query parameters + * @param body The request body object - if it is not binary, otherwise null + * @param binaryBody The request body object - if it is binary, otherwise null + * @param headerParams The header parameters + * @param formParams The form parameters + * @param accept The request's Accept header + * @param contentType The request's Content-Type header + * @param authNames The authentications to apply + * @return The response body in type of string + */ + public T invokeAPI(String path, String method, List queryParams, Object body, byte[] binaryBody, Map headerParams, Map formParams, String accept, String contentType, String[] authNames, TypeRef returnType) throws ApiException { + + ClientResponse response = getAPIResponse(path, method, queryParams, body, binaryBody, headerParams, formParams, accept, contentType, authNames); - if (response.getStatusInfo() == ClientResponse.Status.NO_CONTENT) { + statusCode = response.getStatusInfo().getStatusCode(); + responseHeaders = response.getHeaders(); + + if(response.getStatusInfo() == ClientResponse.Status.NO_CONTENT) { return null; } else if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) { if (returnType == null) @@ -497,6 +538,58 @@ public T invokeAPI(String path, String method, List queryParams, Objec respBody); } } + /** + * Invoke API by sending HTTP request with the given options - return binary result + * + * @param path The sub-path of the HTTP URL + * @param method The request method, one of "GET", "POST", "PUT", and "DELETE" + * @param queryParams The query parameters + * @param body The request body object - if it is not binary, otherwise null + * @param binaryBody The request body object - if it is binary, otherwise null + * @param headerParams The header parameters + * @param formParams The form parameters + * @param accept The request's Accept header + * @param contentType The request's Content-Type header + * @param authNames The authentications to apply + * @return The response body in type of string + */ + public byte[] invokeBinaryAPI(String path, String method, List queryParams, Object body, byte[] binaryBody, Map headerParams, Map formParams, String accept, String contentType, String[]authNames) throws ApiException { + + ClientResponse response = getAPIResponse(path, method, queryParams, body, binaryBody, headerParams, formParams, accept, contentType, authNames); + + if(response.getStatusInfo() == ClientResponse.Status.NO_CONTENT) { + return null; + } + else if(response.getStatusInfo().getFamily() == Family.SUCCESSFUL) { + if(response.hasEntity()) { + DataInputStream stream = new DataInputStream(response.getEntityInputStream()); + byte[] data = new byte[response.getLength()]; + try { + stream.readFully(data); + } catch (IOException ex) { + throw new ApiException(500, "Error obtaining binary response data"); + } + return data; + } + else { + return new byte[0]; + } + } + else { + String message = "error"; + if(response.hasEntity()) { + try{ + message = String.valueOf(response.getEntity(String.class)); + } + catch (RuntimeException e) { + // e.printStackTrace(); + } + } + throw new ApiException( + response.getStatusInfo().getStatusCode(), + message); + } + } /** * Update query and header parameters based on authentication settings. diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/ApiException.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/ApiException.java index 679786deb10..88761f16e9c 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/ApiException.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/ApiException.java @@ -3,23 +3,48 @@ import java.util.Map; import java.util.List; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-24T11:46:58.447+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:58.351+08:00") public class ApiException extends Exception { private int code = 0; - private String message = null; private Map> responseHeaders = null; private String responseBody = null; public ApiException() {} + public ApiException(Throwable throwable) { + super(throwable); + } + + public ApiException(String message) { + super(message); + } + + public ApiException(String message, Throwable throwable, int code, Map> responseHeaders, String responseBody) { + super(message, throwable); + this.code = code; + this.responseHeaders = responseHeaders; + this.responseBody = responseBody; + } + + public ApiException(String message, int code, Map> responseHeaders, String responseBody) { + this(message, (Throwable) null, code, responseHeaders, responseBody); + } + + public ApiException(String message, Throwable throwable, int code, Map> responseHeaders) { + this(message, throwable, code, responseHeaders, null); + } + + public ApiException(int code, Map> responseHeaders, String responseBody) { + this((String) null, (Throwable) null, code, responseHeaders, responseBody); + } + public ApiException(int code, String message) { + super(message); this.code = code; - this.message = message; } public ApiException(int code, String message, Map> responseHeaders, String responseBody) { - this.code = code; - this.message = message; + this(code, message); this.responseHeaders = responseHeaders; this.responseBody = responseBody; } @@ -28,10 +53,6 @@ public int getCode() { return code; } - public String getMessage() { - return message; - } - /** * Get the HTTP response headers. */ diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/Configuration.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/Configuration.java index 0a674b8d52a..47acca1b8ea 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/Configuration.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/Configuration.java @@ -1,6 +1,6 @@ package io.swagger.client; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-24T11:46:58.447+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:58.351+08:00") public class Configuration { private static ApiClient defaultApiClient = new ApiClient(); diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/JSON.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/JSON.java index 5523b921e45..dd716e6fd90 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/JSON.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/JSON.java @@ -6,7 +6,7 @@ import java.io.IOException; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-24T18:19:30.060+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:58.351+08:00") public class JSON { private ObjectMapper mapper; diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/Pair.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/Pair.java index 9f9e2c96b4c..0bff951077c 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/Pair.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/Pair.java @@ -1,6 +1,6 @@ package io.swagger.client; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-24T11:46:58.447+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:58.351+08:00") public class Pair { private String name = ""; private String value = ""; diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/StringUtil.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/StringUtil.java index de5e940ba55..df5670a8b0d 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/StringUtil.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/StringUtil.java @@ -1,6 +1,6 @@ package io.swagger.client; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-24T11:46:58.447+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:58.351+08:00") public class StringUtil { /** * Check if the given array contains the given value (with case-insensitive comparison). @@ -39,4 +39,13 @@ public static String join(String[] array, String separator) { } return out.toString(); } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + public static String toIndentedString(Object o) { + if (o == null) return "null"; + return o.toString().replace("\n", "\n "); + } } diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/TypeRef.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/TypeRef.java index cd69bd71e7c..12a842d8404 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/TypeRef.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/TypeRef.java @@ -3,7 +3,7 @@ import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-24T11:46:58.447+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:58.351+08:00") public class TypeRef { private final Type type; diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/api/PetApi.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/api/PetApi.java index 75dfc35beb1..3a14b07dc25 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/api/PetApi.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/api/PetApi.java @@ -17,7 +17,7 @@ import java.util.Map; import java.util.HashMap; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-24T11:46:58.447+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:58.351+08:00") public class PetApi { private ApiClient apiClient; @@ -46,8 +46,8 @@ public void setApiClient(ApiClient apiClient) { */ public void updatePet (Pet body) throws ApiException { Object postBody = body; + byte[] postBinaryBody = null; - // create path and map variables String path = "/pet".replaceAll("\\{format\\}","json"); @@ -73,9 +73,16 @@ public void updatePet (Pet body) throws ApiException { final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { "petstore_auth" }; + + + + - apiClient.invokeAPI(path, "PUT", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, null); + apiClient.invokeAPI(path, "PUT", queryParams, postBody, postBinaryBody, headerParams, formParams, accept, contentType, authNames, null); + + + } /** @@ -86,8 +93,8 @@ public void updatePet (Pet body) throws ApiException { */ public void addPet (Pet body) throws ApiException { Object postBody = body; + byte[] postBinaryBody = null; - // create path and map variables String path = "/pet".replaceAll("\\{format\\}","json"); @@ -113,9 +120,16 @@ public void addPet (Pet body) throws ApiException { final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { "petstore_auth" }; + + + + - apiClient.invokeAPI(path, "POST", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, null); + apiClient.invokeAPI(path, "POST", queryParams, postBody, postBinaryBody, headerParams, formParams, accept, contentType, authNames, null); + + + } /** @@ -126,8 +140,8 @@ public void addPet (Pet body) throws ApiException { */ public List findPetsByStatus (List status) throws ApiException { Object postBody = null; + byte[] postBinaryBody = null; - // create path and map variables String path = "/pet/findByStatus".replaceAll("\\{format\\}","json"); @@ -155,10 +169,17 @@ public List findPetsByStatus (List status) throws ApiException { final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { "petstore_auth" }; + + + + TypeRef returnType = new TypeRef>() {}; - return apiClient.invokeAPI(path, "GET", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType); + return apiClient.invokeAPI(path, "GET", queryParams, postBody, postBinaryBody, headerParams, formParams, accept, contentType, authNames, returnType); + + + } /** @@ -169,8 +190,8 @@ public List findPetsByStatus (List status) throws ApiException { */ public List findPetsByTags (List tags) throws ApiException { Object postBody = null; + byte[] postBinaryBody = null; - // create path and map variables String path = "/pet/findByTags".replaceAll("\\{format\\}","json"); @@ -198,10 +219,17 @@ public List findPetsByTags (List tags) throws ApiException { final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { "petstore_auth" }; + + + + TypeRef returnType = new TypeRef>() {}; - return apiClient.invokeAPI(path, "GET", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType); + return apiClient.invokeAPI(path, "GET", queryParams, postBody, postBinaryBody, headerParams, formParams, accept, contentType, authNames, returnType); + + + } /** @@ -212,13 +240,13 @@ public List findPetsByTags (List tags) throws ApiException { */ public Pet getPetById (Long petId) throws ApiException { Object postBody = null; + byte[] postBinaryBody = null; - // verify the required parameter 'petId' is set - if (petId == null) { - throw new ApiException(400, "Missing the required parameter 'petId' when calling getPetById"); - } - - + // verify the required parameter 'petId' is set + if (petId == null) { + throw new ApiException(400, "Missing the required parameter 'petId' when calling getPetById"); + } + // create path and map variables String path = "/pet/{petId}".replaceAll("\\{format\\}","json") .replaceAll("\\{" + "petId" + "\\}", apiClient.escapeString(petId.toString())); @@ -244,11 +272,18 @@ public Pet getPetById (Long petId) throws ApiException { }; final String contentType = apiClient.selectHeaderContentType(contentTypes); - String[] authNames = new String[] { "api_key", "petstore_auth" }; + String[] authNames = new String[] { "petstore_auth", "api_key" }; + + + + TypeRef returnType = new TypeRef() {}; - return apiClient.invokeAPI(path, "GET", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType); + return apiClient.invokeAPI(path, "GET", queryParams, postBody, postBinaryBody, headerParams, formParams, accept, contentType, authNames, returnType); + + + } /** @@ -261,13 +296,13 @@ public Pet getPetById (Long petId) throws ApiException { */ public void updatePetWithForm (String petId, String name, String status) throws ApiException { Object postBody = null; + byte[] postBinaryBody = null; - // verify the required parameter 'petId' is set - if (petId == null) { - throw new ApiException(400, "Missing the required parameter 'petId' when calling updatePetWithForm"); - } - - + // verify the required parameter 'petId' is set + if (petId == null) { + throw new ApiException(400, "Missing the required parameter 'petId' when calling updatePetWithForm"); + } + // create path and map variables String path = "/pet/{petId}".replaceAll("\\{format\\}","json") .replaceAll("\\{" + "petId" + "\\}", apiClient.escapeString(petId.toString())); @@ -298,9 +333,16 @@ public void updatePetWithForm (String petId, String name, String status) throws final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { "petstore_auth" }; + + + + - apiClient.invokeAPI(path, "POST", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, null); + apiClient.invokeAPI(path, "POST", queryParams, postBody, postBinaryBody, headerParams, formParams, accept, contentType, authNames, null); + + + } /** @@ -312,13 +354,13 @@ public void updatePetWithForm (String petId, String name, String status) throws */ public void deletePet (Long petId, String apiKey) throws ApiException { Object postBody = null; + byte[] postBinaryBody = null; - // verify the required parameter 'petId' is set - if (petId == null) { - throw new ApiException(400, "Missing the required parameter 'petId' when calling deletePet"); - } - - + // verify the required parameter 'petId' is set + if (petId == null) { + throw new ApiException(400, "Missing the required parameter 'petId' when calling deletePet"); + } + // create path and map variables String path = "/pet/{petId}".replaceAll("\\{format\\}","json") .replaceAll("\\{" + "petId" + "\\}", apiClient.escapeString(petId.toString())); @@ -347,9 +389,16 @@ public void deletePet (Long petId, String apiKey) throws ApiException { final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { "petstore_auth" }; + + + + - apiClient.invokeAPI(path, "DELETE", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, null); + apiClient.invokeAPI(path, "DELETE", queryParams, postBody, postBinaryBody, headerParams, formParams, accept, contentType, authNames, null); + + + } /** @@ -362,13 +411,13 @@ public void deletePet (Long petId, String apiKey) throws ApiException { */ public void uploadFile (Long petId, String additionalMetadata, File file) throws ApiException { Object postBody = null; + byte[] postBinaryBody = null; - // verify the required parameter 'petId' is set - if (petId == null) { - throw new ApiException(400, "Missing the required parameter 'petId' when calling uploadFile"); - } - - + // verify the required parameter 'petId' is set + if (petId == null) { + throw new ApiException(400, "Missing the required parameter 'petId' when calling uploadFile"); + } + // create path and map variables String path = "/pet/{petId}/uploadImage".replaceAll("\\{format\\}","json") .replaceAll("\\{" + "petId" + "\\}", apiClient.escapeString(petId.toString())); @@ -399,9 +448,16 @@ public void uploadFile (Long petId, String additionalMetadata, File file) throws final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { "petstore_auth" }; + + + - apiClient.invokeAPI(path, "POST", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, null); + apiClient.invokeAPI(path, "POST", queryParams, postBody, postBinaryBody, headerParams, formParams, accept, contentType, authNames, null); + + + + } } diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/api/StoreApi.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/api/StoreApi.java index a488fb37445..a7c73b93fa7 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/api/StoreApi.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/api/StoreApi.java @@ -17,7 +17,7 @@ import java.util.Map; import java.util.HashMap; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-24T11:46:58.447+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:58.351+08:00") public class StoreApi { private ApiClient apiClient; @@ -45,8 +45,8 @@ public void setApiClient(ApiClient apiClient) { */ public Map getInventory () throws ApiException { Object postBody = null; + byte[] postBinaryBody = null; - // create path and map variables String path = "/store/inventory".replaceAll("\\{format\\}","json"); @@ -72,10 +72,17 @@ public Map getInventory () throws ApiException { final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { "api_key" }; + + + + TypeRef returnType = new TypeRef>() {}; - return apiClient.invokeAPI(path, "GET", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType); + return apiClient.invokeAPI(path, "GET", queryParams, postBody, postBinaryBody, headerParams, formParams, accept, contentType, authNames, returnType); + + + } /** @@ -86,8 +93,8 @@ public Map getInventory () throws ApiException { */ public Order placeOrder (Order body) throws ApiException { Object postBody = body; + byte[] postBinaryBody = null; - // create path and map variables String path = "/store/order".replaceAll("\\{format\\}","json"); @@ -113,10 +120,17 @@ public Order placeOrder (Order body) throws ApiException { final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { }; + + + + TypeRef returnType = new TypeRef() {}; - return apiClient.invokeAPI(path, "POST", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType); + return apiClient.invokeAPI(path, "POST", queryParams, postBody, postBinaryBody, headerParams, formParams, accept, contentType, authNames, returnType); + + + } /** @@ -127,13 +141,13 @@ public Order placeOrder (Order body) throws ApiException { */ public Order getOrderById (String orderId) throws ApiException { Object postBody = null; + byte[] postBinaryBody = null; - // verify the required parameter 'orderId' is set - if (orderId == null) { - throw new ApiException(400, "Missing the required parameter 'orderId' when calling getOrderById"); - } - - + // verify the required parameter 'orderId' is set + if (orderId == null) { + throw new ApiException(400, "Missing the required parameter 'orderId' when calling getOrderById"); + } + // create path and map variables String path = "/store/order/{orderId}".replaceAll("\\{format\\}","json") .replaceAll("\\{" + "orderId" + "\\}", apiClient.escapeString(orderId.toString())); @@ -160,10 +174,17 @@ public Order getOrderById (String orderId) throws ApiException { final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { }; + + + + TypeRef returnType = new TypeRef() {}; - return apiClient.invokeAPI(path, "GET", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType); + return apiClient.invokeAPI(path, "GET", queryParams, postBody, postBinaryBody, headerParams, formParams, accept, contentType, authNames, returnType); + + + } /** @@ -174,13 +195,13 @@ public Order getOrderById (String orderId) throws ApiException { */ public void deleteOrder (String orderId) throws ApiException { Object postBody = null; + byte[] postBinaryBody = null; - // verify the required parameter 'orderId' is set - if (orderId == null) { - throw new ApiException(400, "Missing the required parameter 'orderId' when calling deleteOrder"); - } - - + // verify the required parameter 'orderId' is set + if (orderId == null) { + throw new ApiException(400, "Missing the required parameter 'orderId' when calling deleteOrder"); + } + // create path and map variables String path = "/store/order/{orderId}".replaceAll("\\{format\\}","json") .replaceAll("\\{" + "orderId" + "\\}", apiClient.escapeString(orderId.toString())); @@ -207,9 +228,16 @@ public void deleteOrder (String orderId) throws ApiException { final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { }; + + + - apiClient.invokeAPI(path, "DELETE", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, null); + apiClient.invokeAPI(path, "DELETE", queryParams, postBody, postBinaryBody, headerParams, formParams, accept, contentType, authNames, null); + + + + } } diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/api/UserApi.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/api/UserApi.java index 3dee565a271..dd798e3e797 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/api/UserApi.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/api/UserApi.java @@ -17,7 +17,7 @@ import java.util.Map; import java.util.HashMap; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-24T11:46:58.447+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:58.351+08:00") public class UserApi { private ApiClient apiClient; @@ -46,8 +46,8 @@ public void setApiClient(ApiClient apiClient) { */ public void createUser (User body) throws ApiException { Object postBody = body; + byte[] postBinaryBody = null; - // create path and map variables String path = "/user".replaceAll("\\{format\\}","json"); @@ -73,9 +73,16 @@ public void createUser (User body) throws ApiException { final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { }; + + + + - apiClient.invokeAPI(path, "POST", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, null); + apiClient.invokeAPI(path, "POST", queryParams, postBody, postBinaryBody, headerParams, formParams, accept, contentType, authNames, null); + + + } /** @@ -86,8 +93,8 @@ public void createUser (User body) throws ApiException { */ public void createUsersWithArrayInput (List body) throws ApiException { Object postBody = body; + byte[] postBinaryBody = null; - // create path and map variables String path = "/user/createWithArray".replaceAll("\\{format\\}","json"); @@ -113,9 +120,16 @@ public void createUsersWithArrayInput (List body) throws ApiException { final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { }; + + + + - apiClient.invokeAPI(path, "POST", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, null); + apiClient.invokeAPI(path, "POST", queryParams, postBody, postBinaryBody, headerParams, formParams, accept, contentType, authNames, null); + + + } /** @@ -126,8 +140,8 @@ public void createUsersWithArrayInput (List body) throws ApiException { */ public void createUsersWithListInput (List body) throws ApiException { Object postBody = body; + byte[] postBinaryBody = null; - // create path and map variables String path = "/user/createWithList".replaceAll("\\{format\\}","json"); @@ -153,9 +167,16 @@ public void createUsersWithListInput (List body) throws ApiException { final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { }; + + + + + + apiClient.invokeAPI(path, "POST", queryParams, postBody, postBinaryBody, headerParams, formParams, accept, contentType, authNames, null); - apiClient.invokeAPI(path, "POST", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, null); + + } /** @@ -167,8 +188,8 @@ public void createUsersWithListInput (List body) throws ApiException { */ public String loginUser (String username, String password) throws ApiException { Object postBody = null; + byte[] postBinaryBody = null; - // create path and map variables String path = "/user/login".replaceAll("\\{format\\}","json"); @@ -198,10 +219,17 @@ public String loginUser (String username, String password) throws ApiException { final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { }; + + + + TypeRef returnType = new TypeRef() {}; - return apiClient.invokeAPI(path, "GET", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType); + return apiClient.invokeAPI(path, "GET", queryParams, postBody, postBinaryBody, headerParams, formParams, accept, contentType, authNames, returnType); + + + } /** @@ -211,8 +239,8 @@ public String loginUser (String username, String password) throws ApiException { */ public void logoutUser () throws ApiException { Object postBody = null; + byte[] postBinaryBody = null; - // create path and map variables String path = "/user/logout".replaceAll("\\{format\\}","json"); @@ -238,26 +266,33 @@ public void logoutUser () throws ApiException { final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { }; + - apiClient.invokeAPI(path, "GET", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, null); + + + + apiClient.invokeAPI(path, "GET", queryParams, postBody, postBinaryBody, headerParams, formParams, accept, contentType, authNames, null); + + + } /** * Get user by user name * - * @param username The name that needs to be fetched. Use user1 for testing. + * @param username The name that needs to be fetched. Use user1 for testing. * @return User */ public User getUserByName (String username) throws ApiException { Object postBody = null; + byte[] postBinaryBody = null; - // verify the required parameter 'username' is set - if (username == null) { - throw new ApiException(400, "Missing the required parameter 'username' when calling getUserByName"); - } - - + // verify the required parameter 'username' is set + if (username == null) { + throw new ApiException(400, "Missing the required parameter 'username' when calling getUserByName"); + } + // create path and map variables String path = "/user/{username}".replaceAll("\\{format\\}","json") .replaceAll("\\{" + "username" + "\\}", apiClient.escapeString(username.toString())); @@ -284,10 +319,17 @@ public User getUserByName (String username) throws ApiException { final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { }; + + + + TypeRef returnType = new TypeRef() {}; - return apiClient.invokeAPI(path, "GET", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType); + return apiClient.invokeAPI(path, "GET", queryParams, postBody, postBinaryBody, headerParams, formParams, accept, contentType, authNames, returnType); + + + } /** @@ -299,13 +341,13 @@ public User getUserByName (String username) throws ApiException { */ public void updateUser (String username, User body) throws ApiException { Object postBody = body; + byte[] postBinaryBody = null; - // verify the required parameter 'username' is set - if (username == null) { - throw new ApiException(400, "Missing the required parameter 'username' when calling updateUser"); - } - - + // verify the required parameter 'username' is set + if (username == null) { + throw new ApiException(400, "Missing the required parameter 'username' when calling updateUser"); + } + // create path and map variables String path = "/user/{username}".replaceAll("\\{format\\}","json") .replaceAll("\\{" + "username" + "\\}", apiClient.escapeString(username.toString())); @@ -332,9 +374,16 @@ public void updateUser (String username, User body) throws ApiException { final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { }; + + + + - apiClient.invokeAPI(path, "PUT", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, null); + apiClient.invokeAPI(path, "PUT", queryParams, postBody, postBinaryBody, headerParams, formParams, accept, contentType, authNames, null); + + + } /** @@ -345,13 +394,13 @@ public void updateUser (String username, User body) throws ApiException { */ public void deleteUser (String username) throws ApiException { Object postBody = null; + byte[] postBinaryBody = null; - // verify the required parameter 'username' is set - if (username == null) { - throw new ApiException(400, "Missing the required parameter 'username' when calling deleteUser"); - } - - + // verify the required parameter 'username' is set + if (username == null) { + throw new ApiException(400, "Missing the required parameter 'username' when calling deleteUser"); + } + // create path and map variables String path = "/user/{username}".replaceAll("\\{format\\}","json") .replaceAll("\\{" + "username" + "\\}", apiClient.escapeString(username.toString())); @@ -378,9 +427,16 @@ public void deleteUser (String username) throws ApiException { final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { }; + + + - apiClient.invokeAPI(path, "DELETE", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, null); + apiClient.invokeAPI(path, "DELETE", queryParams, postBody, postBinaryBody, headerParams, formParams, accept, contentType, authNames, null); + + + + } } diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/ApiKeyAuth.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/ApiKeyAuth.java index dccddad0088..84461023650 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/ApiKeyAuth.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/ApiKeyAuth.java @@ -5,7 +5,7 @@ import java.util.Map; import java.util.List; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-24T11:46:58.447+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:58.351+08:00") public class ApiKeyAuth implements Authentication { private final String location; private final String paramName; diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/Authentication.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/Authentication.java index 7efcc795425..efb1fc172ea 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/Authentication.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/Authentication.java @@ -5,7 +5,7 @@ import java.util.Map; import java.util.List; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-24T11:46:58.447+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:58.351+08:00") public interface Authentication { /** Apply authentication settings to header and query params. */ void applyToParams(List queryParams, Map headerParams); diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/HttpBasicAuth.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/HttpBasicAuth.java index 41d7988af0d..1c3b905baed 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/HttpBasicAuth.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/HttpBasicAuth.java @@ -8,7 +8,7 @@ import java.io.UnsupportedEncodingException; import javax.xml.bind.DatatypeConverter; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-24T11:46:58.447+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:58.351+08:00") public class HttpBasicAuth implements Authentication { private String username; private String password; diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/OAuth.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/OAuth.java index 20520b96813..a5d6fa74040 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/OAuth.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/auth/OAuth.java @@ -5,7 +5,7 @@ import java.util.Map; import java.util.List; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-24T11:46:58.447+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:58.351+08:00") public class OAuth implements Authentication { @Override public void applyToParams(List queryParams, Map headerParams) { diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/Category.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/Category.java index b7ccc46204c..f3ba53b985d 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/Category.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/Category.java @@ -1,5 +1,6 @@ package io.swagger.client.model; +import io.swagger.client.StringUtil; @@ -8,7 +9,7 @@ @ApiModel(description = "") -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-24T11:46:58.447+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:58.351+08:00") public class Category { private Long id = null; @@ -45,9 +46,9 @@ public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class Category {\n"); - sb.append(" id: ").append(id).append("\n"); - sb.append(" name: ").append(name).append("\n"); - sb.append("}\n"); + sb.append(" id: ").append(StringUtil.toIndentedString(id)).append("\n"); + sb.append(" name: ").append(StringUtil.toIndentedString(name)).append("\n"); + sb.append("}"); return sb.toString(); } } diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/Order.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/Order.java index e89c1f3fb40..16855721cd0 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/Order.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/Order.java @@ -1,5 +1,6 @@ package io.swagger.client.model; +import io.swagger.client.StringUtil; import java.util.Date; @@ -9,7 +10,7 @@ @ApiModel(description = "") -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-24T18:19:30.060+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:58.351+08:00") public class Order { private Long id = null; @@ -115,13 +116,13 @@ public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class Order {\n"); - sb.append(" id: ").append(id).append("\n"); - sb.append(" petId: ").append(petId).append("\n"); - sb.append(" quantity: ").append(quantity).append("\n"); - sb.append(" shipDate: ").append(shipDate).append("\n"); - sb.append(" status: ").append(status).append("\n"); - sb.append(" complete: ").append(complete).append("\n"); - sb.append("}\n"); + sb.append(" id: ").append(StringUtil.toIndentedString(id)).append("\n"); + sb.append(" petId: ").append(StringUtil.toIndentedString(petId)).append("\n"); + sb.append(" quantity: ").append(StringUtil.toIndentedString(quantity)).append("\n"); + sb.append(" shipDate: ").append(StringUtil.toIndentedString(shipDate)).append("\n"); + sb.append(" status: ").append(StringUtil.toIndentedString(status)).append("\n"); + sb.append(" complete: ").append(StringUtil.toIndentedString(complete)).append("\n"); + sb.append("}"); return sb.toString(); } } diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/Pet.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/Pet.java index b3b0e1b5347..9f06fc171aa 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/Pet.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/Pet.java @@ -1,5 +1,6 @@ package io.swagger.client.model; +import io.swagger.client.StringUtil; import io.swagger.client.model.Category; import java.util.*; import io.swagger.client.model.Tag; @@ -11,7 +12,7 @@ @ApiModel(description = "") -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-24T18:19:30.060+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:58.351+08:00") public class Pet { private Long id = null; @@ -117,13 +118,13 @@ public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class Pet {\n"); - sb.append(" id: ").append(id).append("\n"); - sb.append(" category: ").append(category).append("\n"); - sb.append(" name: ").append(name).append("\n"); - sb.append(" photoUrls: ").append(photoUrls).append("\n"); - sb.append(" tags: ").append(tags).append("\n"); - sb.append(" status: ").append(status).append("\n"); - sb.append("}\n"); + sb.append(" id: ").append(StringUtil.toIndentedString(id)).append("\n"); + sb.append(" category: ").append(StringUtil.toIndentedString(category)).append("\n"); + sb.append(" name: ").append(StringUtil.toIndentedString(name)).append("\n"); + sb.append(" photoUrls: ").append(StringUtil.toIndentedString(photoUrls)).append("\n"); + sb.append(" tags: ").append(StringUtil.toIndentedString(tags)).append("\n"); + sb.append(" status: ").append(StringUtil.toIndentedString(status)).append("\n"); + sb.append("}"); return sb.toString(); } } diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/Tag.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/Tag.java index 2550d7c7636..4fd62f39a6b 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/Tag.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/Tag.java @@ -1,5 +1,6 @@ package io.swagger.client.model; +import io.swagger.client.StringUtil; @@ -8,7 +9,7 @@ @ApiModel(description = "") -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-24T11:46:58.447+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:58.351+08:00") public class Tag { private Long id = null; @@ -45,9 +46,9 @@ public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class Tag {\n"); - sb.append(" id: ").append(id).append("\n"); - sb.append(" name: ").append(name).append("\n"); - sb.append("}\n"); + sb.append(" id: ").append(StringUtil.toIndentedString(id)).append("\n"); + sb.append(" name: ").append(StringUtil.toIndentedString(name)).append("\n"); + sb.append("}"); return sb.toString(); } } diff --git a/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/User.java b/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/User.java index d27f1c2658d..df035a093e1 100644 --- a/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/User.java +++ b/samples/client/petstore/java/default/src/main/java/io/swagger/client/model/User.java @@ -1,5 +1,6 @@ package io.swagger.client.model; +import io.swagger.client.StringUtil; @@ -8,7 +9,7 @@ @ApiModel(description = "") -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-24T11:46:58.447+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:58.351+08:00") public class User { private Long id = null; @@ -124,15 +125,15 @@ public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class User {\n"); - sb.append(" id: ").append(id).append("\n"); - sb.append(" username: ").append(username).append("\n"); - sb.append(" firstName: ").append(firstName).append("\n"); - sb.append(" lastName: ").append(lastName).append("\n"); - sb.append(" email: ").append(email).append("\n"); - sb.append(" password: ").append(password).append("\n"); - sb.append(" phone: ").append(phone).append("\n"); - sb.append(" userStatus: ").append(userStatus).append("\n"); - sb.append("}\n"); + sb.append(" id: ").append(StringUtil.toIndentedString(id)).append("\n"); + sb.append(" username: ").append(StringUtil.toIndentedString(username)).append("\n"); + sb.append(" firstName: ").append(StringUtil.toIndentedString(firstName)).append("\n"); + sb.append(" lastName: ").append(StringUtil.toIndentedString(lastName)).append("\n"); + sb.append(" email: ").append(StringUtil.toIndentedString(email)).append("\n"); + sb.append(" password: ").append(StringUtil.toIndentedString(password)).append("\n"); + sb.append(" phone: ").append(StringUtil.toIndentedString(phone)).append("\n"); + sb.append(" userStatus: ").append(StringUtil.toIndentedString(userStatus)).append("\n"); + sb.append("}"); return sb.toString(); } } diff --git a/samples/client/petstore/java/jersey2/hello.txt b/samples/client/petstore/java/jersey2/hello.txt new file mode 100644 index 00000000000..6769dd60bdf --- /dev/null +++ b/samples/client/petstore/java/jersey2/hello.txt @@ -0,0 +1 @@ +Hello world! \ No newline at end of file diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/ApiClient.java index 3ddf4621ae8..56d7a5453ed 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/ApiClient.java @@ -43,7 +43,7 @@ import io.swagger.client.auth.ApiKeyAuth; import io.swagger.client.auth.OAuth; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-22T21:47:05.989+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:51.678+08:00") public class ApiClient { private Map hostMap = new HashMap(); private Map defaultHeaderMap = new HashMap(); @@ -53,6 +53,9 @@ public class ApiClient { private Map authentications; + private int statusCode; + private Map> responseHeaders; + private DateFormat dateFormat; public ApiClient() { @@ -83,6 +86,20 @@ public ApiClient setBasePath(String basePath) { return this; } + /** + * Gets the status code of the previous request + */ + public int getStatusCode() { + return statusCode; + } + + /** + * Gets the response headers of the previous request + */ + public Map> getResponseHeaders() { + return responseHeaders; + } + /** * Get authentications (key: authentication name, value: authentication). */ @@ -483,6 +500,9 @@ public T invokeAPI(String path, String method, List queryParams, Objec throw new ApiException(500, "unknown method type " + method); } + statusCode = response.getStatusInfo().getStatusCode(); + responseHeaders = buildResponseHeaders(response); + if (response.getStatus() == Status.NO_CONTENT.getStatusCode()) { return null; } else if (response.getStatusInfo().getFamily().equals(Status.Family.SUCCESSFUL)) { @@ -501,23 +521,27 @@ public T invokeAPI(String path, String method, List queryParams, Objec // e.printStackTrace(); } } - Map> responseHeaders = new HashMap>(); - for (String key: response.getHeaders().keySet()) { - List values = response.getHeaders().get(key); - List headers = new ArrayList(); - for (Object o : values) { - headers.add(String.valueOf(o)); - } - responseHeaders.put(key, headers); - } throw new ApiException( response.getStatus(), message, - responseHeaders, + buildResponseHeaders(response), respBody); } } + private Map> buildResponseHeaders(Response response) { + Map> responseHeaders = new HashMap>(); + for (Entry> entry: response.getHeaders().entrySet()) { + List values = entry.getValue(); + List headers = new ArrayList(); + for (Object o : values) { + headers.add(String.valueOf(o)); + } + responseHeaders.put(entry.getKey(), headers); + } + return responseHeaders; + } + /** * Update query and header parameters based on authentication settings. * diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/ApiException.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/ApiException.java index 48b196e2af7..aec34b70511 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/ApiException.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/ApiException.java @@ -3,23 +3,48 @@ import java.util.Map; import java.util.List; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-22T21:47:05.989+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:51.678+08:00") public class ApiException extends Exception { private int code = 0; - private String message = null; private Map> responseHeaders = null; private String responseBody = null; public ApiException() {} + public ApiException(Throwable throwable) { + super(throwable); + } + + public ApiException(String message) { + super(message); + } + + public ApiException(String message, Throwable throwable, int code, Map> responseHeaders, String responseBody) { + super(message, throwable); + this.code = code; + this.responseHeaders = responseHeaders; + this.responseBody = responseBody; + } + + public ApiException(String message, int code, Map> responseHeaders, String responseBody) { + this(message, (Throwable) null, code, responseHeaders, responseBody); + } + + public ApiException(String message, Throwable throwable, int code, Map> responseHeaders) { + this(message, throwable, code, responseHeaders, null); + } + + public ApiException(int code, Map> responseHeaders, String responseBody) { + this((String) null, (Throwable) null, code, responseHeaders, responseBody); + } + public ApiException(int code, String message) { + super(message); this.code = code; - this.message = message; } public ApiException(int code, String message, Map> responseHeaders, String responseBody) { - this.code = code; - this.message = message; + this(code, message); this.responseHeaders = responseHeaders; this.responseBody = responseBody; } @@ -28,10 +53,6 @@ public int getCode() { return code; } - public String getMessage() { - return message; - } - /** * Get the HTTP response headers. */ diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/Configuration.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/Configuration.java index e94cd5c0aa3..778c303e0ec 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/Configuration.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/Configuration.java @@ -1,6 +1,6 @@ package io.swagger.client; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-22T21:47:05.989+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:51.678+08:00") public class Configuration { private static ApiClient defaultApiClient = new ApiClient(); diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/JSON.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/JSON.java index 3095c7bacea..4b14a48b858 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/JSON.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/JSON.java @@ -6,7 +6,7 @@ import java.io.IOException; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-24T16:42:49.539+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:51.678+08:00") public class JSON { private ObjectMapper mapper; diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/Pair.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/Pair.java index cb0e034bd63..1695577aff0 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/Pair.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/Pair.java @@ -1,6 +1,6 @@ package io.swagger.client; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-22T21:47:05.989+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:51.678+08:00") public class Pair { private String name = ""; private String value = ""; diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/StringUtil.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/StringUtil.java index 50e37eb367a..f706fb4f9fa 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/StringUtil.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/StringUtil.java @@ -1,6 +1,6 @@ package io.swagger.client; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-22T21:47:05.989+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:51.678+08:00") public class StringUtil { /** * Check if the given array contains the given value (with case-insensitive comparison). @@ -39,4 +39,13 @@ public static String join(String[] array, String separator) { } return out.toString(); } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + public static String toIndentedString(Object o) { + if (o == null) return "null"; + return o.toString().replace("\n", "\n "); + } } diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/TypeRef.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/TypeRef.java index 1444bca5a06..cbff07c9470 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/TypeRef.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/TypeRef.java @@ -3,7 +3,7 @@ import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-22T21:47:05.989+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:51.678+08:00") public class TypeRef { private final Type type; diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/api/PetApi.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/api/PetApi.java index ca72d88b130..26e0f275c8e 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/api/PetApi.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/api/PetApi.java @@ -17,7 +17,7 @@ import java.util.Map; import java.util.HashMap; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-22T21:47:05.989+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:51.678+08:00") public class PetApi { private ApiClient apiClient; @@ -47,7 +47,6 @@ public void setApiClient(ApiClient apiClient) { public void updatePet (Pet body) throws ApiException { Object postBody = body; - // create path and map variables String path = "/pet".replaceAll("\\{format\\}","json"); @@ -73,6 +72,7 @@ public void updatePet (Pet body) throws ApiException { final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { "petstore_auth" }; + apiClient.invokeAPI(path, "PUT", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, null); @@ -87,7 +87,6 @@ public void updatePet (Pet body) throws ApiException { public void addPet (Pet body) throws ApiException { Object postBody = body; - // create path and map variables String path = "/pet".replaceAll("\\{format\\}","json"); @@ -113,6 +112,7 @@ public void addPet (Pet body) throws ApiException { final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { "petstore_auth" }; + apiClient.invokeAPI(path, "POST", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, null); @@ -127,7 +127,6 @@ public void addPet (Pet body) throws ApiException { public List findPetsByStatus (List status) throws ApiException { Object postBody = null; - // create path and map variables String path = "/pet/findByStatus".replaceAll("\\{format\\}","json"); @@ -155,6 +154,7 @@ public List findPetsByStatus (List status) throws ApiException { final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { "petstore_auth" }; + TypeRef returnType = new TypeRef>() {}; return apiClient.invokeAPI(path, "GET", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType); @@ -170,7 +170,6 @@ public List findPetsByStatus (List status) throws ApiException { public List findPetsByTags (List tags) throws ApiException { Object postBody = null; - // create path and map variables String path = "/pet/findByTags".replaceAll("\\{format\\}","json"); @@ -198,6 +197,7 @@ public List findPetsByTags (List tags) throws ApiException { final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { "petstore_auth" }; + TypeRef returnType = new TypeRef>() {}; return apiClient.invokeAPI(path, "GET", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType); @@ -215,10 +215,9 @@ public Pet getPetById (Long petId) throws ApiException { // verify the required parameter 'petId' is set if (petId == null) { - throw new ApiException(400, "Missing the required parameter 'petId' when calling getPetById"); + throw new ApiException(400, "Missing the required parameter 'petId' when calling getPetById"); } - // create path and map variables String path = "/pet/{petId}".replaceAll("\\{format\\}","json") .replaceAll("\\{" + "petId" + "\\}", apiClient.escapeString(petId.toString())); @@ -245,6 +244,7 @@ public Pet getPetById (Long petId) throws ApiException { final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { "petstore_auth", "api_key" }; + TypeRef returnType = new TypeRef() {}; return apiClient.invokeAPI(path, "GET", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType); @@ -264,10 +264,9 @@ public void updatePetWithForm (String petId, String name, String status) throws // verify the required parameter 'petId' is set if (petId == null) { - throw new ApiException(400, "Missing the required parameter 'petId' when calling updatePetWithForm"); + throw new ApiException(400, "Missing the required parameter 'petId' when calling updatePetWithForm"); } - // create path and map variables String path = "/pet/{petId}".replaceAll("\\{format\\}","json") .replaceAll("\\{" + "petId" + "\\}", apiClient.escapeString(petId.toString())); @@ -298,6 +297,7 @@ public void updatePetWithForm (String petId, String name, String status) throws final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { "petstore_auth" }; + apiClient.invokeAPI(path, "POST", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, null); @@ -315,10 +315,9 @@ public void deletePet (Long petId, String apiKey) throws ApiException { // verify the required parameter 'petId' is set if (petId == null) { - throw new ApiException(400, "Missing the required parameter 'petId' when calling deletePet"); + throw new ApiException(400, "Missing the required parameter 'petId' when calling deletePet"); } - // create path and map variables String path = "/pet/{petId}".replaceAll("\\{format\\}","json") .replaceAll("\\{" + "petId" + "\\}", apiClient.escapeString(petId.toString())); @@ -347,6 +346,7 @@ public void deletePet (Long petId, String apiKey) throws ApiException { final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { "petstore_auth" }; + apiClient.invokeAPI(path, "DELETE", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, null); @@ -365,10 +365,9 @@ public void uploadFile (Long petId, String additionalMetadata, File file) throws // verify the required parameter 'petId' is set if (petId == null) { - throw new ApiException(400, "Missing the required parameter 'petId' when calling uploadFile"); + throw new ApiException(400, "Missing the required parameter 'petId' when calling uploadFile"); } - // create path and map variables String path = "/pet/{petId}/uploadImage".replaceAll("\\{format\\}","json") .replaceAll("\\{" + "petId" + "\\}", apiClient.escapeString(petId.toString())); @@ -399,6 +398,7 @@ public void uploadFile (Long petId, String additionalMetadata, File file) throws final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { "petstore_auth" }; + apiClient.invokeAPI(path, "POST", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, null); diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/api/StoreApi.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/api/StoreApi.java index 2abbae3f714..c95256c69aa 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/api/StoreApi.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/api/StoreApi.java @@ -17,7 +17,7 @@ import java.util.Map; import java.util.HashMap; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-22T21:47:05.989+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:51.678+08:00") public class StoreApi { private ApiClient apiClient; @@ -46,7 +46,6 @@ public void setApiClient(ApiClient apiClient) { public Map getInventory () throws ApiException { Object postBody = null; - // create path and map variables String path = "/store/inventory".replaceAll("\\{format\\}","json"); @@ -72,6 +71,7 @@ public Map getInventory () throws ApiException { final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { "api_key" }; + TypeRef returnType = new TypeRef>() {}; return apiClient.invokeAPI(path, "GET", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType); @@ -87,7 +87,6 @@ public Map getInventory () throws ApiException { public Order placeOrder (Order body) throws ApiException { Object postBody = body; - // create path and map variables String path = "/store/order".replaceAll("\\{format\\}","json"); @@ -113,6 +112,7 @@ public Order placeOrder (Order body) throws ApiException { final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { }; + TypeRef returnType = new TypeRef() {}; return apiClient.invokeAPI(path, "POST", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType); @@ -130,10 +130,9 @@ public Order getOrderById (String orderId) throws ApiException { // verify the required parameter 'orderId' is set if (orderId == null) { - throw new ApiException(400, "Missing the required parameter 'orderId' when calling getOrderById"); + throw new ApiException(400, "Missing the required parameter 'orderId' when calling getOrderById"); } - // create path and map variables String path = "/store/order/{orderId}".replaceAll("\\{format\\}","json") .replaceAll("\\{" + "orderId" + "\\}", apiClient.escapeString(orderId.toString())); @@ -160,6 +159,7 @@ public Order getOrderById (String orderId) throws ApiException { final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { }; + TypeRef returnType = new TypeRef() {}; return apiClient.invokeAPI(path, "GET", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType); @@ -177,10 +177,9 @@ public void deleteOrder (String orderId) throws ApiException { // verify the required parameter 'orderId' is set if (orderId == null) { - throw new ApiException(400, "Missing the required parameter 'orderId' when calling deleteOrder"); + throw new ApiException(400, "Missing the required parameter 'orderId' when calling deleteOrder"); } - // create path and map variables String path = "/store/order/{orderId}".replaceAll("\\{format\\}","json") .replaceAll("\\{" + "orderId" + "\\}", apiClient.escapeString(orderId.toString())); @@ -207,6 +206,7 @@ public void deleteOrder (String orderId) throws ApiException { final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { }; + apiClient.invokeAPI(path, "DELETE", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, null); diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/api/UserApi.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/api/UserApi.java index 7959290acd6..26c8d4b035f 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/api/UserApi.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/api/UserApi.java @@ -17,7 +17,7 @@ import java.util.Map; import java.util.HashMap; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-22T21:47:05.989+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:51.678+08:00") public class UserApi { private ApiClient apiClient; @@ -47,7 +47,6 @@ public void setApiClient(ApiClient apiClient) { public void createUser (User body) throws ApiException { Object postBody = body; - // create path and map variables String path = "/user".replaceAll("\\{format\\}","json"); @@ -73,6 +72,7 @@ public void createUser (User body) throws ApiException { final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { }; + apiClient.invokeAPI(path, "POST", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, null); @@ -87,7 +87,6 @@ public void createUser (User body) throws ApiException { public void createUsersWithArrayInput (List body) throws ApiException { Object postBody = body; - // create path and map variables String path = "/user/createWithArray".replaceAll("\\{format\\}","json"); @@ -113,6 +112,7 @@ public void createUsersWithArrayInput (List body) throws ApiException { final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { }; + apiClient.invokeAPI(path, "POST", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, null); @@ -127,7 +127,6 @@ public void createUsersWithArrayInput (List body) throws ApiException { public void createUsersWithListInput (List body) throws ApiException { Object postBody = body; - // create path and map variables String path = "/user/createWithList".replaceAll("\\{format\\}","json"); @@ -153,6 +152,7 @@ public void createUsersWithListInput (List body) throws ApiException { final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { }; + apiClient.invokeAPI(path, "POST", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, null); @@ -168,7 +168,6 @@ public void createUsersWithListInput (List body) throws ApiException { public String loginUser (String username, String password) throws ApiException { Object postBody = null; - // create path and map variables String path = "/user/login".replaceAll("\\{format\\}","json"); @@ -198,6 +197,7 @@ public String loginUser (String username, String password) throws ApiException { final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { }; + TypeRef returnType = new TypeRef() {}; return apiClient.invokeAPI(path, "GET", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType); @@ -212,7 +212,6 @@ public String loginUser (String username, String password) throws ApiException { public void logoutUser () throws ApiException { Object postBody = null; - // create path and map variables String path = "/user/logout".replaceAll("\\{format\\}","json"); @@ -238,6 +237,7 @@ public void logoutUser () throws ApiException { final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { }; + apiClient.invokeAPI(path, "GET", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, null); @@ -246,7 +246,7 @@ public void logoutUser () throws ApiException { /** * Get user by user name * - * @param username The name that needs to be fetched. Use user1 for testing. + * @param username The name that needs to be fetched. Use user1 for testing. * @return User */ public User getUserByName (String username) throws ApiException { @@ -254,10 +254,9 @@ public User getUserByName (String username) throws ApiException { // verify the required parameter 'username' is set if (username == null) { - throw new ApiException(400, "Missing the required parameter 'username' when calling getUserByName"); + throw new ApiException(400, "Missing the required parameter 'username' when calling getUserByName"); } - // create path and map variables String path = "/user/{username}".replaceAll("\\{format\\}","json") .replaceAll("\\{" + "username" + "\\}", apiClient.escapeString(username.toString())); @@ -284,6 +283,7 @@ public User getUserByName (String username) throws ApiException { final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { }; + TypeRef returnType = new TypeRef() {}; return apiClient.invokeAPI(path, "GET", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType); @@ -302,10 +302,9 @@ public void updateUser (String username, User body) throws ApiException { // verify the required parameter 'username' is set if (username == null) { - throw new ApiException(400, "Missing the required parameter 'username' when calling updateUser"); + throw new ApiException(400, "Missing the required parameter 'username' when calling updateUser"); } - // create path and map variables String path = "/user/{username}".replaceAll("\\{format\\}","json") .replaceAll("\\{" + "username" + "\\}", apiClient.escapeString(username.toString())); @@ -332,6 +331,7 @@ public void updateUser (String username, User body) throws ApiException { final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { }; + apiClient.invokeAPI(path, "PUT", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, null); @@ -348,10 +348,9 @@ public void deleteUser (String username) throws ApiException { // verify the required parameter 'username' is set if (username == null) { - throw new ApiException(400, "Missing the required parameter 'username' when calling deleteUser"); + throw new ApiException(400, "Missing the required parameter 'username' when calling deleteUser"); } - // create path and map variables String path = "/user/{username}".replaceAll("\\{format\\}","json") .replaceAll("\\{" + "username" + "\\}", apiClient.escapeString(username.toString())); @@ -378,6 +377,7 @@ public void deleteUser (String username) throws ApiException { final String contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { }; + apiClient.invokeAPI(path, "DELETE", queryParams, postBody, headerParams, formParams, accept, contentType, authNames, null); diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/auth/ApiKeyAuth.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/auth/ApiKeyAuth.java index 87a4a90a49c..6082e3a6e4c 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/auth/ApiKeyAuth.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/auth/ApiKeyAuth.java @@ -5,7 +5,7 @@ import java.util.Map; import java.util.List; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-22T21:47:05.989+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:51.678+08:00") public class ApiKeyAuth implements Authentication { private final String location; private final String paramName; diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/auth/Authentication.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/auth/Authentication.java index b35133a0c94..6555e457ee5 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/auth/Authentication.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/auth/Authentication.java @@ -5,7 +5,7 @@ import java.util.Map; import java.util.List; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-22T21:47:05.989+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:51.678+08:00") public interface Authentication { /** Apply authentication settings to header and query params. */ void applyToParams(List queryParams, Map headerParams); diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/auth/HttpBasicAuth.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/auth/HttpBasicAuth.java index 7d224efefbb..909043e180e 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/auth/HttpBasicAuth.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/auth/HttpBasicAuth.java @@ -8,7 +8,7 @@ import java.io.UnsupportedEncodingException; import javax.xml.bind.DatatypeConverter; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-22T21:47:05.989+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:51.678+08:00") public class HttpBasicAuth implements Authentication { private String username; private String password; diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/auth/OAuth.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/auth/OAuth.java index 06debad62e4..d4f548b1412 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/auth/OAuth.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/auth/OAuth.java @@ -5,7 +5,7 @@ import java.util.Map; import java.util.List; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-22T21:47:05.989+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:51.678+08:00") public class OAuth implements Authentication { @Override public void applyToParams(List queryParams, Map headerParams) { diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/Category.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/Category.java index f0dab47c7f7..f09bf60128a 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/Category.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/Category.java @@ -1,13 +1,16 @@ package io.swagger.client.model; +import io.swagger.client.StringUtil; + + import io.swagger.annotations.*; import com.fasterxml.jackson.annotation.JsonProperty; @ApiModel(description = "") -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-22T21:47:05.989+08:00") -public class Category { +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:51.678+08:00") +public class Category { private Long id = null; private String name = null; @@ -43,9 +46,9 @@ public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class Category {\n"); - sb.append(" id: ").append(id).append("\n"); - sb.append(" name: ").append(name).append("\n"); - sb.append("}\n"); + sb.append(" id: ").append(StringUtil.toIndentedString(id)).append("\n"); + sb.append(" name: ").append(StringUtil.toIndentedString(name)).append("\n"); + sb.append("}"); return sb.toString(); } } diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/Order.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/Order.java index 2477288848d..868c59a783d 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/Order.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/Order.java @@ -1,5 +1,6 @@ package io.swagger.client.model; +import io.swagger.client.StringUtil; import java.util.Date; @@ -9,7 +10,7 @@ @ApiModel(description = "") -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-24T16:42:49.539+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:51.678+08:00") public class Order { private Long id = null; @@ -115,13 +116,13 @@ public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class Order {\n"); - sb.append(" id: ").append(id).append("\n"); - sb.append(" petId: ").append(petId).append("\n"); - sb.append(" quantity: ").append(quantity).append("\n"); - sb.append(" shipDate: ").append(shipDate).append("\n"); - sb.append(" status: ").append(status).append("\n"); - sb.append(" complete: ").append(complete).append("\n"); - sb.append("}\n"); + sb.append(" id: ").append(StringUtil.toIndentedString(id)).append("\n"); + sb.append(" petId: ").append(StringUtil.toIndentedString(petId)).append("\n"); + sb.append(" quantity: ").append(StringUtil.toIndentedString(quantity)).append("\n"); + sb.append(" shipDate: ").append(StringUtil.toIndentedString(shipDate)).append("\n"); + sb.append(" status: ").append(StringUtil.toIndentedString(status)).append("\n"); + sb.append(" complete: ").append(StringUtil.toIndentedString(complete)).append("\n"); + sb.append("}"); return sb.toString(); } } diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/Pet.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/Pet.java index 1ed72947556..2a4a0b6c93d 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/Pet.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/Pet.java @@ -1,5 +1,6 @@ package io.swagger.client.model; +import io.swagger.client.StringUtil; import io.swagger.client.model.Category; import java.util.*; import io.swagger.client.model.Tag; @@ -11,7 +12,7 @@ @ApiModel(description = "") -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-24T16:42:49.539+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:51.678+08:00") public class Pet { private Long id = null; @@ -117,13 +118,13 @@ public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class Pet {\n"); - sb.append(" id: ").append(id).append("\n"); - sb.append(" category: ").append(category).append("\n"); - sb.append(" name: ").append(name).append("\n"); - sb.append(" photoUrls: ").append(photoUrls).append("\n"); - sb.append(" tags: ").append(tags).append("\n"); - sb.append(" status: ").append(status).append("\n"); - sb.append("}\n"); + sb.append(" id: ").append(StringUtil.toIndentedString(id)).append("\n"); + sb.append(" category: ").append(StringUtil.toIndentedString(category)).append("\n"); + sb.append(" name: ").append(StringUtil.toIndentedString(name)).append("\n"); + sb.append(" photoUrls: ").append(StringUtil.toIndentedString(photoUrls)).append("\n"); + sb.append(" tags: ").append(StringUtil.toIndentedString(tags)).append("\n"); + sb.append(" status: ").append(StringUtil.toIndentedString(status)).append("\n"); + sb.append("}"); return sb.toString(); } } diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/Tag.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/Tag.java index 3bf1b196e1d..2f7b12a9c2d 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/Tag.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/Tag.java @@ -1,13 +1,16 @@ package io.swagger.client.model; +import io.swagger.client.StringUtil; + + import io.swagger.annotations.*; import com.fasterxml.jackson.annotation.JsonProperty; @ApiModel(description = "") -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-22T21:47:05.989+08:00") -public class Tag { +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:51.678+08:00") +public class Tag { private Long id = null; private String name = null; @@ -43,9 +46,9 @@ public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class Tag {\n"); - sb.append(" id: ").append(id).append("\n"); - sb.append(" name: ").append(name).append("\n"); - sb.append("}\n"); + sb.append(" id: ").append(StringUtil.toIndentedString(id)).append("\n"); + sb.append(" name: ").append(StringUtil.toIndentedString(name)).append("\n"); + sb.append("}"); return sb.toString(); } } diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/User.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/User.java index 0d454ec95aa..be1089d751d 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/User.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/model/User.java @@ -1,13 +1,16 @@ package io.swagger.client.model; +import io.swagger.client.StringUtil; + + import io.swagger.annotations.*; import com.fasterxml.jackson.annotation.JsonProperty; @ApiModel(description = "") -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-22T21:47:05.989+08:00") -public class User { +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T11:35:51.678+08:00") +public class User { private Long id = null; private String username = null; @@ -122,15 +125,15 @@ public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class User {\n"); - sb.append(" id: ").append(id).append("\n"); - sb.append(" username: ").append(username).append("\n"); - sb.append(" firstName: ").append(firstName).append("\n"); - sb.append(" lastName: ").append(lastName).append("\n"); - sb.append(" email: ").append(email).append("\n"); - sb.append(" password: ").append(password).append("\n"); - sb.append(" phone: ").append(phone).append("\n"); - sb.append(" userStatus: ").append(userStatus).append("\n"); - sb.append("}\n"); + sb.append(" id: ").append(StringUtil.toIndentedString(id)).append("\n"); + sb.append(" username: ").append(StringUtil.toIndentedString(username)).append("\n"); + sb.append(" firstName: ").append(StringUtil.toIndentedString(firstName)).append("\n"); + sb.append(" lastName: ").append(StringUtil.toIndentedString(lastName)).append("\n"); + sb.append(" email: ").append(StringUtil.toIndentedString(email)).append("\n"); + sb.append(" password: ").append(StringUtil.toIndentedString(password)).append("\n"); + sb.append(" phone: ").append(StringUtil.toIndentedString(phone)).append("\n"); + sb.append(" userStatus: ").append(StringUtil.toIndentedString(userStatus)).append("\n"); + sb.append("}"); return sb.toString(); } } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiCallback.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiCallback.java index f8254311bce..d75713c9a01 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiCallback.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiCallback.java @@ -2,6 +2,9 @@ import java.io.IOException; +import java.util.Map; +import java.util.List; + /** * Callback for asynchronous API call. * @@ -10,13 +13,19 @@ public interface ApiCallback { /** * This is called when the API call fails. + * + * @param e The exception causing the failure + * @param statusCode Status code of the response if available, otherwise it would be 0 + * @param responseHeaders Headers of the response if available, otherwise it would be null */ - void onFailure(ApiException e); + void onFailure(ApiException e, int statusCode, Map> responseHeaders); /** * This is called when the API call succeeded. * * @param result The result deserialized from response + * @param statusCode Status code of the response + * @param responseHeaders Headers of the response */ - void onSuccess(T result); + void onSuccess(T result, int statusCode, Map> responseHeaders); } 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 f189ea10238..33c009fa0a3 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 @@ -48,6 +48,9 @@ public class ApiClient { private Map authentications; + private int statusCode; + private Map> responseHeaders; + private String dateFormat; private DateFormat dateFormatter; private int dateLength; @@ -106,6 +109,24 @@ public ApiClient setJSON(JSON json) { 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 String getDateFormat() { return dateFormat; } @@ -533,6 +554,8 @@ public T execute(Call call) throws ApiException { public 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); } catch (IOException e) { throw new ApiException(e); @@ -556,7 +579,7 @@ public void executeAsync(Call call, final Type returnType, final ApiCallback call.enqueue(new Callback() { @Override public void onFailure(Request request, IOException e) { - callback.onFailure(new ApiException(e)); + callback.onFailure(new ApiException(e), 0, null); } @Override @@ -565,10 +588,10 @@ public void onResponse(Response response) throws IOException { try { result = (T) handleResponse(response, returnType); } catch (ApiException e) { - callback.onFailure(e); + callback.onFailure(e, response.code(), response.headers().toMultimap()); return; } - callback.onSuccess(result); + callback.onSuccess(result, response.code(), response.headers().toMultimap()); } }); } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiException.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiException.java index d19aa8ebb3a..a76d5872a90 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiException.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiException.java @@ -3,7 +3,7 @@ import java.util.Map; import java.util.List; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-31T19:27:38.337+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T13:13:26.059+08:00") public class ApiException extends Exception { private int code = 0; private Map> responseHeaders = null; diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/Configuration.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/Configuration.java index 07c97e116d7..7a4d947d5e5 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/Configuration.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/Configuration.java @@ -1,6 +1,6 @@ package io.swagger.client; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-31T19:27:38.337+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T13:13:26.059+08:00") public class Configuration { private static ApiClient defaultApiClient = new ApiClient(); diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/Pair.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/Pair.java index bb0cd823791..5986bdd0db6 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/Pair.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/Pair.java @@ -1,6 +1,6 @@ package io.swagger.client; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-31T19:27:38.337+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T13:13:26.059+08:00") public class Pair { private String name = ""; private String value = ""; diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/StringUtil.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/StringUtil.java index 9a58d6d5558..762f1c61161 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/StringUtil.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/StringUtil.java @@ -1,6 +1,6 @@ package io.swagger.client; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-31T19:27:38.337+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T13:13:26.059+08:00") public class StringUtil { /** * Check if the given array contains the given value (with case-insensitive comparison). 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 27429765069..ce1bae64a46 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 @@ -354,7 +354,7 @@ private Call getUserByNameCall(String username) throws ApiException { /** * Get user by user name * - * @param username The name that needs to be fetched. Use user1 for testing. + * @param username The name that needs to be fetched. Use user1 for testing. * @return User */ public User getUserByName(String username) throws ApiException { @@ -366,7 +366,7 @@ public User getUserByName(String username) throws ApiException { /** * Get user by user name (asynchronously) * - * @param username The name that needs to be fetched. Use user1 for testing. + * @param username The name that needs to be fetched. Use user1 for testing. * @param callback The callback to be executed when the API call finishes * @return The request call */ diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/ApiKeyAuth.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/ApiKeyAuth.java index 20ebbf17e74..6bfe672ea93 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/ApiKeyAuth.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/ApiKeyAuth.java @@ -5,7 +5,7 @@ import java.util.Map; import java.util.List; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-31T19:27:38.337+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T13:13:26.059+08:00") public class ApiKeyAuth implements Authentication { private final String location; private final String paramName; diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/Authentication.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/Authentication.java index 9197d04b1b7..3fa136f64c0 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/Authentication.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/Authentication.java @@ -5,7 +5,7 @@ import java.util.Map; import java.util.List; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-31T19:27:38.337+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T13:13:26.059+08:00") public interface Authentication { /** Apply authentication settings to header and query params. */ void applyToParams(List queryParams, Map headerParams); diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/OAuth.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/OAuth.java index 184b9e82ca7..4e3b5a035bd 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/OAuth.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/OAuth.java @@ -5,7 +5,7 @@ import java.util.Map; import java.util.List; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-08-31T19:27:38.337+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-09-11T13:13:26.059+08:00") public class OAuth implements Authentication { @Override public void applyToParams(List queryParams, Map headerParams) { 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 0a8f8a1665d..c9586343025 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 @@ -4,6 +4,7 @@ import io.swagger.client.ApiException; import io.swagger.client.Configuration; +import io.swagger.client.ApiCallback; import io.swagger.client.api.*; import io.swagger.client.auth.*; import io.swagger.client.model.*; @@ -13,7 +14,9 @@ import java.io.FileWriter; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.junit.*; import static org.junit.Assert.*; @@ -68,6 +71,81 @@ public void testCreateAndGetPet() throws Exception { assertEquals(fetched.getCategory().getName(), pet.getCategory().getName()); } + @Test + public void testCreateAndGetPetAsync() throws Exception { + Pet pet = createRandomPet(); + api.addPet(pet); + // to store returned Pet or error message/exception + final Map result = new HashMap(); + + api.getPetByIdAsync(pet.getId(), new ApiCallback() { + @Override + public void onFailure(ApiException e, int statusCode, Map> responseHeaders) { + result.put("error", e.getMessage()); + } + + @Override + public void onSuccess(Pet pet, int statusCode, Map> responseHeaders) { + result.put("pet", pet); + } + }); + // the API call should be executed asynchronously, so result should be empty at the moment + assertTrue(result.isEmpty()); + + // wait for the asynchronous call to finish (at most 10 seconds) + final int maxTry = 10; + int tryCount = 1; + Pet fetched = null; + do { + if (tryCount > maxTry) fail("have not got result of getPetByIdAsync after 10 seconds"); + Thread.sleep(1000); + tryCount += 1; + if (result.get("error") != null) fail((String) result.get("error")); + if (result.get("pet") != null) { + fetched = (Pet) result.get("pet"); + break; + } + } while (result.isEmpty()); + assertNotNull(fetched); + assertEquals(pet.getId(), fetched.getId()); + assertNotNull(fetched.getCategory()); + assertEquals(fetched.getCategory().getName(), pet.getCategory().getName()); + + // test getting a nonexistent pet + result.clear(); + api.getPetByIdAsync(new Long(-10000), new ApiCallback() { + @Override + public void onFailure(ApiException e, int statusCode, Map> responseHeaders) { + result.put("exception", e); + } + + @Override + public void onSuccess(Pet pet, int statusCode, Map> responseHeaders) { + result.put("pet", pet); + } + }); + // the API call should be executed asynchronously, so result should be empty at the moment + assertTrue(result.isEmpty()); + + // wait for the asynchronous call to finish (at most 10 seconds) + tryCount = 1; + ApiException exception = null; + do { + if (tryCount > maxTry) fail("have not got result of getPetByIdAsync after 10 seconds"); + Thread.sleep(1000); + tryCount += 1; + if (result.get("pet") != null) fail("expected an error"); + if (result.get("exception") != null) { + exception = (ApiException) result.get("exception"); + break; + } + } while (result.isEmpty()); + assertNotNull(exception); + assertEquals(404, exception.getCode()); + assertEquals("Not Found", exception.getMessage()); + assertEquals("application/json", exception.getResponseHeaders().get("Content-Type").get(0)); + } + @Test public void testUpdatePet() throws Exception { Pet pet = createRandomPet();