diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000000..4bef580bb26 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,62 @@ +# Guidelines For Contributing + +## Before submitting an issue + + - Before submitting an issue, search the [open issue](https://github.com/swagger-api/swagger-codegen/issues) and [closed issue](https://github.com/swagger-api/swagger-codegen/issues?q=is%3Aissue+is%3Aclosed) to ensure no one else has reported something similar before. + - The issue should contain details on how to repeat the issue, e.g. + - the Swagger spec for reproducing the issue (:bulb: use [Gist](https://gist.github.com) to share). If the Swagger spec cannot be shared publicly, it will be hard for the community to help + - version of Swagger Codegen + - language (`-l` in the command line, e.g. java, csharp, php) + - You can also make a suggestion or ask a question by opening an "issue" + +## Before submitting a PR + + - Search the [open issue](https://github.com/swagger-api/swagger-codegen/issues) to ensure no one else has reported something similar and no one is actively working on similar proposed change. + - If no one has suggested something similar, open an ["issue"](https://github.com/swagger-api/swagger-codegen/issues) with your suggestion to gather feedback from the community. + +## How to contribute + +### Code generators + +All the code generators can be found in [modules/swagger-codegen/src/main/java/io/swagger/codegen/languages](https://github.com/swagger-api/swagger-codegen/tree/master/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages) + +### Templates + +All the templates ([mustache](https://mustache.github.io/)) can be found in [modules/swagger-codegen/src/main/resources](https://github.com/swagger-api/swagger-codegen/tree/master/modules/swagger-codegen/src/main/resources). + +For a list of variables available in the template, please refer to this [page](https://github.com/swagger-api/swagger-codegen/wiki/Mustache-Template-Variables) + + +### Style guide +Code change should conform to the programming style guide of the respective langauages: +- C#: https://msdn.microsoft.com/en-us/library/vstudio/ff926074.aspx +- Java: https://google.github.io/styleguide/javaguide.html +- ObjC: https://github.com/NYTimes/objective-c-style-guide +- PHP: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md +- Python: https://www.python.org/dev/peps/pep-0008/ +- Ruby: https://github.com/bbatsov/ruby-style-guide +- TypeScript: https://github.com/Microsoft/TypeScript/wiki/Coding-guidelines + + +For other languages, feel free to suggest. + +You may find the current code base not 100% conform to the coding style and we welcome contributions to fix those. + +### Testing + +To add test cases (optional) covering the change in the code generator, please refer to [modules/swagger-codegen/src/test/java/io/swagger/codegen](https://github.com/swagger-api/swagger-codegen/tree/master/modules/swagger-codegen/src/test/java/io/swagger/codegen) + +To test the templates, please perform the following: +- Update the [Petstore](http://petstore.swagger.io/) sample by running the shell script under `bin` folder. For example, run `./bin/ruby-petstore.sh` to update the Ruby PetStore API client under [`samples/client/petstore/ruby`](https://github.com/swagger-api/swagger-codegen/tree/master/samples/client/petstore/ruby) (For Windows, the batch files can be found under `bin\windows` folder) +- Run the tests in the sample folder, e.g. in `samples/client/petstore/ruby`, run `mvn integration-test -rf :RubyPetstoreClientTests`. (some languages may not contain unit testing for Petstore and we're looking for contribution from the community to implement those tests) +- Finally, git commit the updated samples files: `git commit -a` + (`git add -A` if added files with new test cases) + +To start the CI tests, you can run `mvn verify -Psamples` (assuming you've all the required tools installed to run tests for different languages) or you can leverage http://travis-ci.org to run the CI tests by adding your own Swagger-Codegen repository. + +### Tips +- Smaller changes are easier to review +- [Optional] For bug fixes, provide a Swagger spec to repeat the issue so that the reviewer can use it to confirm the fix +- Add test case(s) to cover the change +- Document the fix in the code to make the code more readable +- Make sure test cases passed after the change (one way is to leverage https://travis-ci.org/ to run the CI tests) diff --git a/README.md b/README.md index 30af2fc837c..e1015f0fef8 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,8 @@ [![Build Status](https://travis-ci.org/swagger-api/swagger-codegen.png)](https://travis-ci.org/swagger-api/swagger-codegen) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.swagger/swagger-codegen-project/badge.svg?style=plastic)](https://maven-badges.herokuapp.com/maven-central/io.swagger/swagger-codegen-project) +:star::star::star: If you would like to contribute, please refer to [guidelines](https://github.com/swagger-api/swagger-codegen/blob/master/CONTRIBUTING.md) and a list of [open tasks](https://github.com/swagger-api/swagger-codegen/issues?q=is%3Aopen+is%3Aissue+label%3A%22Need+community+contribution%22).:star::star::star: + ## Overview This is the swagger codegen project, which allows generation of client libraries automatically from a Swagger-compliant server. diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CSharpClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CSharpClientCodegen.java index be8b4b74781..f69ddd16d35 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CSharpClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CSharpClientCodegen.java @@ -7,9 +7,7 @@ import io.swagger.codegen.DefaultCodegen; import io.swagger.codegen.SupportingFile; import io.swagger.codegen.CodegenProperty; import io.swagger.codegen.CodegenModel; -import io.swagger.models.properties.ArrayProperty; -import io.swagger.models.properties.MapProperty; -import io.swagger.models.properties.Property; +import io.swagger.models.properties.*; import io.swagger.codegen.CliOption; import java.io.File; @@ -300,4 +298,51 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig } return objs; } + + /** + * Return the default value of the property + * + * @param p Swagger property object + * @return string presentation of the default value of the property + */ + @Override + public String toDefaultValue(Property p) { + if (p instanceof StringProperty) { + StringProperty dp = (StringProperty) p; + if (dp.getDefault() != null) { + return "\"" + dp.getDefault().toString() + "\""; + } + } else if (p instanceof BooleanProperty) { + BooleanProperty dp = (BooleanProperty) p; + if (dp.getDefault() != null) { + return dp.getDefault().toString(); + } + } else if (p instanceof DateProperty) { + // TODO + } else if (p instanceof DateTimeProperty) { + // TODO + } else if (p instanceof DoubleProperty) { + DoubleProperty dp = (DoubleProperty) p; + if (dp.getDefault() != null) { + return dp.getDefault().toString(); + } + } else if (p instanceof FloatProperty) { + FloatProperty dp = (FloatProperty) p; + if (dp.getDefault() != null) { + return dp.getDefault().toString(); + } + } else if (p instanceof IntegerProperty) { + IntegerProperty dp = (IntegerProperty) p; + if (dp.getDefault() != null) { + return dp.getDefault().toString(); + } + } else if (p instanceof LongProperty) { + LongProperty dp = (LongProperty) p; + if (dp.getDefault() != null) { + return dp.getDefault().toString(); + } + } + + return null; + } } diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java index 0aba8c2c9d1..67a746d4afb 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java @@ -232,6 +232,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig { if ("okhttp-gson".equals(getLibrary())) { // the "okhttp-gson" library template requires "ApiCallback.mustache" for async call supportingFiles.add(new SupportingFile("ApiCallback.mustache", invokerFolder, "ApiCallback.java")); + supportingFiles.add(new SupportingFile("ApiResponse.mustache", invokerFolder, "ApiResponse.java")); supportingFiles.add(new SupportingFile("ProgressRequestBody.mustache", invokerFolder, "ProgressRequestBody.java")); supportingFiles.add(new SupportingFile("ProgressResponseBody.mustache", invokerFolder, "ProgressResponseBody.java")); // "build.sbt" is for development with SBT diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache index cef9a843347..e97e4c7f97d 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache @@ -104,9 +104,6 @@ public class ApiClient { private Map authentications; - private int statusCode; - private Map> responseHeaders; - private DateFormat dateFormat; private DateFormat datetimeFormat; private boolean lenientDatetimeFormat; @@ -177,24 +174,6 @@ public class ApiClient { return this; } - /** - * Gets the status code of the previous request. - * NOTE: Status code of last async response is not recorded here, it is - * passed to the callback methods instead. - */ - public int getStatusCode() { - return statusCode; - } - - /** - * Gets the response headers of the previous request. - * NOTE: Headers of last async response is not recorded here, it is passed - * to callback methods instead. - */ - public Map> getResponseHeaders() { - return responseHeaders; - } - public boolean isVerifyingSsl() { return verifyingSsl; } @@ -618,6 +597,8 @@ public class ApiClient { * @param response HTTP response * @param returnType The type of the Java object * @return The deserialized Java object + * @throws ApiException If fail to deserialize response body, i.e. cannot read response body + * or the Content-Type of the response is not supported. */ public T deserialize(Response response, Type returnType) throws ApiException { if (response == null || returnType == null) @@ -666,6 +647,7 @@ public class ApiClient { * @param obj The Java object * @param contentType The request Content-Type * @return The serialized string + * @throws ApiException If fail to serialize the given object */ public String serialize(Object obj, String contentType) throws ApiException { if (contentType.startsWith("application/json")) { @@ -680,6 +662,7 @@ public class ApiClient { /** * Download file from the given response. + * @throws ApiException If fail to read file content from response and write to disk */ public File downloadFileFromResponse(Response response) throws ApiException { try { @@ -731,7 +714,7 @@ public class ApiClient { /** * @see #execute(Call, Type) */ - public T execute(Call call) throws ApiException { + public ApiResponse execute(Call call) throws ApiException { return execute(call, null); } @@ -740,14 +723,16 @@ public class ApiClient { * * @param returnType The return type used to deserialize HTTP response body * @param The return type corresponding to (same with) returnType - * @return The Java object deserialized from response body. Returns null if returnType is null. + * @return ApiResponse object containing response status, headers and + * data, which is a Java object deserialized from response body and would be null + * when returnType is null. + * @throws ApiException If fail to execute the call */ - public T execute(Call call, Type returnType) throws ApiException { + public ApiResponse execute(Call call, Type returnType) throws ApiException { try { Response response = call.execute(); - this.statusCode = response.code(); - this.responseHeaders = response.headers().toMultimap(); - return handleResponse(response, returnType); + T data = handleResponse(response, returnType); + return new ApiResponse(response.code(), response.headers().toMultimap(), data); } catch (IOException e) { throw new ApiException(e); } @@ -756,7 +741,7 @@ public class ApiClient { /** * #see executeAsync(Call, Type, ApiCallback) */ - public void executeAsync(Call call, ApiCallback callback) throws ApiException { + public void executeAsync(Call call, ApiCallback callback) { executeAsync(call, null, callback); } @@ -787,6 +772,12 @@ public class ApiClient { }); } + /** + * Handle the given response, return the deserialized object when the response is successful. + * + * @throws ApiException If the response has a unsuccessful status code or + * fail to deserialize the response body + */ public T handleResponse(Response response, Type returnType) throws ApiException { if (response.isSuccessful()) { if (returnType == null || response.code() == 204) { @@ -820,6 +811,7 @@ public class ApiClient { * @param formParams The form parameters * @param authNames The authentications to apply * @return The HTTP call + * @throws ApiException If fail to serialize the request body object */ public Call buildCall(String path, String method, List queryParams, Object body, Map headerParams, Map formParams, String[] authNames, ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { updateParamsForAuth(authNames, queryParams, headerParams); diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/ApiResponse.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/ApiResponse.mustache new file mode 100644 index 00000000000..452f4e1e982 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/ApiResponse.mustache @@ -0,0 +1,46 @@ +package {{invokerPackage}}; + +import java.util.List; +import java.util.Map; + +/** + * API response returned by API call. + * + * @param T The type of data that is deserialized from response body + */ +public class ApiResponse { + final private int statusCode; + final private Map> headers; + final private T data; + + /** + * @param statusCode The status code of HTTP response + * @param headers The headers of HTTP response + */ + public ApiResponse(int statusCode, Map> headers) { + this(statusCode, headers, null); + } + + /** + * @param statusCode The status code of HTTP response + * @param headers The headers of HTTP response + * @param data The object deserialized from response bod + */ + public ApiResponse(int statusCode, Map> headers, T data) { + this.statusCode = statusCode; + this.headers = headers; + this.data = data; + } + + public int getStatusCode() { + return statusCode; + } + + public Map> getHeaders() { + return headers; + } + + public T getData() { + return data; + } +} diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/api.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/api.mustache index a1a4c9f8fb4..e760f4a370e 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/api.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/api.mustache @@ -3,6 +3,7 @@ package {{package}}; import {{invokerPackage}}.ApiCallback; import {{invokerPackage}}.ApiClient; import {{invokerPackage}}.ApiException; +import {{invokerPackage}}.ApiResponse; import {{invokerPackage}}.Configuration; import {{invokerPackage}}.Pair; import {{invokerPackage}}.ProgressRequestBody; @@ -104,11 +105,24 @@ public class {{classname}} { * {{notes}}{{#allParams}} * @param {{paramName}} {{description}}{{/allParams}}{{#returnType}} * @return {{{returnType}}}{{/returnType}} + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{operationId}}({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException { + {{#returnType}}ApiResponse<{{{returnType}}}> {{localVariablePrefix}}resp = {{/returnType}}{{operationId}}WithHttpInfo({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{#returnType}} + return {{localVariablePrefix}}resp.getData();{{/returnType}} + } + + /** + * {{summary}} + * {{notes}}{{#allParams}} + * @param {{paramName}} {{description}}{{/allParams}} + * @return ApiResponse<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}> + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + */ + public ApiResponse<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}> {{operationId}}WithHttpInfo({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException { Call {{localVariablePrefix}}call = {{operationId}}Call({{#allParams}}{{paramName}}, {{/allParams}}null, null); {{#returnType}}Type {{localVariablePrefix}}returnType = new TypeToken<{{{returnType}}}>(){}.getType(); - return {{localVariablePrefix}}apiClient.execute({{localVariablePrefix}}call, {{localVariablePrefix}}returnType);{{/returnType}}{{^returnType}}{{localVariablePrefix}}apiClient.execute({{localVariablePrefix}}call);{{/returnType}} + return {{localVariablePrefix}}apiClient.execute({{localVariablePrefix}}call, {{localVariablePrefix}}returnType);{{/returnType}}{{^returnType}}return {{localVariablePrefix}}apiClient.execute({{localVariablePrefix}}call);{{/returnType}} } /** @@ -117,6 +131,7 @@ public class {{classname}} { * @param {{paramName}} {{description}}{{/allParams}} * @param callback The callback to be executed when the API call finishes * @return The request call + * @throws ApiException If fail to process the API call, e.g. serializing the request body object */ public Call {{operationId}}Async({{#allParams}}{{{dataType}}} {{paramName}}, {{/allParams}}final ApiCallback<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}> {{localVariablePrefix}}callback) throws ApiException { diff --git a/modules/swagger-codegen/src/main/resources/clojure/core.mustache b/modules/swagger-codegen/src/main/resources/clojure/core.mustache index 931d2b73c76..79d0ee9b5ee 100644 --- a/modules/swagger-codegen/src/main/resources/clojure/core.mustache +++ b/modules/swagger-codegen/src/main/resources/clojure/core.mustache @@ -169,15 +169,17 @@ (map (fn [[k v]] [k (normalize-param v)])) (into {}))) -(defn json-mime? [mime] +(defn json-mime? "Check if the given MIME is a standard JSON MIME or :json." + [mime] (if mime (or (= :json mime) (re-matches #"application/json(;.*)?" (name mime))))) -(defn json-preferred-mime [mimes] +(defn json-preferred-mime "Choose a MIME from the given MIMEs with JSON preferred, i.e. return JSON if included, otherwise return the first one." + [mimes] (-> (filter json-mime? mimes) first (or (first mimes)))) diff --git a/modules/swagger-codegen/src/main/resources/csharp/model.mustache b/modules/swagger-codegen/src/main/resources/csharp/model.mustache index 7b7f1a6aea0..faff8d20329 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/model.mustache +++ b/modules/swagger-codegen/src/main/resources/csharp/model.mustache @@ -18,6 +18,15 @@ namespace {{packageName}}.Model [DataContract] public class {{classname}} : IEquatable<{{classname}}>{{#parent}}, {{{parent}}}{{/parent}} { + /// + /// Initializes a new instance of the class. + /// + public {{classname}}() + { + {{#vars}}{{#defaultValue}}this.{{name}} = {{{defaultValue}}}; + {{/defaultValue}}{{/vars}} + } + {{#vars}} /// /// {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{{description}}}{{/description}} diff --git a/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache index 11fe3827d48..be18e221972 100644 --- a/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache @@ -131,7 +131,7 @@ class ApiClient * @throws \{{invokerPackage}}\ApiException on a non 2xx response * @return mixed */ - public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams, $responseType=null) + public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams, $responseType = null) { $headers = array(); @@ -149,7 +149,7 @@ class ApiClient // form data if ($postData and in_array('Content-Type: application/x-www-form-urlencoded', $headers)) { $postData = http_build_query($postData); - } else if ((is_object($postData) or is_array($postData)) and !in_array('Content-Type: multipart/form-data', $headers)) { // json model + } elseif ((is_object($postData) or is_array($postData)) and !in_array('Content-Type: multipart/form-data', $headers)) { // json model $postData = json_encode($this->serializer->sanitizeForSerialization($postData)); } @@ -160,7 +160,7 @@ class ApiClient if ($this->config->getCurlTimeout() != 0) { curl_setopt($curl, CURLOPT_TIMEOUT, $this->config->getCurlTimeout()); } - // return the result on success, rather than just TRUE + // return the result on success, rather than just true curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); @@ -178,21 +178,21 @@ class ApiClient if ($method == self::$POST) { curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method == self::$HEAD) { + } elseif ($method == self::$HEAD) { curl_setopt($curl, CURLOPT_NOBODY, true); - } else if ($method == self::$OPTIONS) { + } elseif ($method == self::$OPTIONS) { curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "OPTIONS"); curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method == self::$PATCH) { + } elseif ($method == self::$PATCH) { curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH"); curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method == self::$PUT) { + } elseif ($method == self::$PUT) { curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method == self::$DELETE) { + } elseif ($method == self::$DELETE) { curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method != self::$GET) { + } elseif ($method != self::$GET) { throw new ApiException('Method ' . $method . ' is not recognized.'); } curl_setopt($curl, CURLOPT_URL, $url); @@ -216,7 +216,7 @@ class ApiClient // Make the request $response = curl_exec($curl); $http_header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE); - $http_header = substr($response, 0, $http_header_size); + $http_header = $this->http_parse_headers(substr($response, 0, $http_header_size)); $http_body = substr($response, $http_header_size); $response_info = curl_getinfo($curl); @@ -228,10 +228,10 @@ class ApiClient // Handle the response if ($response_info['http_code'] == 0) { throw new ApiException("API call to $url timed out: ".serialize($response_info), 0, null, null); - } else if ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) { + } elseif ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) { // return raw body if response is a file if ($responseType == '\SplFileObject') { - return array($http_body, $http_header); + return array($http_body, $response_info['http_code'], $http_header); } $data = json_decode($http_body); @@ -249,7 +249,7 @@ class ApiClient $response_info['http_code'], $http_header, $data ); } - return array($data, $http_header); + return array($data, $response_info['http_code'], $http_header); } /** @@ -287,4 +287,52 @@ class ApiClient return implode(',', $content_type); } } + + /** + * Return an array of HTTP response headers + * + * @param string $raw_headers A string of raw HTTP response headers + * + * @return string[] Array of HTTP response heaers + */ + protected function http_parse_headers($raw_headers) + { + // ref/credit: http://php.net/manual/en/function.http-parse-headers.php#112986 + $headers = array(); + $key = ''; // [+] + + foreach(explode("\n", $raw_headers) as $i => $h) + { + $h = explode(':', $h, 2); + + if (isset($h[1])) + { + if (!isset($headers[$h[0]])) + $headers[$h[0]] = trim($h[1]); + elseif (is_array($headers[$h[0]])) + { + // $tmp = array_merge($headers[$h[0]], array(trim($h[1]))); // [-] + // $headers[$h[0]] = $tmp; // [-] + $headers[$h[0]] = array_merge($headers[$h[0]], array(trim($h[1]))); // [+] + } + else + { + // $tmp = array_merge(array($headers[$h[0]]), array(trim($h[1]))); // [-] + // $headers[$h[0]] = $tmp; // [-] + $headers[$h[0]] = array_merge(array($headers[$h[0]]), array(trim($h[1]))); // [+] + } + + $key = $h[0]; // [+] + } + else // [+] + { // [+] + if (substr($h[0], 0, 1) == "\t") // [+] + $headers[$key] .= "\r\n\t".trim($h[0]); // [+] + elseif (!$key) // [+] + $headers[0] = trim($h[0]);trim($h[0]); // [+] + } // [+] + } + + return $headers; + } } diff --git a/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache b/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache index 45b56aa9b97..133c1b1f454 100644 --- a/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache +++ b/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache @@ -56,14 +56,14 @@ class ObjectSerializer { if (is_scalar($data) || null === $data) { $sanitized = $data; - } else if ($data instanceof \DateTime) { + } elseif ($data instanceof \DateTime) { $sanitized = $data->format(\DateTime::ISO8601); - } else if (is_array($data)) { + } elseif (is_array($data)) { foreach ($data as $property => $value) { $data[$property] = $this->sanitizeForSerialization($value); } $sanitized = $data; - } else if (is_object($data)) { + } elseif (is_object($data)) { $values = array(); foreach (array_keys($data::$swaggerTypes) as $property) { $getter = $data::$getters[$property]; @@ -198,7 +198,7 @@ class ObjectSerializer $deserialized = $data; } elseif ($class === '\SplFileObject') { // determine file name - if (preg_match('/Content-Disposition: inline; filename=[\'"]?([^\'"\s]+)[\'"]?$/i', $httpHeader, $match)) { + if (array_key_exists('Content-Disposition', $httpHeaders) && preg_match('/inline; filename=[\'"]?([^\'"\s]+)[\'"]?$/i', $httpHeader['Content-Disposition'], $match)) { $filename = Configuration::getDefaultConfiguration()->getTempFolderPath().$match[1]; } else { $filename = tempnam(Configuration::getDefaultConfiguration()->getTempFolderPath(), ''); diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index 53a81030813..22ae27fc77d 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -92,7 +92,7 @@ use \{{invokerPackage}}\ObjectSerializer; {{#operation}} /** - * {{{nickname}}} + * {{{operationId}}} * * {{{summary}}} * @@ -100,12 +100,28 @@ use \{{invokerPackage}}\ObjectSerializer; {{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} * @throws \{{invokerPackage}}\ApiException on non-2xx response */ - public function {{nickname}}({{#allParams}}${{paramName}}{{^required}}=null{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) + public function {{operationId}}({{#allParams}}${{paramName}}{{^required}} = null{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) + { + list($response, $statusCode, $httpHeader) = $this->{{operationId}}WithHttpInfo ({{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); + return $response; + } + + + /** + * {{{operationId}}}WithHttpInfo + * + * {{{summary}}} + * + {{#allParams}} * @param {{dataType}} ${{paramName}} {{description}} {{#required}}(required){{/required}}{{^required}}(optional){{/required}} + {{/allParams}} * @return Array of {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}null{{/returnType}}, HTTP status code, HTTP response headers (array of strings) + * @throws \{{invokerPackage}}\ApiException on non-2xx response + */ + public function {{operationId}}WithHttpInfo({{#allParams}}${{paramName}}{{^required}} = null{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { {{#allParams}}{{#required}} // verify the required parameter '{{paramName}}' is set if (${{paramName}} === null) { - throw new \InvalidArgumentException('Missing the required parameter ${{paramName}} when calling {{nickname}}'); + throw new \InvalidArgumentException('Missing the required parameter ${{paramName}} when calling {{operationId}}'); }{{/required}}{{/allParams}} // parse inputs @@ -162,7 +178,7 @@ use \{{invokerPackage}}\ObjectSerializer; // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } {{#authMethods}}{{#isApiKey}} @@ -180,19 +196,20 @@ use \{{invokerPackage}}\ObjectSerializer; }{{/isOAuth}} {{/authMethods}} // make the API Call - try - { - list($response, $httpHeader) = $this->apiClient->callApi( + try { + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams{{#returnType}}, '{{returnType}}'{{/returnType}} ); {{#returnType}} if (!$response) { - return null; + return array(null, $statusCode, $httpHeader); } - return $this->apiClient->getSerializer()->deserialize($response, '{{returnType}}', $httpHeader); + return array($this->apiClient->getSerializer()->deserialize($response, '{{returnType}}', $httpHeader), $statusCode, $httpHeader); + {{/returnType}}{{^returnType}} + return array(null, $statusCode, $httpHeader); {{/returnType}} } catch (ApiException $e) { switch ($e->getCode()) { {{#responses}}{{#dataType}} @@ -204,9 +221,6 @@ use \{{invokerPackage}}\ObjectSerializer; throw $e; } - {{#returnType}} - return null; - {{/returnType}} } {{/operation}} } diff --git a/modules/swagger-codegen/src/main/resources/qt5cpp/helpers-body.mustache b/modules/swagger-codegen/src/main/resources/qt5cpp/helpers-body.mustache index 7bd9b3f46cc..6b439996724 100644 --- a/modules/swagger-codegen/src/main/resources/qt5cpp/helpers-body.mustache +++ b/modules/swagger-codegen/src/main/resources/qt5cpp/helpers-body.mustache @@ -1,9 +1,9 @@ #include "SWGHelpers.h" #include "SWGModelFactory.h" #include "SWGObject.h" -#import -#import -#import +#include +#include +#include namespace Swagger { diff --git a/modules/swagger-codegen/src/main/resources/ruby/api.mustache b/modules/swagger-codegen/src/main/resources/ruby/api.mustache index b8e2e0da4c8..65e00081686 100644 --- a/modules/swagger-codegen/src/main/resources/ruby/api.mustache +++ b/modules/swagger-codegen/src/main/resources/ruby/api.mustache @@ -17,6 +17,17 @@ module {{moduleName}} {{#allParams}}{{^required}} # @option opts [{{{dataType}}}] :{{paramName}} {{description}} {{/required}}{{/allParams}} # @return [{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}nil{{/returnType}}] def {{operationId}}({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}opts = {}) + {{#returnType}}data, status_code, headers = {{/returnType}}{{operationId}}_with_http_info({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}opts) + {{#returnType}}return data{{/returnType}}{{^returnType}}return nil{{/returnType}} + end + + # {{summary}} + # {{notes}} +{{#allParams}}{{#required}} # @param {{paramName}} {{description}} +{{/required}}{{/allParams}} # @param [Hash] opts the optional parameters +{{#allParams}}{{^required}} # @option opts [{{{dataType}}}] :{{paramName}} {{description}} +{{/required}}{{/allParams}} # @return [Array<({{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}nil{{/returnType}}, Fixnum, Hash)>] {{#returnType}}{{{returnType}}} data{{/returnType}}{{^returnType}}nil{{/returnType}}, response status code and response headers + def {{operationId}}_with_http_info({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}opts = {}) if Configuration.debugging Configuration.logger.debug "Calling API: {{classname}}#{{operationId}} ..." end @@ -63,26 +74,17 @@ module {{moduleName}} {{/bodyParam}} auth_names = [{{#authMethods}}'{{name}}'{{#hasMore}}, {{/hasMore}}{{/authMethods}}] - {{#returnType}}result = @api_client.call_api(:{{httpMethod}}, path, + data, status_code, headers = @api_client.call_api(:{{httpMethod}}, path, :header_params => header_params, :query_params => query_params, :form_params => form_params, :body => post_body, - :auth_names => auth_names, - :return_type => '{{{returnType}}}') + :auth_names => auth_names{{#returnType}}, + :return_type => '{{{returnType}}}'{{/returnType}}) if Configuration.debugging - Configuration.logger.debug "API called: {{classname}}#{{operationId}}. Result: #{result.inspect}" + Configuration.logger.debug "API called: {{classname}}#{{operationId}}\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end - return result{{/returnType}}{{^returnType}}@api_client.call_api(:{{httpMethod}}, path, - :header_params => header_params, - :query_params => query_params, - :form_params => form_params, - :body => post_body, - :auth_names => auth_names) - if Configuration.debugging - Configuration.logger.debug "API called: {{classname}}#{{operationId}}" - end - return nil{{/returnType}} + return data, status_code, headers end {{/operation}} end diff --git a/modules/swagger-codegen/src/main/resources/ruby/api_client.mustache b/modules/swagger-codegen/src/main/resources/ruby/api_client.mustache index 4ef665bddf2..3873d476577 100644 --- a/modules/swagger-codegen/src/main/resources/ruby/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/ruby/api_client.mustache @@ -15,9 +15,6 @@ module {{moduleName}} # @return [Hash] attr_accessor :default_headers - # Stores the HTTP response from the last API call using this API client. - attr_accessor :last_response - def initialize(host = nil) @host = host || Configuration.base_url @format = 'json' @@ -28,13 +25,14 @@ module {{moduleName}} } end + # Call an API with given options. + # + # @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements: + # the data deserialized from response body (could be nil), response status code and response headers. def call_api(http_method, path, opts = {}) request = build_request(http_method, path, opts) response = request.run - # record as last response - @last_response = response - if Configuration.debugging Configuration.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n" end @@ -47,10 +45,11 @@ module {{moduleName}} end if opts[:return_type] - deserialize(response, opts[:return_type]) + data = deserialize(response, opts[:return_type]) else - nil + data = nil end + return data, response.code, response.headers end def build_request(http_method, path, opts = {}) diff --git a/samples/client/petstore/clojure/src/swagger_petstore/core.clj b/samples/client/petstore/clojure/src/swagger_petstore/core.clj index 523e38aae75..4c8a8426968 100644 --- a/samples/client/petstore/clojure/src/swagger_petstore/core.clj +++ b/samples/client/petstore/clojure/src/swagger_petstore/core.clj @@ -169,15 +169,17 @@ (map (fn [[k v]] [k (normalize-param v)])) (into {}))) -(defn json-mime? [mime] +(defn json-mime? "Check if the given MIME is a standard JSON MIME or :json." + [mime] (if mime (or (= :json mime) (re-matches #"application/json(;.*)?" (name mime))))) -(defn json-preferred-mime [mimes] +(defn json-preferred-mime "Choose a MIME from the given MIMEs with JSON preferred, i.e. return JSON if included, otherwise return the first one." + [mimes] (-> (filter json-mime? mimes) first (or (first mimes)))) diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Category.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Category.cs index 7d3f0936dce..d9cb6b21005 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Category.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Category.cs @@ -16,6 +16,14 @@ namespace IO.Swagger.Model [DataContract] public class Category : IEquatable { + /// + /// Initializes a new instance of the class. + /// + public Category() + { + + } + /// /// Gets or Sets Id diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Order.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Order.cs index 1f786769d55..2191707bd09 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Order.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Order.cs @@ -16,6 +16,14 @@ namespace IO.Swagger.Model [DataContract] public class Order : IEquatable { + /// + /// Initializes a new instance of the class. + /// + public Order() + { + + } + /// /// Gets or Sets Id diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Pet.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Pet.cs index d85d8a8be7e..10c44fb46a7 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Pet.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Pet.cs @@ -16,6 +16,14 @@ namespace IO.Swagger.Model [DataContract] public class Pet : IEquatable { + /// + /// Initializes a new instance of the class. + /// + public Pet() + { + + } + /// /// Gets or Sets Id diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Tag.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Tag.cs index 8b2cbe08474..93210505bf0 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Tag.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Tag.cs @@ -16,6 +16,14 @@ namespace IO.Swagger.Model [DataContract] public class Tag : IEquatable { + /// + /// Initializes a new instance of the class. + /// + public Tag() + { + + } + /// /// Gets or Sets Id diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/User.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/User.cs index d2c1e3a46eb..1fbd17da993 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/User.cs +++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/User.cs @@ -16,6 +16,14 @@ namespace IO.Swagger.Model [DataContract] public class User : IEquatable { + /// + /// Initializes a new instance of the class. + /// + public User() + { + + } + /// /// Gets or Sets Id diff --git a/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.userprefs b/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.userprefs index da9e64e0c90..ab3a8ae3ac4 100644 --- a/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.userprefs +++ b/samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.userprefs @@ -1,30 +1,11 @@  - + - - - - + + - - - - - - - - - - - - - - - - - diff --git a/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll b/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll index eb5aee17989..a438e103954 100755 Binary files a/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll and b/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll differ diff --git a/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb b/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb index 073b96f23b3..79928c469ee 100644 Binary files a/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb and b/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb differ diff --git a/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll b/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll index eb5aee17989..a438e103954 100755 Binary files a/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll and b/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll differ diff --git a/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb b/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb index 073b96f23b3..79928c469ee 100644 Binary files a/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb and b/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb differ 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 8d38c18e907..d4ee79cb3ad 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java @@ -104,9 +104,6 @@ public class ApiClient { private Map authentications; - private int statusCode; - private Map> responseHeaders; - private DateFormat dateFormat; private DateFormat datetimeFormat; private boolean lenientDatetimeFormat; @@ -143,8 +140,8 @@ public class ApiClient { // Setup authentications (key: authentication name, value: authentication). authentications = new HashMap(); - authentications.put("api_key", new ApiKeyAuth("header", "api_key")); authentications.put("petstore_auth", new OAuth()); + authentications.put("api_key", new ApiKeyAuth("header", "api_key")); // Prevent the authentications from being modified. authentications = Collections.unmodifiableMap(authentications); } @@ -176,24 +173,6 @@ public class ApiClient { return this; } - /** - * Gets the status code of the previous request. - * NOTE: Status code of last async response is not recorded here, it is - * passed to the callback methods instead. - */ - public int getStatusCode() { - return statusCode; - } - - /** - * Gets the response headers of the previous request. - * NOTE: Headers of last async response is not recorded here, it is passed - * to callback methods instead. - */ - public Map> getResponseHeaders() { - return responseHeaders; - } - public boolean isVerifyingSsl() { return verifyingSsl; } @@ -617,6 +596,8 @@ public class ApiClient { * @param response HTTP response * @param returnType The type of the Java object * @return The deserialized Java object + * @throws ApiException If fail to deserialize response body, i.e. cannot read response body + * or the Content-Type of the response is not supported. */ public T deserialize(Response response, Type returnType) throws ApiException { if (response == null || returnType == null) @@ -665,6 +646,7 @@ public class ApiClient { * @param obj The Java object * @param contentType The request Content-Type * @return The serialized string + * @throws ApiException If fail to serialize the given object */ public String serialize(Object obj, String contentType) throws ApiException { if (contentType.startsWith("application/json")) { @@ -679,6 +661,7 @@ public class ApiClient { /** * Download file from the given response. + * @throws ApiException If fail to read file content from response and write to disk */ public File downloadFileFromResponse(Response response) throws ApiException { try { @@ -730,7 +713,7 @@ public class ApiClient { /** * @see #execute(Call, Type) */ - public T execute(Call call) throws ApiException { + public ApiResponse execute(Call call) throws ApiException { return execute(call, null); } @@ -739,14 +722,16 @@ public class ApiClient { * * @param returnType The return type used to deserialize HTTP response body * @param The return type corresponding to (same with) returnType - * @return The Java object deserialized from response body. Returns null if returnType is null. + * @return ApiResponse object containing response status, headers and + * data, which is a Java object deserialized from response body and would be null + * when returnType is null. + * @throws ApiException If fail to execute the call */ - public T execute(Call call, Type returnType) throws ApiException { + public ApiResponse execute(Call call, Type returnType) throws ApiException { try { Response response = call.execute(); - this.statusCode = response.code(); - this.responseHeaders = response.headers().toMultimap(); - return handleResponse(response, returnType); + T data = handleResponse(response, returnType); + return new ApiResponse(response.code(), response.headers().toMultimap(), data); } catch (IOException e) { throw new ApiException(e); } @@ -755,7 +740,7 @@ public class ApiClient { /** * #see executeAsync(Call, Type, ApiCallback) */ - public void executeAsync(Call call, ApiCallback callback) throws ApiException { + public void executeAsync(Call call, ApiCallback callback) { executeAsync(call, null, callback); } @@ -786,6 +771,12 @@ public class ApiClient { }); } + /** + * Handle the given response, return the deserialized object when the response is successful. + * + * @throws ApiException If the response has a unsuccessful status code or + * fail to deserialize the response body + */ public T handleResponse(Response response, Type returnType) throws ApiException { if (response.isSuccessful()) { if (returnType == null || response.code() == 204) { @@ -819,6 +810,7 @@ public class ApiClient { * @param formParams The form parameters * @param authNames The authentications to apply * @return The HTTP call + * @throws ApiException If fail to serialize the request body object */ public Call buildCall(String path, String method, List queryParams, Object body, Map headerParams, Map formParams, String[] authNames, ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { updateParamsForAuth(authNames, queryParams, headerParams); 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 46b52990f44..bf096d22a5c 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 @@ package io.swagger.client; import java.util.Map; import java.util.List; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-11-29T00:18:08.052+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-12-07T12:21:33.403+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/ApiResponse.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiResponse.java new file mode 100644 index 00000000000..0a33f09e64e --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiResponse.java @@ -0,0 +1,46 @@ +package io.swagger.client; + +import java.util.List; +import java.util.Map; + +/** + * API response returned by API call. + * + * @param T The type of data that is deserialized from response body + */ +public class ApiResponse { + final private int statusCode; + final private Map> headers; + final private T data; + + /** + * @param statusCode The status code of HTTP response + * @param headers The headers of HTTP response + */ + public ApiResponse(int statusCode, Map> headers) { + this(statusCode, headers, null); + } + + /** + * @param statusCode The status code of HTTP response + * @param headers The headers of HTTP response + * @param data The object deserialized from response bod + */ + public ApiResponse(int statusCode, Map> headers, T data) { + this.statusCode = statusCode; + this.headers = headers; + this.data = data; + } + + public int getStatusCode() { + return statusCode; + } + + public Map> getHeaders() { + return headers; + } + + public T getData() { + return data; + } +} diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/Configuration.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/Configuration.java index b99c939af83..e996b89ef77 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-11-29T00:18:08.052+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-12-07T12:21:33.403+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 98f5f92e0a4..ef80752c495 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-11-29T00:18:08.052+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-12-07T12:21:33.403+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 702b8cf350c..3a105a258e4 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-11-29T00:18:08.052+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-12-07T12:21:33.403+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/PetApi.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/PetApi.java index cce05b29a3a..460cd0f4c4d 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/PetApi.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/PetApi.java @@ -3,6 +3,7 @@ package io.swagger.client.api; import io.swagger.client.ApiCallback; import io.swagger.client.ApiClient; import io.swagger.client.ApiException; +import io.swagger.client.ApiResponse; import io.swagger.client.Configuration; import io.swagger.client.Pair; import io.swagger.client.ProgressRequestBody; @@ -88,10 +89,22 @@ public class PetApi { * Update an existing pet * * @param body Pet object that needs to be added to the store + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public void updatePet(Pet body) throws ApiException { + updatePetWithHttpInfo(body); + } + + /** + * Update an existing pet + * + * @param body Pet object that needs to be added to the store + * @return ApiResponse + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + */ + public ApiResponse updatePetWithHttpInfo(Pet body) throws ApiException { Call call = updatePetCall(body, null, null); - apiClient.execute(call); + return apiClient.execute(call); } /** @@ -100,13 +113,14 @@ public class PetApi { * @param body Pet object that needs to be added to the store * @param callback The callback to be executed when the API call finishes * @return The request call + * @throws ApiException If fail to process the API call, e.g. serializing the request body object */ public Call updatePetAsync(Pet body, final ApiCallback callback) throws ApiException { ProgressResponseBody.ProgressListener progressListener = null; ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - if(callback != null) { + if (callback != null) { progressListener = new ProgressResponseBody.ProgressListener() { @Override public void update(long bytesRead, long contentLength, boolean done) { @@ -173,10 +187,22 @@ public class PetApi { * Add a new pet to the store * * @param body Pet object that needs to be added to the store + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public void addPet(Pet body) throws ApiException { + addPetWithHttpInfo(body); + } + + /** + * Add a new pet to the store + * + * @param body Pet object that needs to be added to the store + * @return ApiResponse + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + */ + public ApiResponse addPetWithHttpInfo(Pet body) throws ApiException { Call call = addPetCall(body, null, null); - apiClient.execute(call); + return apiClient.execute(call); } /** @@ -185,13 +211,14 @@ public class PetApi { * @param body Pet object that needs to be added to the store * @param callback The callback to be executed when the API call finishes * @return The request call + * @throws ApiException If fail to process the API call, e.g. serializing the request body object */ public Call addPetAsync(Pet body, final ApiCallback callback) throws ApiException { ProgressResponseBody.ProgressListener progressListener = null; ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - if(callback != null) { + if (callback != null) { progressListener = new ProgressResponseBody.ProgressListener() { @Override public void update(long bytesRead, long contentLength, boolean done) { @@ -261,8 +288,21 @@ public class PetApi { * Multiple status values can be provided with comma seperated strings * @param status Status values that need to be considered for filter * @return List + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public List findPetsByStatus(List status) throws ApiException { + ApiResponse> resp = findPetsByStatusWithHttpInfo(status); + return resp.getData(); + } + + /** + * Finds Pets by status + * Multiple status values can be provided with comma seperated strings + * @param status Status values that need to be considered for filter + * @return ApiResponse> + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + */ + public ApiResponse> findPetsByStatusWithHttpInfo(List status) throws ApiException { Call call = findPetsByStatusCall(status, null, null); Type returnType = new TypeToken>(){}.getType(); return apiClient.execute(call, returnType); @@ -274,13 +314,14 @@ public class PetApi { * @param status Status values that need to be considered for filter * @param callback The callback to be executed when the API call finishes * @return The request call + * @throws ApiException If fail to process the API call, e.g. serializing the request body object */ public Call findPetsByStatusAsync(List status, final ApiCallback> callback) throws ApiException { ProgressResponseBody.ProgressListener progressListener = null; ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - if(callback != null) { + if (callback != null) { progressListener = new ProgressResponseBody.ProgressListener() { @Override public void update(long bytesRead, long contentLength, boolean done) { @@ -351,8 +392,21 @@ public class PetApi { * Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. * @param tags Tags to filter by * @return List + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public List findPetsByTags(List tags) throws ApiException { + ApiResponse> resp = findPetsByTagsWithHttpInfo(tags); + return resp.getData(); + } + + /** + * Finds Pets by tags + * Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. + * @param tags Tags to filter by + * @return ApiResponse> + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + */ + public ApiResponse> findPetsByTagsWithHttpInfo(List tags) throws ApiException { Call call = findPetsByTagsCall(tags, null, null); Type returnType = new TypeToken>(){}.getType(); return apiClient.execute(call, returnType); @@ -364,13 +418,14 @@ public class PetApi { * @param tags Tags to filter by * @param callback The callback to be executed when the API call finishes * @return The request call + * @throws ApiException If fail to process the API call, e.g. serializing the request body object */ public Call findPetsByTagsAsync(List tags, final ApiCallback> callback) throws ApiException { ProgressResponseBody.ProgressListener progressListener = null; ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - if(callback != null) { + if (callback != null) { progressListener = new ProgressResponseBody.ProgressListener() { @Override public void update(long bytesRead, long contentLength, boolean done) { @@ -445,8 +500,21 @@ public class PetApi { * Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions * @param petId ID of pet that needs to be fetched * @return Pet + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public Pet getPetById(Long petId) throws ApiException { + ApiResponse resp = getPetByIdWithHttpInfo(petId); + return resp.getData(); + } + + /** + * Find pet by ID + * Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions + * @param petId ID of pet that needs to be fetched + * @return ApiResponse + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + */ + public ApiResponse getPetByIdWithHttpInfo(Long petId) throws ApiException { Call call = getPetByIdCall(petId, null, null); Type returnType = new TypeToken(){}.getType(); return apiClient.execute(call, returnType); @@ -458,13 +526,14 @@ public class PetApi { * @param petId ID of pet that needs to be fetched * @param callback The callback to be executed when the API call finishes * @return The request call + * @throws ApiException If fail to process the API call, e.g. serializing the request body object */ public Call getPetByIdAsync(Long petId, final ApiCallback callback) throws ApiException { ProgressResponseBody.ProgressListener progressListener = null; ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - if(callback != null) { + if (callback != null) { progressListener = new ProgressResponseBody.ProgressListener() { @Override public void update(long bytesRead, long contentLength, boolean done) { @@ -487,7 +556,7 @@ public class PetApi { } /* Build call for updatePetWithForm */ - private Call updatePetWithFormCall(String petId,String name,String status, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { + private Call updatePetWithFormCall(String petId, String name, String status, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object postBody = null; // verify the required parameter 'petId' is set @@ -544,10 +613,24 @@ public class PetApi { * @param petId ID of pet that needs to be updated * @param name Updated name of the pet * @param status Updated status of the pet + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public void updatePetWithForm(String petId, String name, String status) throws ApiException { - Call call = updatePetWithFormCall(petId,name,status, null, null); - apiClient.execute(call); + updatePetWithFormWithHttpInfo(petId, name, status); + } + + /** + * Updates a pet in the store with form data + * + * @param petId ID of pet that needs to be updated + * @param name Updated name of the pet + * @param status Updated status of the pet + * @return ApiResponse + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + */ + public ApiResponse updatePetWithFormWithHttpInfo(String petId, String name, String status) throws ApiException { + Call call = updatePetWithFormCall(petId, name, status, null, null); + return apiClient.execute(call); } /** @@ -558,13 +641,14 @@ public class PetApi { * @param status Updated status of the pet * @param callback The callback to be executed when the API call finishes * @return The request call + * @throws ApiException If fail to process the API call, e.g. serializing the request body object */ public Call updatePetWithFormAsync(String petId, String name, String status, final ApiCallback callback) throws ApiException { ProgressResponseBody.ProgressListener progressListener = null; ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - if(callback != null) { + if (callback != null) { progressListener = new ProgressResponseBody.ProgressListener() { @Override public void update(long bytesRead, long contentLength, boolean done) { @@ -580,13 +664,13 @@ public class PetApi { }; } - Call call = updatePetWithFormCall(petId,name,status, progressListener, progressRequestListener); + Call call = updatePetWithFormCall(petId, name, status, progressListener, progressRequestListener); apiClient.executeAsync(call, callback); return call; } /* Build call for deletePet */ - private Call deletePetCall(Long petId,String apiKey, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { + private Call deletePetCall(Long petId, String apiKey, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object postBody = null; // verify the required parameter 'petId' is set @@ -640,10 +724,23 @@ public class PetApi { * * @param petId Pet id to delete * @param apiKey + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public void deletePet(Long petId, String apiKey) throws ApiException { - Call call = deletePetCall(petId,apiKey, null, null); - apiClient.execute(call); + deletePetWithHttpInfo(petId, apiKey); + } + + /** + * Deletes a pet + * + * @param petId Pet id to delete + * @param apiKey + * @return ApiResponse + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + */ + public ApiResponse deletePetWithHttpInfo(Long petId, String apiKey) throws ApiException { + Call call = deletePetCall(petId, apiKey, null, null); + return apiClient.execute(call); } /** @@ -653,13 +750,14 @@ public class PetApi { * @param apiKey * @param callback The callback to be executed when the API call finishes * @return The request call + * @throws ApiException If fail to process the API call, e.g. serializing the request body object */ public Call deletePetAsync(Long petId, String apiKey, final ApiCallback callback) throws ApiException { ProgressResponseBody.ProgressListener progressListener = null; ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - if(callback != null) { + if (callback != null) { progressListener = new ProgressResponseBody.ProgressListener() { @Override public void update(long bytesRead, long contentLength, boolean done) { @@ -675,13 +773,13 @@ public class PetApi { }; } - Call call = deletePetCall(petId,apiKey, progressListener, progressRequestListener); + Call call = deletePetCall(petId, apiKey, progressListener, progressRequestListener); apiClient.executeAsync(call, callback); return call; } /* Build call for uploadFile */ - private Call uploadFileCall(Long petId,String additionalMetadata,File file, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { + private Call uploadFileCall(Long petId, String additionalMetadata, File file, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object postBody = null; // verify the required parameter 'petId' is set @@ -738,10 +836,24 @@ public class PetApi { * @param petId ID of pet to update * @param additionalMetadata Additional data to pass to server * @param file file to upload + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public void uploadFile(Long petId, String additionalMetadata, File file) throws ApiException { - Call call = uploadFileCall(petId,additionalMetadata,file, null, null); - apiClient.execute(call); + uploadFileWithHttpInfo(petId, additionalMetadata, file); + } + + /** + * uploads an image + * + * @param petId ID of pet to update + * @param additionalMetadata Additional data to pass to server + * @param file file to upload + * @return ApiResponse + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + */ + public ApiResponse uploadFileWithHttpInfo(Long petId, String additionalMetadata, File file) throws ApiException { + Call call = uploadFileCall(petId, additionalMetadata, file, null, null); + return apiClient.execute(call); } /** @@ -752,13 +864,14 @@ public class PetApi { * @param file file to upload * @param callback The callback to be executed when the API call finishes * @return The request call + * @throws ApiException If fail to process the API call, e.g. serializing the request body object */ public Call uploadFileAsync(Long petId, String additionalMetadata, File file, final ApiCallback callback) throws ApiException { ProgressResponseBody.ProgressListener progressListener = null; ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - if(callback != null) { + if (callback != null) { progressListener = new ProgressResponseBody.ProgressListener() { @Override public void update(long bytesRead, long contentLength, boolean done) { @@ -774,7 +887,7 @@ public class PetApi { }; } - Call call = uploadFileCall(petId,additionalMetadata,file, progressListener, progressRequestListener); + Call call = uploadFileCall(petId, additionalMetadata, file, progressListener, progressRequestListener); apiClient.executeAsync(call, callback); return call; } diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/StoreApi.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/StoreApi.java index 551fe0fbfc2..5e6c7c48c6b 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/StoreApi.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/StoreApi.java @@ -3,6 +3,7 @@ package io.swagger.client.api; import io.swagger.client.ApiCallback; import io.swagger.client.ApiClient; import io.swagger.client.ApiException; +import io.swagger.client.ApiResponse; import io.swagger.client.Configuration; import io.swagger.client.Pair; import io.swagger.client.ProgressRequestBody; @@ -43,7 +44,7 @@ public class StoreApi { /* Build call for getInventory */ - private Call getInventoryCall( final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { + private Call getInventoryCall(final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object postBody = null; @@ -88,9 +89,21 @@ public class StoreApi { * Returns pet inventories by status * Returns a map of status codes to quantities * @return Map + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public Map getInventory() throws ApiException { - Call call = getInventoryCall( null, null); + ApiResponse> resp = getInventoryWithHttpInfo(); + return resp.getData(); + } + + /** + * Returns pet inventories by status + * Returns a map of status codes to quantities + * @return ApiResponse> + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + */ + public ApiResponse> getInventoryWithHttpInfo() throws ApiException { + Call call = getInventoryCall(null, null); Type returnType = new TypeToken>(){}.getType(); return apiClient.execute(call, returnType); } @@ -100,13 +113,14 @@ public class StoreApi { * Returns a map of status codes to quantities * @param callback The callback to be executed when the API call finishes * @return The request call + * @throws ApiException If fail to process the API call, e.g. serializing the request body object */ public Call getInventoryAsync(final ApiCallback> callback) throws ApiException { ProgressResponseBody.ProgressListener progressListener = null; ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - if(callback != null) { + if (callback != null) { progressListener = new ProgressResponseBody.ProgressListener() { @Override public void update(long bytesRead, long contentLength, boolean done) { @@ -122,7 +136,7 @@ public class StoreApi { }; } - Call call = getInventoryCall( progressListener, progressRequestListener); + Call call = getInventoryCall(progressListener, progressRequestListener); Type returnType = new TypeToken>(){}.getType(); apiClient.executeAsync(call, returnType, callback); return call; @@ -175,8 +189,21 @@ public class StoreApi { * * @param body order placed for purchasing the pet * @return Order + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public Order placeOrder(Order body) throws ApiException { + ApiResponse resp = placeOrderWithHttpInfo(body); + return resp.getData(); + } + + /** + * Place an order for a pet + * + * @param body order placed for purchasing the pet + * @return ApiResponse + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + */ + public ApiResponse placeOrderWithHttpInfo(Order body) throws ApiException { Call call = placeOrderCall(body, null, null); Type returnType = new TypeToken(){}.getType(); return apiClient.execute(call, returnType); @@ -188,13 +215,14 @@ public class StoreApi { * @param body order placed for purchasing the pet * @param callback The callback to be executed when the API call finishes * @return The request call + * @throws ApiException If fail to process the API call, e.g. serializing the request body object */ public Call placeOrderAsync(Order body, final ApiCallback callback) throws ApiException { ProgressResponseBody.ProgressListener progressListener = null; ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - if(callback != null) { + if (callback != null) { progressListener = new ProgressResponseBody.ProgressListener() { @Override public void update(long bytesRead, long contentLength, boolean done) { @@ -269,8 +297,21 @@ public class StoreApi { * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions * @param orderId ID of pet that needs to be fetched * @return Order + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public Order getOrderById(String orderId) throws ApiException { + ApiResponse resp = getOrderByIdWithHttpInfo(orderId); + return resp.getData(); + } + + /** + * Find purchase order by ID + * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + * @param orderId ID of pet that needs to be fetched + * @return ApiResponse + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + */ + public ApiResponse getOrderByIdWithHttpInfo(String orderId) throws ApiException { Call call = getOrderByIdCall(orderId, null, null); Type returnType = new TypeToken(){}.getType(); return apiClient.execute(call, returnType); @@ -282,13 +323,14 @@ public class StoreApi { * @param orderId ID of pet that needs to be fetched * @param callback The callback to be executed when the API call finishes * @return The request call + * @throws ApiException If fail to process the API call, e.g. serializing the request body object */ public Call getOrderByIdAsync(String orderId, final ApiCallback callback) throws ApiException { ProgressResponseBody.ProgressListener progressListener = null; ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - if(callback != null) { + if (callback != null) { progressListener = new ProgressResponseBody.ProgressListener() { @Override public void update(long bytesRead, long contentLength, boolean done) { @@ -362,10 +404,22 @@ public class StoreApi { * Delete purchase order by ID * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors * @param orderId ID of the order that needs to be deleted + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public void deleteOrder(String orderId) throws ApiException { + deleteOrderWithHttpInfo(orderId); + } + + /** + * Delete purchase order by ID + * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + * @param orderId ID of the order that needs to be deleted + * @return ApiResponse + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + */ + public ApiResponse deleteOrderWithHttpInfo(String orderId) throws ApiException { Call call = deleteOrderCall(orderId, null, null); - apiClient.execute(call); + return apiClient.execute(call); } /** @@ -374,13 +428,14 @@ public class StoreApi { * @param orderId ID of the order that needs to be deleted * @param callback The callback to be executed when the API call finishes * @return The request call + * @throws ApiException If fail to process the API call, e.g. serializing the request body object */ public Call deleteOrderAsync(String orderId, final ApiCallback callback) throws ApiException { ProgressResponseBody.ProgressListener progressListener = null; ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - if(callback != null) { + if (callback != null) { progressListener = new ProgressResponseBody.ProgressListener() { @Override public void update(long bytesRead, long contentLength, boolean done) { diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/UserApi.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/UserApi.java index 57aebd4a4d1..ab043bdbe3b 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/UserApi.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/UserApi.java @@ -3,6 +3,7 @@ package io.swagger.client.api; import io.swagger.client.ApiCallback; import io.swagger.client.ApiClient; import io.swagger.client.ApiException; +import io.swagger.client.ApiResponse; import io.swagger.client.Configuration; import io.swagger.client.Pair; import io.swagger.client.ProgressRequestBody; @@ -88,10 +89,22 @@ public class UserApi { * Create user * This can only be done by the logged in user. * @param body Created user object + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public void createUser(User body) throws ApiException { + createUserWithHttpInfo(body); + } + + /** + * Create user + * This can only be done by the logged in user. + * @param body Created user object + * @return ApiResponse + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + */ + public ApiResponse createUserWithHttpInfo(User body) throws ApiException { Call call = createUserCall(body, null, null); - apiClient.execute(call); + return apiClient.execute(call); } /** @@ -100,13 +113,14 @@ public class UserApi { * @param body Created user object * @param callback The callback to be executed when the API call finishes * @return The request call + * @throws ApiException If fail to process the API call, e.g. serializing the request body object */ public Call createUserAsync(User body, final ApiCallback callback) throws ApiException { ProgressResponseBody.ProgressListener progressListener = null; ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - if(callback != null) { + if (callback != null) { progressListener = new ProgressResponseBody.ProgressListener() { @Override public void update(long bytesRead, long contentLength, boolean done) { @@ -173,10 +187,22 @@ public class UserApi { * Creates list of users with given input array * * @param body List of user object + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public void createUsersWithArrayInput(List body) throws ApiException { + createUsersWithArrayInputWithHttpInfo(body); + } + + /** + * Creates list of users with given input array + * + * @param body List of user object + * @return ApiResponse + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + */ + public ApiResponse createUsersWithArrayInputWithHttpInfo(List body) throws ApiException { Call call = createUsersWithArrayInputCall(body, null, null); - apiClient.execute(call); + return apiClient.execute(call); } /** @@ -185,13 +211,14 @@ public class UserApi { * @param body List of user object * @param callback The callback to be executed when the API call finishes * @return The request call + * @throws ApiException If fail to process the API call, e.g. serializing the request body object */ public Call createUsersWithArrayInputAsync(List body, final ApiCallback callback) throws ApiException { ProgressResponseBody.ProgressListener progressListener = null; ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - if(callback != null) { + if (callback != null) { progressListener = new ProgressResponseBody.ProgressListener() { @Override public void update(long bytesRead, long contentLength, boolean done) { @@ -258,10 +285,22 @@ public class UserApi { * Creates list of users with given input array * * @param body List of user object + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public void createUsersWithListInput(List body) throws ApiException { + createUsersWithListInputWithHttpInfo(body); + } + + /** + * Creates list of users with given input array + * + * @param body List of user object + * @return ApiResponse + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + */ + public ApiResponse createUsersWithListInputWithHttpInfo(List body) throws ApiException { Call call = createUsersWithListInputCall(body, null, null); - apiClient.execute(call); + return apiClient.execute(call); } /** @@ -270,13 +309,14 @@ public class UserApi { * @param body List of user object * @param callback The callback to be executed when the API call finishes * @return The request call + * @throws ApiException If fail to process the API call, e.g. serializing the request body object */ public Call createUsersWithListInputAsync(List body, final ApiCallback callback) throws ApiException { ProgressResponseBody.ProgressListener progressListener = null; ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - if(callback != null) { + if (callback != null) { progressListener = new ProgressResponseBody.ProgressListener() { @Override public void update(long bytesRead, long contentLength, boolean done) { @@ -298,7 +338,7 @@ public class UserApi { } /* Build call for loginUser */ - private Call loginUserCall(String username,String password, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { + private Call loginUserCall(String username, String password, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object postBody = null; @@ -349,9 +389,23 @@ public class UserApi { * @param username The user name for login * @param password The password for login in clear text * @return String + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public String loginUser(String username, String password) throws ApiException { - Call call = loginUserCall(username,password, null, null); + ApiResponse resp = loginUserWithHttpInfo(username, password); + return resp.getData(); + } + + /** + * Logs user into the system + * + * @param username The user name for login + * @param password The password for login in clear text + * @return ApiResponse + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + */ + public ApiResponse loginUserWithHttpInfo(String username, String password) throws ApiException { + Call call = loginUserCall(username, password, null, null); Type returnType = new TypeToken(){}.getType(); return apiClient.execute(call, returnType); } @@ -363,13 +417,14 @@ public class UserApi { * @param password The password for login in clear text * @param callback The callback to be executed when the API call finishes * @return The request call + * @throws ApiException If fail to process the API call, e.g. serializing the request body object */ public Call loginUserAsync(String username, String password, final ApiCallback callback) throws ApiException { ProgressResponseBody.ProgressListener progressListener = null; ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - if(callback != null) { + if (callback != null) { progressListener = new ProgressResponseBody.ProgressListener() { @Override public void update(long bytesRead, long contentLength, boolean done) { @@ -385,14 +440,14 @@ public class UserApi { }; } - Call call = loginUserCall(username,password, progressListener, progressRequestListener); + Call call = loginUserCall(username, password, progressListener, progressRequestListener); Type returnType = new TypeToken(){}.getType(); apiClient.executeAsync(call, returnType, callback); return call; } /* Build call for logoutUser */ - private Call logoutUserCall( final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { + private Call logoutUserCall(final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object postBody = null; @@ -436,10 +491,21 @@ public class UserApi { /** * Logs out current logged in user session * + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public void logoutUser() throws ApiException { - Call call = logoutUserCall( null, null); - apiClient.execute(call); + logoutUserWithHttpInfo(); + } + + /** + * Logs out current logged in user session + * + * @return ApiResponse + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + */ + public ApiResponse logoutUserWithHttpInfo() throws ApiException { + Call call = logoutUserCall(null, null); + return apiClient.execute(call); } /** @@ -447,13 +513,14 @@ public class UserApi { * * @param callback The callback to be executed when the API call finishes * @return The request call + * @throws ApiException If fail to process the API call, e.g. serializing the request body object */ public Call logoutUserAsync(final ApiCallback callback) throws ApiException { ProgressResponseBody.ProgressListener progressListener = null; ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - if(callback != null) { + if (callback != null) { progressListener = new ProgressResponseBody.ProgressListener() { @Override public void update(long bytesRead, long contentLength, boolean done) { @@ -469,7 +536,7 @@ public class UserApi { }; } - Call call = logoutUserCall( progressListener, progressRequestListener); + Call call = logoutUserCall(progressListener, progressRequestListener); apiClient.executeAsync(call, callback); return call; } @@ -527,8 +594,21 @@ public class UserApi { * * @param username The name that needs to be fetched. Use user1 for testing. * @return User + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public User getUserByName(String username) throws ApiException { + ApiResponse resp = getUserByNameWithHttpInfo(username); + return resp.getData(); + } + + /** + * Get user by user name + * + * @param username The name that needs to be fetched. Use user1 for testing. + * @return ApiResponse + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + */ + public ApiResponse getUserByNameWithHttpInfo(String username) throws ApiException { Call call = getUserByNameCall(username, null, null); Type returnType = new TypeToken(){}.getType(); return apiClient.execute(call, returnType); @@ -540,13 +620,14 @@ public class UserApi { * @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 + * @throws ApiException If fail to process the API call, e.g. serializing the request body object */ public Call getUserByNameAsync(String username, final ApiCallback callback) throws ApiException { ProgressResponseBody.ProgressListener progressListener = null; ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - if(callback != null) { + if (callback != null) { progressListener = new ProgressResponseBody.ProgressListener() { @Override public void update(long bytesRead, long contentLength, boolean done) { @@ -569,7 +650,7 @@ public class UserApi { } /* Build call for updateUser */ - private Call updateUserCall(String username,User body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { + private Call updateUserCall(String username, User body, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { Object postBody = body; // verify the required parameter 'username' is set @@ -621,10 +702,23 @@ public class UserApi { * This can only be done by the logged in user. * @param username name that need to be deleted * @param body Updated user object + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public void updateUser(String username, User body) throws ApiException { - Call call = updateUserCall(username,body, null, null); - apiClient.execute(call); + updateUserWithHttpInfo(username, body); + } + + /** + * Updated user + * This can only be done by the logged in user. + * @param username name that need to be deleted + * @param body Updated user object + * @return ApiResponse + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + */ + public ApiResponse updateUserWithHttpInfo(String username, User body) throws ApiException { + Call call = updateUserCall(username, body, null, null); + return apiClient.execute(call); } /** @@ -634,13 +728,14 @@ public class UserApi { * @param body Updated user object * @param callback The callback to be executed when the API call finishes * @return The request call + * @throws ApiException If fail to process the API call, e.g. serializing the request body object */ public Call updateUserAsync(String username, User body, final ApiCallback callback) throws ApiException { ProgressResponseBody.ProgressListener progressListener = null; ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - if(callback != null) { + if (callback != null) { progressListener = new ProgressResponseBody.ProgressListener() { @Override public void update(long bytesRead, long contentLength, boolean done) { @@ -656,7 +751,7 @@ public class UserApi { }; } - Call call = updateUserCall(username,body, progressListener, progressRequestListener); + Call call = updateUserCall(username, body, progressListener, progressRequestListener); apiClient.executeAsync(call, callback); return call; } @@ -713,10 +808,22 @@ public class UserApi { * Delete user * This can only be done by the logged in user. * @param username The name that needs to be deleted + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body */ public void deleteUser(String username) throws ApiException { + deleteUserWithHttpInfo(username); + } + + /** + * Delete user + * This can only be done by the logged in user. + * @param username The name that needs to be deleted + * @return ApiResponse + * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body + */ + public ApiResponse deleteUserWithHttpInfo(String username) throws ApiException { Call call = deleteUserCall(username, null, null); - apiClient.execute(call); + return apiClient.execute(call); } /** @@ -725,13 +832,14 @@ public class UserApi { * @param username The name that needs to be deleted * @param callback The callback to be executed when the API call finishes * @return The request call + * @throws ApiException If fail to process the API call, e.g. serializing the request body object */ public Call deleteUserAsync(String username, final ApiCallback callback) throws ApiException { ProgressResponseBody.ProgressListener progressListener = null; ProgressRequestBody.ProgressRequestListener progressRequestListener = null; - if(callback != null) { + if (callback != null) { progressListener = new ProgressResponseBody.ProgressListener() { @Override public void update(long bytesRead, long contentLength, boolean done) { diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/ApiKeyAuth.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/auth/ApiKeyAuth.java index 2110aff20d8..8439d297d45 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 io.swagger.client.Pair; import java.util.Map; import java.util.List; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-11-29T00:18:08.052+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-12-07T12:21:33.403+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 f00217c451e..6817892cce9 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 io.swagger.client.Pair; import java.util.Map; import java.util.List; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-11-29T00:18:08.052+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-12-07T12:21:33.403+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 b750aaa2360..d0b457bacd8 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 io.swagger.client.Pair; import java.util.Map; import java.util.List; -@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-11-29T00:18:08.052+08:00") +@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-12-07T12:21:33.403+08:00") public class OAuth implements Authentication { private String accessToken; diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/Pet.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/Pet.java index bc3b80370b0..7e771866b39 100644 --- a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/Pet.java +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/model/Pet.java @@ -2,8 +2,8 @@ package io.swagger.client.model; import io.swagger.client.StringUtil; import io.swagger.client.model.Category; -import io.swagger.client.model.Tag; import java.util.*; +import io.swagger.client.model.Tag; import com.google.gson.annotations.SerializedName; 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 b6d8286d7ef..56cc8073984 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/io/swagger/petstore/test/PetApiTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/io/swagger/petstore/test/PetApiTest.java @@ -1,10 +1,6 @@ package io.swagger.petstore.test; -import io.swagger.client.ApiClient; -import io.swagger.client.ApiException; -import io.swagger.client.Configuration; - -import io.swagger.client.ApiCallback; +import io.swagger.client.*; import io.swagger.client.api.*; import io.swagger.client.auth.*; import io.swagger.client.model.*; @@ -71,6 +67,21 @@ public class PetApiTest { assertEquals(fetched.getCategory().getName(), pet.getCategory().getName()); } + @Test + public void testCreateAndGetPetWithHttpInfo() throws Exception { + Pet pet = createRandomPet(); + api.addPetWithHttpInfo(pet); + + ApiResponse resp = api.getPetByIdWithHttpInfo(pet.getId()); + assertEquals(200, resp.getStatusCode()); + assertEquals("application/json", resp.getHeaders().get("Content-Type").get(0)); + Pet fetched = resp.getData(); + assertNotNull(fetched); + assertEquals(pet.getId(), fetched.getId()); + assertNotNull(fetched.getCategory()); + assertEquals(fetched.getCategory().getName(), pet.getCategory().getName()); + } + @Test public void testCreateAndGetPetAsync() throws Exception { Pet pet = createRandomPet(); diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php index bc03a7974d3..18aeba64072 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php @@ -100,7 +100,23 @@ class PetApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function updatePet($body=null) + public function updatePet($body = null) + { + list($response, $statusCode, $httpHeader) = $this->updatePetWithHttpInfo ($body); + return $response; + } + + + /** + * updatePetWithHttpInfo + * + * Update an existing pet + * + * @param \Swagger\Client\Model\Pet $body Pet object that needs to be added to the store (optional) + * @return Array of null, HTTP status code, HTTP response headers (array of strings) + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function updatePetWithHttpInfo($body = null) { @@ -131,7 +147,7 @@ class PetApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } @@ -141,21 +157,21 @@ class PetApi } // make the API Call - try - { - list($response, $httpHeader) = $this->apiClient->callApi( + try { + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams ); + return array(null, $statusCode, $httpHeader); + } catch (ApiException $e) { switch ($e->getCode()) { } throw $e; } - } /** @@ -167,7 +183,23 @@ class PetApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function addPet($body=null) + public function addPet($body = null) + { + list($response, $statusCode, $httpHeader) = $this->addPetWithHttpInfo ($body); + return $response; + } + + + /** + * addPetWithHttpInfo + * + * Add a new pet to the store + * + * @param \Swagger\Client\Model\Pet $body Pet object that needs to be added to the store (optional) + * @return Array of null, HTTP status code, HTTP response headers (array of strings) + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function addPetWithHttpInfo($body = null) { @@ -198,7 +230,7 @@ class PetApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } @@ -208,21 +240,21 @@ class PetApi } // make the API Call - try - { - list($response, $httpHeader) = $this->apiClient->callApi( + try { + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams ); + return array(null, $statusCode, $httpHeader); + } catch (ApiException $e) { switch ($e->getCode()) { } throw $e; } - } /** @@ -234,7 +266,23 @@ class PetApi * @return \Swagger\Client\Model\Pet[] * @throws \Swagger\Client\ApiException on non-2xx response */ - public function findPetsByStatus($status=null) + public function findPetsByStatus($status = null) + { + list($response, $statusCode, $httpHeader) = $this->findPetsByStatusWithHttpInfo ($status); + return $response; + } + + + /** + * findPetsByStatusWithHttpInfo + * + * Finds Pets by status + * + * @param string[] $status Status values that need to be considered for filter (optional) + * @return Array of \Swagger\Client\Model\Pet[], HTTP status code, HTTP response headers (array of strings) + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function findPetsByStatusWithHttpInfo($status = null) { @@ -264,7 +312,7 @@ class PetApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } @@ -274,19 +322,18 @@ class PetApi } // make the API Call - try - { - list($response, $httpHeader) = $this->apiClient->callApi( + try { + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams, '\Swagger\Client\Model\Pet[]' ); if (!$response) { - return null; + return array(null, $statusCode, $httpHeader); } - return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Pet[]', $httpHeader); + return array($this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Pet[]', $httpHeader), $statusCode, $httpHeader); } catch (ApiException $e) { switch ($e->getCode()) { @@ -298,9 +345,6 @@ class PetApi throw $e; } - - return null; - } /** @@ -312,7 +356,23 @@ class PetApi * @return \Swagger\Client\Model\Pet[] * @throws \Swagger\Client\ApiException on non-2xx response */ - public function findPetsByTags($tags=null) + public function findPetsByTags($tags = null) + { + list($response, $statusCode, $httpHeader) = $this->findPetsByTagsWithHttpInfo ($tags); + return $response; + } + + + /** + * findPetsByTagsWithHttpInfo + * + * Finds Pets by tags + * + * @param string[] $tags Tags to filter by (optional) + * @return Array of \Swagger\Client\Model\Pet[], HTTP status code, HTTP response headers (array of strings) + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function findPetsByTagsWithHttpInfo($tags = null) { @@ -342,7 +402,7 @@ class PetApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } @@ -352,19 +412,18 @@ class PetApi } // make the API Call - try - { - list($response, $httpHeader) = $this->apiClient->callApi( + try { + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams, '\Swagger\Client\Model\Pet[]' ); if (!$response) { - return null; + return array(null, $statusCode, $httpHeader); } - return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Pet[]', $httpHeader); + return array($this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Pet[]', $httpHeader), $statusCode, $httpHeader); } catch (ApiException $e) { switch ($e->getCode()) { @@ -376,9 +435,6 @@ class PetApi throw $e; } - - return null; - } /** @@ -391,6 +447,22 @@ class PetApi * @throws \Swagger\Client\ApiException on non-2xx response */ public function getPetById($pet_id) + { + list($response, $statusCode, $httpHeader) = $this->getPetByIdWithHttpInfo ($pet_id); + return $response; + } + + + /** + * getPetByIdWithHttpInfo + * + * Find pet by ID + * + * @param int $pet_id ID of pet that needs to be fetched (required) + * @return Array of \Swagger\Client\Model\Pet, HTTP status code, HTTP response headers (array of strings) + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function getPetByIdWithHttpInfo($pet_id) { // verify the required parameter 'pet_id' is set @@ -428,7 +500,7 @@ class PetApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } @@ -440,19 +512,18 @@ class PetApi // make the API Call - try - { - list($response, $httpHeader) = $this->apiClient->callApi( + try { + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams, '\Swagger\Client\Model\Pet' ); if (!$response) { - return null; + return array(null, $statusCode, $httpHeader); } - return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Pet', $httpHeader); + return array($this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Pet', $httpHeader), $statusCode, $httpHeader); } catch (ApiException $e) { switch ($e->getCode()) { @@ -464,9 +535,6 @@ class PetApi throw $e; } - - return null; - } /** @@ -480,7 +548,25 @@ class PetApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function updatePetWithForm($pet_id, $name=null, $status=null) + public function updatePetWithForm($pet_id, $name = null, $status = null) + { + list($response, $statusCode, $httpHeader) = $this->updatePetWithFormWithHttpInfo ($pet_id, $name, $status); + return $response; + } + + + /** + * updatePetWithFormWithHttpInfo + * + * Updates a pet in the store with form data + * + * @param string $pet_id ID of pet that needs to be updated (required) + * @param string $name Updated name of the pet (optional) + * @param string $status Updated status of the pet (optional) + * @return Array of null, HTTP status code, HTTP response headers (array of strings) + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function updatePetWithFormWithHttpInfo($pet_id, $name = null, $status = null) { // verify the required parameter 'pet_id' is set @@ -530,7 +616,7 @@ class PetApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } @@ -540,21 +626,21 @@ class PetApi } // make the API Call - try - { - list($response, $httpHeader) = $this->apiClient->callApi( + try { + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams ); + return array(null, $statusCode, $httpHeader); + } catch (ApiException $e) { switch ($e->getCode()) { } throw $e; } - } /** @@ -567,7 +653,24 @@ class PetApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function deletePet($pet_id, $api_key=null) + public function deletePet($pet_id, $api_key = null) + { + list($response, $statusCode, $httpHeader) = $this->deletePetWithHttpInfo ($pet_id, $api_key); + return $response; + } + + + /** + * deletePetWithHttpInfo + * + * Deletes a pet + * + * @param int $pet_id Pet id to delete (required) + * @param string $api_key (optional) + * @return Array of null, HTTP status code, HTTP response headers (array of strings) + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function deletePetWithHttpInfo($pet_id, $api_key = null) { // verify the required parameter 'pet_id' is set @@ -608,7 +711,7 @@ class PetApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } @@ -618,21 +721,21 @@ class PetApi } // make the API Call - try - { - list($response, $httpHeader) = $this->apiClient->callApi( + try { + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams ); + return array(null, $statusCode, $httpHeader); + } catch (ApiException $e) { switch ($e->getCode()) { } throw $e; } - } /** @@ -646,7 +749,25 @@ class PetApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function uploadFile($pet_id, $additional_metadata=null, $file=null) + public function uploadFile($pet_id, $additional_metadata = null, $file = null) + { + list($response, $statusCode, $httpHeader) = $this->uploadFileWithHttpInfo ($pet_id, $additional_metadata, $file); + return $response; + } + + + /** + * uploadFileWithHttpInfo + * + * uploads an image + * + * @param int $pet_id ID of pet to update (required) + * @param string $additional_metadata Additional data to pass to server (optional) + * @param \SplFileObject $file file to upload (optional) + * @return Array of null, HTTP status code, HTTP response headers (array of strings) + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function uploadFileWithHttpInfo($pet_id, $additional_metadata = null, $file = null) { // verify the required parameter 'pet_id' is set @@ -702,7 +823,7 @@ class PetApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } @@ -712,21 +833,21 @@ class PetApi } // make the API Call - try - { - list($response, $httpHeader) = $this->apiClient->callApi( + try { + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams ); + return array(null, $statusCode, $httpHeader); + } catch (ApiException $e) { switch ($e->getCode()) { } throw $e; } - } } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php index d709330b056..4539aeeeab4 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php @@ -100,6 +100,21 @@ class StoreApi * @throws \Swagger\Client\ApiException on non-2xx response */ public function getInventory() + { + list($response, $statusCode, $httpHeader) = $this->getInventoryWithHttpInfo (); + return $response; + } + + + /** + * getInventoryWithHttpInfo + * + * Returns pet inventories by status + * + * @return Array of map[string,int], HTTP status code, HTTP response headers (array of strings) + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function getInventoryWithHttpInfo() { @@ -126,7 +141,7 @@ class StoreApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } @@ -138,19 +153,18 @@ class StoreApi // make the API Call - try - { - list($response, $httpHeader) = $this->apiClient->callApi( + try { + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams, 'map[string,int]' ); if (!$response) { - return null; + return array(null, $statusCode, $httpHeader); } - return $this->apiClient->getSerializer()->deserialize($response, 'map[string,int]', $httpHeader); + return array($this->apiClient->getSerializer()->deserialize($response, 'map[string,int]', $httpHeader), $statusCode, $httpHeader); } catch (ApiException $e) { switch ($e->getCode()) { @@ -162,9 +176,6 @@ class StoreApi throw $e; } - - return null; - } /** @@ -176,7 +187,23 @@ class StoreApi * @return \Swagger\Client\Model\Order * @throws \Swagger\Client\ApiException on non-2xx response */ - public function placeOrder($body=null) + public function placeOrder($body = null) + { + list($response, $statusCode, $httpHeader) = $this->placeOrderWithHttpInfo ($body); + return $response; + } + + + /** + * placeOrderWithHttpInfo + * + * Place an order for a pet + * + * @param \Swagger\Client\Model\Order $body order placed for purchasing the pet (optional) + * @return Array of \Swagger\Client\Model\Order, HTTP status code, HTTP response headers (array of strings) + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function placeOrderWithHttpInfo($body = null) { @@ -207,24 +234,23 @@ class StoreApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } // make the API Call - try - { - list($response, $httpHeader) = $this->apiClient->callApi( + try { + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams, '\Swagger\Client\Model\Order' ); if (!$response) { - return null; + return array(null, $statusCode, $httpHeader); } - return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Order', $httpHeader); + return array($this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Order', $httpHeader), $statusCode, $httpHeader); } catch (ApiException $e) { switch ($e->getCode()) { @@ -236,9 +262,6 @@ class StoreApi throw $e; } - - return null; - } /** @@ -251,6 +274,22 @@ class StoreApi * @throws \Swagger\Client\ApiException on non-2xx response */ public function getOrderById($order_id) + { + list($response, $statusCode, $httpHeader) = $this->getOrderByIdWithHttpInfo ($order_id); + return $response; + } + + + /** + * getOrderByIdWithHttpInfo + * + * Find purchase order by ID + * + * @param string $order_id ID of pet that needs to be fetched (required) + * @return Array of \Swagger\Client\Model\Order, HTTP status code, HTTP response headers (array of strings) + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function getOrderByIdWithHttpInfo($order_id) { // verify the required parameter 'order_id' is set @@ -288,24 +327,23 @@ class StoreApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } // make the API Call - try - { - list($response, $httpHeader) = $this->apiClient->callApi( + try { + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams, '\Swagger\Client\Model\Order' ); if (!$response) { - return null; + return array(null, $statusCode, $httpHeader); } - return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Order', $httpHeader); + return array($this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Order', $httpHeader), $statusCode, $httpHeader); } catch (ApiException $e) { switch ($e->getCode()) { @@ -317,9 +355,6 @@ class StoreApi throw $e; } - - return null; - } /** @@ -332,6 +367,22 @@ class StoreApi * @throws \Swagger\Client\ApiException on non-2xx response */ public function deleteOrder($order_id) + { + list($response, $statusCode, $httpHeader) = $this->deleteOrderWithHttpInfo ($order_id); + return $response; + } + + + /** + * deleteOrderWithHttpInfo + * + * Delete purchase order by ID + * + * @param string $order_id ID of the order that needs to be deleted (required) + * @return Array of null, HTTP status code, HTTP response headers (array of strings) + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function deleteOrderWithHttpInfo($order_id) { // verify the required parameter 'order_id' is set @@ -369,26 +420,26 @@ class StoreApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } // make the API Call - try - { - list($response, $httpHeader) = $this->apiClient->callApi( + try { + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams ); + return array(null, $statusCode, $httpHeader); + } catch (ApiException $e) { switch ($e->getCode()) { } throw $e; } - } } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php index 8ce6301a51e..f200ff51d2a 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php @@ -100,7 +100,23 @@ class UserApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function createUser($body=null) + public function createUser($body = null) + { + list($response, $statusCode, $httpHeader) = $this->createUserWithHttpInfo ($body); + return $response; + } + + + /** + * createUserWithHttpInfo + * + * Create user + * + * @param \Swagger\Client\Model\User $body Created user object (optional) + * @return Array of null, HTTP status code, HTTP response headers (array of strings) + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function createUserWithHttpInfo($body = null) { @@ -131,26 +147,26 @@ class UserApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } // make the API Call - try - { - list($response, $httpHeader) = $this->apiClient->callApi( + try { + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams ); + return array(null, $statusCode, $httpHeader); + } catch (ApiException $e) { switch ($e->getCode()) { } throw $e; } - } /** @@ -162,7 +178,23 @@ class UserApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function createUsersWithArrayInput($body=null) + public function createUsersWithArrayInput($body = null) + { + list($response, $statusCode, $httpHeader) = $this->createUsersWithArrayInputWithHttpInfo ($body); + return $response; + } + + + /** + * createUsersWithArrayInputWithHttpInfo + * + * Creates list of users with given input array + * + * @param \Swagger\Client\Model\User[] $body List of user object (optional) + * @return Array of null, HTTP status code, HTTP response headers (array of strings) + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function createUsersWithArrayInputWithHttpInfo($body = null) { @@ -193,26 +225,26 @@ class UserApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } // make the API Call - try - { - list($response, $httpHeader) = $this->apiClient->callApi( + try { + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams ); + return array(null, $statusCode, $httpHeader); + } catch (ApiException $e) { switch ($e->getCode()) { } throw $e; } - } /** @@ -224,7 +256,23 @@ class UserApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function createUsersWithListInput($body=null) + public function createUsersWithListInput($body = null) + { + list($response, $statusCode, $httpHeader) = $this->createUsersWithListInputWithHttpInfo ($body); + return $response; + } + + + /** + * createUsersWithListInputWithHttpInfo + * + * Creates list of users with given input array + * + * @param \Swagger\Client\Model\User[] $body List of user object (optional) + * @return Array of null, HTTP status code, HTTP response headers (array of strings) + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function createUsersWithListInputWithHttpInfo($body = null) { @@ -255,26 +303,26 @@ class UserApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } // make the API Call - try - { - list($response, $httpHeader) = $this->apiClient->callApi( + try { + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams ); + return array(null, $statusCode, $httpHeader); + } catch (ApiException $e) { switch ($e->getCode()) { } throw $e; } - } /** @@ -287,7 +335,24 @@ class UserApi * @return string * @throws \Swagger\Client\ApiException on non-2xx response */ - public function loginUser($username=null, $password=null) + public function loginUser($username = null, $password = null) + { + list($response, $statusCode, $httpHeader) = $this->loginUserWithHttpInfo ($username, $password); + return $response; + } + + + /** + * loginUserWithHttpInfo + * + * Logs user into the system + * + * @param string $username The user name for login (optional) + * @param string $password The password for login in clear text (optional) + * @return Array of string, HTTP status code, HTTP response headers (array of strings) + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function loginUserWithHttpInfo($username = null, $password = null) { @@ -320,24 +385,23 @@ class UserApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } // make the API Call - try - { - list($response, $httpHeader) = $this->apiClient->callApi( + try { + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams, 'string' ); if (!$response) { - return null; + return array(null, $statusCode, $httpHeader); } - return $this->apiClient->getSerializer()->deserialize($response, 'string', $httpHeader); + return array($this->apiClient->getSerializer()->deserialize($response, 'string', $httpHeader), $statusCode, $httpHeader); } catch (ApiException $e) { switch ($e->getCode()) { @@ -349,9 +413,6 @@ class UserApi throw $e; } - - return null; - } /** @@ -363,6 +424,21 @@ class UserApi * @throws \Swagger\Client\ApiException on non-2xx response */ public function logoutUser() + { + list($response, $statusCode, $httpHeader) = $this->logoutUserWithHttpInfo (); + return $response; + } + + + /** + * logoutUserWithHttpInfo + * + * Logs out current logged in user session + * + * @return Array of null, HTTP status code, HTTP response headers (array of strings) + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function logoutUserWithHttpInfo() { @@ -389,26 +465,26 @@ class UserApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } // make the API Call - try - { - list($response, $httpHeader) = $this->apiClient->callApi( + try { + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams ); + return array(null, $statusCode, $httpHeader); + } catch (ApiException $e) { switch ($e->getCode()) { } throw $e; } - } /** @@ -421,6 +497,22 @@ class UserApi * @throws \Swagger\Client\ApiException on non-2xx response */ public function getUserByName($username) + { + list($response, $statusCode, $httpHeader) = $this->getUserByNameWithHttpInfo ($username); + return $response; + } + + + /** + * getUserByNameWithHttpInfo + * + * Get user by user name + * + * @param string $username The name that needs to be fetched. Use user1 for testing. (required) + * @return Array of \Swagger\Client\Model\User, HTTP status code, HTTP response headers (array of strings) + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function getUserByNameWithHttpInfo($username) { // verify the required parameter 'username' is set @@ -458,24 +550,23 @@ class UserApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } // make the API Call - try - { - list($response, $httpHeader) = $this->apiClient->callApi( + try { + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams, '\Swagger\Client\Model\User' ); if (!$response) { - return null; + return array(null, $statusCode, $httpHeader); } - return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\User', $httpHeader); + return array($this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\User', $httpHeader), $statusCode, $httpHeader); } catch (ApiException $e) { switch ($e->getCode()) { @@ -487,9 +578,6 @@ class UserApi throw $e; } - - return null; - } /** @@ -502,7 +590,24 @@ class UserApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function updateUser($username, $body=null) + public function updateUser($username, $body = null) + { + list($response, $statusCode, $httpHeader) = $this->updateUserWithHttpInfo ($username, $body); + return $response; + } + + + /** + * updateUserWithHttpInfo + * + * Updated user + * + * @param string $username name that need to be deleted (required) + * @param \Swagger\Client\Model\User $body Updated user object (optional) + * @return Array of null, HTTP status code, HTTP response headers (array of strings) + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function updateUserWithHttpInfo($username, $body = null) { // verify the required parameter 'username' is set @@ -544,26 +649,26 @@ class UserApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } // make the API Call - try - { - list($response, $httpHeader) = $this->apiClient->callApi( + try { + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams ); + return array(null, $statusCode, $httpHeader); + } catch (ApiException $e) { switch ($e->getCode()) { } throw $e; } - } /** @@ -576,6 +681,22 @@ class UserApi * @throws \Swagger\Client\ApiException on non-2xx response */ public function deleteUser($username) + { + list($response, $statusCode, $httpHeader) = $this->deleteUserWithHttpInfo ($username); + return $response; + } + + + /** + * deleteUserWithHttpInfo + * + * Delete user + * + * @param string $username The name that needs to be deleted (required) + * @return Array of null, HTTP status code, HTTP response headers (array of strings) + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function deleteUserWithHttpInfo($username) { // verify the required parameter 'username' is set @@ -613,26 +734,26 @@ class UserApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } // make the API Call - try - { - list($response, $httpHeader) = $this->apiClient->callApi( + try { + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams ); + return array(null, $statusCode, $httpHeader); + } catch (ApiException $e) { switch ($e->getCode()) { } throw $e; } - } } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php b/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php index a0bb07273e4..8730a8c0601 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php @@ -131,7 +131,7 @@ class ApiClient * @throws \Swagger\Client\ApiException on a non 2xx response * @return mixed */ - public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams, $responseType=null) + public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams, $responseType = null) { $headers = array(); @@ -149,7 +149,7 @@ class ApiClient // form data if ($postData and in_array('Content-Type: application/x-www-form-urlencoded', $headers)) { $postData = http_build_query($postData); - } else if ((is_object($postData) or is_array($postData)) and !in_array('Content-Type: multipart/form-data', $headers)) { // json model + } elseif ((is_object($postData) or is_array($postData)) and !in_array('Content-Type: multipart/form-data', $headers)) { // json model $postData = json_encode($this->serializer->sanitizeForSerialization($postData)); } @@ -160,7 +160,7 @@ class ApiClient if ($this->config->getCurlTimeout() != 0) { curl_setopt($curl, CURLOPT_TIMEOUT, $this->config->getCurlTimeout()); } - // return the result on success, rather than just TRUE + // return the result on success, rather than just true curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); @@ -178,21 +178,21 @@ class ApiClient if ($method == self::$POST) { curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method == self::$HEAD) { + } elseif ($method == self::$HEAD) { curl_setopt($curl, CURLOPT_NOBODY, true); - } else if ($method == self::$OPTIONS) { + } elseif ($method == self::$OPTIONS) { curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "OPTIONS"); curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method == self::$PATCH) { + } elseif ($method == self::$PATCH) { curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH"); curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method == self::$PUT) { + } elseif ($method == self::$PUT) { curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method == self::$DELETE) { + } elseif ($method == self::$DELETE) { curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method != self::$GET) { + } elseif ($method != self::$GET) { throw new ApiException('Method ' . $method . ' is not recognized.'); } curl_setopt($curl, CURLOPT_URL, $url); @@ -216,7 +216,7 @@ class ApiClient // Make the request $response = curl_exec($curl); $http_header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE); - $http_header = substr($response, 0, $http_header_size); + $http_header = $this->http_parse_headers(substr($response, 0, $http_header_size)); $http_body = substr($response, $http_header_size); $response_info = curl_getinfo($curl); @@ -228,10 +228,10 @@ class ApiClient // Handle the response if ($response_info['http_code'] == 0) { throw new ApiException("API call to $url timed out: ".serialize($response_info), 0, null, null); - } else if ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) { + } elseif ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) { // return raw body if response is a file if ($responseType == '\SplFileObject') { - return array($http_body, $http_header); + return array($http_body, $response_info['http_code'], $http_header); } $data = json_decode($http_body); @@ -249,7 +249,7 @@ class ApiClient $response_info['http_code'], $http_header, $data ); } - return array($data, $http_header); + return array($data, $response_info['http_code'], $http_header); } /** @@ -287,4 +287,52 @@ class ApiClient return implode(',', $content_type); } } + + /** + * Return an array of HTTP response headers + * + * @param string $raw_headers A string of raw HTTP response headers + * + * @return string[] Array of HTTP response heaers + */ + protected function http_parse_headers($raw_headers) + { + // ref/credit: http://php.net/manual/en/function.http-parse-headers.php#112986 + $headers = array(); + $key = ''; // [+] + + foreach(explode("\n", $raw_headers) as $i => $h) + { + $h = explode(':', $h, 2); + + if (isset($h[1])) + { + if (!isset($headers[$h[0]])) + $headers[$h[0]] = trim($h[1]); + elseif (is_array($headers[$h[0]])) + { + // $tmp = array_merge($headers[$h[0]], array(trim($h[1]))); // [-] + // $headers[$h[0]] = $tmp; // [-] + $headers[$h[0]] = array_merge($headers[$h[0]], array(trim($h[1]))); // [+] + } + else + { + // $tmp = array_merge(array($headers[$h[0]]), array(trim($h[1]))); // [-] + // $headers[$h[0]] = $tmp; // [-] + $headers[$h[0]] = array_merge(array($headers[$h[0]]), array(trim($h[1]))); // [+] + } + + $key = $h[0]; // [+] + } + else // [+] + { // [+] + if (substr($h[0], 0, 1) == "\t") // [+] + $headers[$key] .= "\r\n\t".trim($h[0]); // [+] + elseif (!$key) // [+] + $headers[0] = trim($h[0]);trim($h[0]); // [+] + } // [+] + } + + return $headers; + } } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php b/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php index 0d281b9d1fa..cc023b61bd2 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php @@ -56,14 +56,14 @@ class ObjectSerializer { if (is_scalar($data) || null === $data) { $sanitized = $data; - } else if ($data instanceof \DateTime) { + } elseif ($data instanceof \DateTime) { $sanitized = $data->format(\DateTime::ISO8601); - } else if (is_array($data)) { + } elseif (is_array($data)) { foreach ($data as $property => $value) { $data[$property] = $this->sanitizeForSerialization($value); } $sanitized = $data; - } else if (is_object($data)) { + } elseif (is_object($data)) { $values = array(); foreach (array_keys($data::$swaggerTypes) as $property) { $getter = $data::$getters[$property]; @@ -198,7 +198,7 @@ class ObjectSerializer $deserialized = $data; } elseif ($class === '\SplFileObject') { // determine file name - if (preg_match('/Content-Disposition: inline; filename=[\'"]?([^\'"\s]+)[\'"]?$/i', $httpHeader, $match)) { + if (array_key_exists('Content-Disposition', $httpHeaders) && preg_match('/inline; filename=[\'"]?([^\'"\s]+)[\'"]?$/i', $httpHeader['Content-Disposition'], $match)) { $filename = Configuration::getDefaultConfiguration()->getTempFolderPath().$match[1]; } else { $filename = tempnam(Configuration::getDefaultConfiguration()->getTempFolderPath(), ''); diff --git a/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php b/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php index 58d5cd661f4..c81b07b38fd 100644 --- a/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php @@ -105,6 +105,25 @@ class PetApiTest extends \PHPUnit_Framework_TestCase $this->assertSame($response->getTags()[0]->getName(), 'test php tag'); } + // test getPetById with a Pet object (id 10005) + public function testGetPetByIdWithHttpInfo() + { + // initialize the API client without host + $pet_id = 10005; // ID of pet that needs to be fetched + $pet_api = new Swagger\Client\Api\PetAPI(); + $pet_api->getApiClient()->getConfig()->setApiKey('api_key', '111222333444555'); + // return Pet (model) + list($response, $status_code, $response_headers) = $pet_api->getPetByIdWithHttpInfo($pet_id); + $this->assertSame($response->getId(), $pet_id); + $this->assertSame($response->getName(), 'PHP Unit Test'); + $this->assertSame($response->getCategory()->getId(), $pet_id); + $this->assertSame($response->getCategory()->getName(), 'test php category'); + $this->assertSame($response->getTags()[0]->getId(), $pet_id); + $this->assertSame($response->getTags()[0]->getName(), 'test php tag'); + $this->assertSame($status_code, 200); + $this->assertSame($response_headers['Content-Type'], 'application/json'); + } + // test getPetByStatus and verify by the "id" of the response public function testFindPetByStatus() { @@ -149,7 +168,26 @@ class PetApiTest extends \PHPUnit_Framework_TestCase $this->assertSame($response->getName(), 'updatePet'); } - // test updatePet and verify by the "id" of the response + // test updatePetWithFormWithHttpInfo and verify by the "name" of the response + public function testUpdatePetWithFormWithHttpInfo() + { + // initialize the API client + $config = (new Swagger\Client\Configuration())->setHost('http://petstore.swagger.io/v2'); + $api_client = new Swagger\Client\ApiClient($config); + $pet_id = 10001; // ID of pet that needs to be fetched + $pet_api = new Swagger\Client\Api\PetAPI($api_client); + // update Pet (form) + list($update_response, $status_code, $http_headers) = $pet_api->updatePetWithFormWithHttpInfo($pet_id, 'update pet with form with http info'); + // return nothing (void) + $this->assertNull($update_response); + $this->assertSame($status_code, 200); + $this->assertSame($http_headers['Content-Type'], 'application/json'); + $response = $pet_api->getPetById($pet_id); + $this->assertSame($response->getId(), $pet_id); + $this->assertSame($response->getName(), 'update pet with form with http info'); + } + + // test updatePetWithForm and verify by the "name" and "status" of the response public function testUpdatePetWithForm() { // initialize the API client diff --git a/samples/client/petstore/qt5cpp/PetStore/PetApiTests.cpp b/samples/client/petstore/qt5cpp/PetStore/PetApiTests.cpp index 829fbe92640..e2d0ffb5d37 100644 --- a/samples/client/petstore/qt5cpp/PetStore/PetApiTests.cpp +++ b/samples/client/petstore/qt5cpp/PetStore/PetApiTests.cpp @@ -35,34 +35,12 @@ void PetApiTests::runTests() { delete tests; } -void PetApiTests::getPetByIdTest() { - SWGPetApi* api = getApi(); - - static QEventLoop loop; - QTimer timer; - timer.setInterval(1000); - timer.setSingleShot(true); - - auto validator = [](SWGPet* pet) { - QVERIFY(pet->getId() == 3); - loop.quit(); - }; - - connect(api, &SWGPetApi::getPetByIdSignal, this, validator); - connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit); - api->getPetById(3); - timer.start(); - loop.exec(); - QVERIFY2(timer.isActive(), "didn't finish within timeout"); - delete api; -} - void PetApiTests::findPetsByStatusTest() { SWGPetApi* api = getApi(); static QEventLoop loop; QTimer timer; - timer.setInterval(1000); + timer.setInterval(4000); timer.setSingleShot(true); auto validator = [](QList* pets) { diff --git a/samples/client/petstore/qt5cpp/PetStore/PetApiTests.h b/samples/client/petstore/qt5cpp/PetStore/PetApiTests.h index 9fdc939ab11..e219bb9a639 100644 --- a/samples/client/petstore/qt5cpp/PetStore/PetApiTests.h +++ b/samples/client/petstore/qt5cpp/PetStore/PetApiTests.h @@ -25,7 +25,6 @@ signals: bool success(); private slots: - void getPetByIdTest(); void findPetsByStatusTest(); void createAndGetPetTest(); void updatePetTest(); diff --git a/samples/client/petstore/qt5cpp/PetStore/PetStore.pro.user b/samples/client/petstore/qt5cpp/PetStore/PetStore.pro.user index a506d15a1d1..c8f28a4d2b1 100644 --- a/samples/client/petstore/qt5cpp/PetStore/PetStore.pro.user +++ b/samples/client/petstore/qt5cpp/PetStore/PetStore.pro.user @@ -1,10 +1,10 @@ - + EnvironmentId - {e1009bf2-3b8d-440a-a972-23a1fd0a9453} + {20946a4e-8558-4260-a72e-14a8108ad944} ProjectExplorer.Project.ActiveTarget @@ -58,14 +58,14 @@ ProjectExplorer.Project.Target.0 - Desktop Qt 5.4.1 clang 64bit - Desktop Qt 5.4.1 clang 64bit - qt.54.clang_64_kit + Desktop Qt 5.5.1 clang 64bit + Desktop Qt 5.5.1 clang 64bit + qt.55.clang_64_kit 0 0 0 - /Users/tony/dev/projects/swagger-api/swagger-codegen/samples/client/petstore/qt5cpp/build-PetStore-Desktop_Qt_5_4_1_clang_64bit-Debug + /Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/qt5cpp/build-PetStore-Desktop_Qt_5_5_1_clang_64bit-Debug true @@ -76,6 +76,7 @@ true false + false false @@ -125,7 +126,7 @@ true - /Users/tony/dev/projects/swagger-api/swagger-codegen/samples/client/petstore/qt5cpp/build-PetStore-Desktop_Qt_5_4_1_clang_64bit-Release + /Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/qt5cpp/build-PetStore-Desktop_Qt_5_5_1_clang_64bit-Release true @@ -136,6 +137,7 @@ true false + false false @@ -216,12 +218,10 @@ true false true - /usr/local/bin/valgrind + valgrind - 11 - 14 - 12 - 13 + 0 + 1 2 3 4 @@ -231,14 +231,16 @@ 8 9 10 - 0 - 1 + 11 + 12 + 13 + 14 2 PetStore - Qt4ProjectManager.Qt4RunConfiguration:/Users/tony/dev/projects/swagger-api/swagger-codegen/samples/client/petstore/qt5cpp/PetStore/PetStore.pro + Qt4ProjectManager.Qt4RunConfiguration:/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/qt5cpp/PetStore/PetStore.pro PetStore.pro false diff --git a/samples/client/petstore/qt5cpp/client/SWGHelpers.cpp b/samples/client/petstore/qt5cpp/client/SWGHelpers.cpp index 7f4d748c2dc..6b439996724 100644 --- a/samples/client/petstore/qt5cpp/client/SWGHelpers.cpp +++ b/samples/client/petstore/qt5cpp/client/SWGHelpers.cpp @@ -1,9 +1,9 @@ #include "SWGHelpers.h" #include "SWGModelFactory.h" #include "SWGObject.h" -#import -#import -#import +#include +#include +#include namespace Swagger { @@ -25,6 +25,14 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) { qint64 *val = static_cast(value); *val = obj.toVariant().toLongLong(); } + else if(QStringLiteral("float").compare(type) == 0) { + float *val = static_cast(value); + *val = obj.toDouble(); + } + else if(QStringLiteral("double").compare(type) == 0) { + double *val = static_cast(value); + *val = obj.toDouble(); + } else if (QStringLiteral("QString").compare(type) == 0) { QString **val = static_cast(value); @@ -86,6 +94,16 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) { setValue(&val, jval, QStringLiteral("bool"), QStringLiteral("")); output->append((void*)&val); } + else if(QStringLiteral("float").compare(complexType) == 0) { + float val; + setValue(&val, jval, QStringLiteral("float"), QStringLiteral("")); + output->append((void*)&val); + } + else if(QStringLiteral("double").compare(complexType) == 0) { + double val; + setValue(&val, jval, QStringLiteral("double"), QStringLiteral("")); + output->append((void*)&val); + } } } QList **val = static_cast**>(value); @@ -131,6 +149,14 @@ toJsonValue(QString name, void* value, QJsonObject* output, QString type) { bool* str = static_cast(value); output->insert(name, QJsonValue(*str)); } + else if(QStringLiteral("float").compare(type) == 0) { + float* str = static_cast(value); + output->insert(name, QJsonValue((double)*str)); + } + else if(QStringLiteral("double").compare(type) == 0) { + double* str = static_cast(value); + output->insert(name, QJsonValue(*str)); + } } void diff --git a/samples/client/petstore/qt5cpp/client/SWGPet.h b/samples/client/petstore/qt5cpp/client/SWGPet.h index e9cb4d08233..3f9320f1507 100644 --- a/samples/client/petstore/qt5cpp/client/SWGPet.h +++ b/samples/client/petstore/qt5cpp/client/SWGPet.h @@ -10,10 +10,10 @@ #include -#include "SWGTag.h" -#include -#include "SWGCategory.h" #include +#include "SWGCategory.h" +#include +#include "SWGTag.h" #include "SWGObject.h" diff --git a/samples/client/petstore/ruby/lib/petstore/api/pet_api.rb b/samples/client/petstore/ruby/lib/petstore/api/pet_api.rb index 887f86dd45c..acbd564db53 100644 --- a/samples/client/petstore/ruby/lib/petstore/api/pet_api.rb +++ b/samples/client/petstore/ruby/lib/petstore/api/pet_api.rb @@ -14,6 +14,16 @@ module Petstore # @option opts [Pet] :body Pet object that needs to be added to the store # @return [nil] def update_pet(opts = {}) + update_pet_with_http_info(opts) + return nil + end + + # Update an existing pet + # + # @param [Hash] opts the optional parameters + # @option opts [Pet] :body Pet object that needs to be added to the store + # @return [Array<(nil, Fixnum, Hash)>] nil, response status code and response headers + def update_pet_with_http_info(opts = {}) if Configuration.debugging Configuration.logger.debug "Calling API: PetApi#update_pet ..." end @@ -43,16 +53,16 @@ module Petstore auth_names = ['petstore_auth'] - @api_client.call_api(:PUT, path, + data, status_code, headers = @api_client.call_api(:PUT, path, :header_params => header_params, :query_params => query_params, :form_params => form_params, :body => post_body, :auth_names => auth_names) if Configuration.debugging - Configuration.logger.debug "API called: PetApi#update_pet" + Configuration.logger.debug "API called: PetApi#update_pet\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end - return nil + return data, status_code, headers end # Add a new pet to the store @@ -61,6 +71,16 @@ module Petstore # @option opts [Pet] :body Pet object that needs to be added to the store # @return [nil] def add_pet(opts = {}) + add_pet_with_http_info(opts) + return nil + end + + # Add a new pet to the store + # + # @param [Hash] opts the optional parameters + # @option opts [Pet] :body Pet object that needs to be added to the store + # @return [Array<(nil, Fixnum, Hash)>] nil, response status code and response headers + def add_pet_with_http_info(opts = {}) if Configuration.debugging Configuration.logger.debug "Calling API: PetApi#add_pet ..." end @@ -90,16 +110,16 @@ module Petstore auth_names = ['petstore_auth'] - @api_client.call_api(:POST, path, + data, status_code, headers = @api_client.call_api(:POST, path, :header_params => header_params, :query_params => query_params, :form_params => form_params, :body => post_body, :auth_names => auth_names) if Configuration.debugging - Configuration.logger.debug "API called: PetApi#add_pet" + Configuration.logger.debug "API called: PetApi#add_pet\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end - return nil + return data, status_code, headers end # Finds Pets by status @@ -108,6 +128,16 @@ module Petstore # @option opts [Array] :status Status values that need to be considered for filter # @return [Array] def find_pets_by_status(opts = {}) + data, status_code, headers = find_pets_by_status_with_http_info(opts) + return data + end + + # Finds Pets by status + # Multiple status values can be provided with comma seperated strings + # @param [Hash] opts the optional parameters + # @option opts [Array] :status Status values that need to be considered for filter + # @return [Array<(Array, Fixnum, Hash)>] Array data, response status code and response headers + def find_pets_by_status_with_http_info(opts = {}) if Configuration.debugging Configuration.logger.debug "Calling API: PetApi#find_pets_by_status ..." end @@ -138,7 +168,7 @@ module Petstore auth_names = ['petstore_auth'] - result = @api_client.call_api(:GET, path, + data, status_code, headers = @api_client.call_api(:GET, path, :header_params => header_params, :query_params => query_params, :form_params => form_params, @@ -146,9 +176,9 @@ module Petstore :auth_names => auth_names, :return_type => 'Array') if Configuration.debugging - Configuration.logger.debug "API called: PetApi#find_pets_by_status. Result: #{result.inspect}" + Configuration.logger.debug "API called: PetApi#find_pets_by_status\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end - return result + return data, status_code, headers end # Finds Pets by tags @@ -157,6 +187,16 @@ module Petstore # @option opts [Array] :tags Tags to filter by # @return [Array] def find_pets_by_tags(opts = {}) + data, status_code, headers = find_pets_by_tags_with_http_info(opts) + return data + end + + # Finds Pets by tags + # Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. + # @param [Hash] opts the optional parameters + # @option opts [Array] :tags Tags to filter by + # @return [Array<(Array, Fixnum, Hash)>] Array data, response status code and response headers + def find_pets_by_tags_with_http_info(opts = {}) if Configuration.debugging Configuration.logger.debug "Calling API: PetApi#find_pets_by_tags ..." end @@ -187,7 +227,7 @@ module Petstore auth_names = ['petstore_auth'] - result = @api_client.call_api(:GET, path, + data, status_code, headers = @api_client.call_api(:GET, path, :header_params => header_params, :query_params => query_params, :form_params => form_params, @@ -195,9 +235,9 @@ module Petstore :auth_names => auth_names, :return_type => 'Array') if Configuration.debugging - Configuration.logger.debug "API called: PetApi#find_pets_by_tags. Result: #{result.inspect}" + Configuration.logger.debug "API called: PetApi#find_pets_by_tags\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end - return result + return data, status_code, headers end # Find pet by ID @@ -206,6 +246,16 @@ module Petstore # @param [Hash] opts the optional parameters # @return [Pet] def get_pet_by_id(pet_id, opts = {}) + data, status_code, headers = get_pet_by_id_with_http_info(pet_id, opts) + return data + end + + # Find pet by ID + # Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions + # @param pet_id ID of pet that needs to be fetched + # @param [Hash] opts the optional parameters + # @return [Array<(Pet, Fixnum, Hash)>] Pet data, response status code and response headers + def get_pet_by_id_with_http_info(pet_id, opts = {}) if Configuration.debugging Configuration.logger.debug "Calling API: PetApi#get_pet_by_id ..." end @@ -238,7 +288,7 @@ module Petstore auth_names = ['api_key'] - result = @api_client.call_api(:GET, path, + data, status_code, headers = @api_client.call_api(:GET, path, :header_params => header_params, :query_params => query_params, :form_params => form_params, @@ -246,9 +296,9 @@ module Petstore :auth_names => auth_names, :return_type => 'Pet') if Configuration.debugging - Configuration.logger.debug "API called: PetApi#get_pet_by_id. Result: #{result.inspect}" + Configuration.logger.debug "API called: PetApi#get_pet_by_id\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end - return result + return data, status_code, headers end # Updates a pet in the store with form data @@ -259,6 +309,18 @@ module Petstore # @option opts [String] :status Updated status of the pet # @return [nil] def update_pet_with_form(pet_id, opts = {}) + update_pet_with_form_with_http_info(pet_id, opts) + return nil + end + + # Updates a pet in the store with form data + # + # @param pet_id ID of pet that needs to be updated + # @param [Hash] opts the optional parameters + # @option opts [String] :name Updated name of the pet + # @option opts [String] :status Updated status of the pet + # @return [Array<(nil, Fixnum, Hash)>] nil, response status code and response headers + def update_pet_with_form_with_http_info(pet_id, opts = {}) if Configuration.debugging Configuration.logger.debug "Calling API: PetApi#update_pet_with_form ..." end @@ -293,16 +355,16 @@ module Petstore auth_names = ['petstore_auth'] - @api_client.call_api(:POST, path, + data, status_code, headers = @api_client.call_api(:POST, path, :header_params => header_params, :query_params => query_params, :form_params => form_params, :body => post_body, :auth_names => auth_names) if Configuration.debugging - Configuration.logger.debug "API called: PetApi#update_pet_with_form" + Configuration.logger.debug "API called: PetApi#update_pet_with_form\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end - return nil + return data, status_code, headers end # Deletes a pet @@ -312,6 +374,17 @@ module Petstore # @option opts [String] :api_key # @return [nil] def delete_pet(pet_id, opts = {}) + delete_pet_with_http_info(pet_id, opts) + return nil + end + + # Deletes a pet + # + # @param pet_id Pet id to delete + # @param [Hash] opts the optional parameters + # @option opts [String] :api_key + # @return [Array<(nil, Fixnum, Hash)>] nil, response status code and response headers + def delete_pet_with_http_info(pet_id, opts = {}) if Configuration.debugging Configuration.logger.debug "Calling API: PetApi#delete_pet ..." end @@ -345,16 +418,16 @@ module Petstore auth_names = ['petstore_auth'] - @api_client.call_api(:DELETE, path, + data, status_code, headers = @api_client.call_api(:DELETE, path, :header_params => header_params, :query_params => query_params, :form_params => form_params, :body => post_body, :auth_names => auth_names) if Configuration.debugging - Configuration.logger.debug "API called: PetApi#delete_pet" + Configuration.logger.debug "API called: PetApi#delete_pet\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end - return nil + return data, status_code, headers end # uploads an image @@ -365,6 +438,18 @@ module Petstore # @option opts [File] :file file to upload # @return [nil] def upload_file(pet_id, opts = {}) + upload_file_with_http_info(pet_id, opts) + return nil + end + + # uploads an image + # + # @param pet_id ID of pet to update + # @param [Hash] opts the optional parameters + # @option opts [String] :additional_metadata Additional data to pass to server + # @option opts [File] :file file to upload + # @return [Array<(nil, Fixnum, Hash)>] nil, response status code and response headers + def upload_file_with_http_info(pet_id, opts = {}) if Configuration.debugging Configuration.logger.debug "Calling API: PetApi#upload_file ..." end @@ -399,16 +484,16 @@ module Petstore auth_names = ['petstore_auth'] - @api_client.call_api(:POST, path, + data, status_code, headers = @api_client.call_api(:POST, path, :header_params => header_params, :query_params => query_params, :form_params => form_params, :body => post_body, :auth_names => auth_names) if Configuration.debugging - Configuration.logger.debug "API called: PetApi#upload_file" + Configuration.logger.debug "API called: PetApi#upload_file\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end - return nil + return data, status_code, headers end end end diff --git a/samples/client/petstore/ruby/lib/petstore/api/store_api.rb b/samples/client/petstore/ruby/lib/petstore/api/store_api.rb index 235ff1c4106..548973eefd3 100644 --- a/samples/client/petstore/ruby/lib/petstore/api/store_api.rb +++ b/samples/client/petstore/ruby/lib/petstore/api/store_api.rb @@ -13,6 +13,15 @@ module Petstore # @param [Hash] opts the optional parameters # @return [Hash] def get_inventory(opts = {}) + data, status_code, headers = get_inventory_with_http_info(opts) + return data + end + + # Returns pet inventories by status + # Returns a map of status codes to quantities + # @param [Hash] opts the optional parameters + # @return [Array<(Hash, Fixnum, Hash)>] Hash data, response status code and response headers + def get_inventory_with_http_info(opts = {}) if Configuration.debugging Configuration.logger.debug "Calling API: StoreApi#get_inventory ..." end @@ -42,7 +51,7 @@ module Petstore auth_names = ['api_key'] - result = @api_client.call_api(:GET, path, + data, status_code, headers = @api_client.call_api(:GET, path, :header_params => header_params, :query_params => query_params, :form_params => form_params, @@ -50,9 +59,9 @@ module Petstore :auth_names => auth_names, :return_type => 'Hash') if Configuration.debugging - Configuration.logger.debug "API called: StoreApi#get_inventory. Result: #{result.inspect}" + Configuration.logger.debug "API called: StoreApi#get_inventory\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end - return result + return data, status_code, headers end # Place an order for a pet @@ -61,6 +70,16 @@ module Petstore # @option opts [Order] :body order placed for purchasing the pet # @return [Order] def place_order(opts = {}) + data, status_code, headers = place_order_with_http_info(opts) + return data + end + + # Place an order for a pet + # + # @param [Hash] opts the optional parameters + # @option opts [Order] :body order placed for purchasing the pet + # @return [Array<(Order, Fixnum, Hash)>] Order data, response status code and response headers + def place_order_with_http_info(opts = {}) if Configuration.debugging Configuration.logger.debug "Calling API: StoreApi#place_order ..." end @@ -90,7 +109,7 @@ module Petstore auth_names = [] - result = @api_client.call_api(:POST, path, + data, status_code, headers = @api_client.call_api(:POST, path, :header_params => header_params, :query_params => query_params, :form_params => form_params, @@ -98,9 +117,9 @@ module Petstore :auth_names => auth_names, :return_type => 'Order') if Configuration.debugging - Configuration.logger.debug "API called: StoreApi#place_order. Result: #{result.inspect}" + Configuration.logger.debug "API called: StoreApi#place_order\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end - return result + return data, status_code, headers end # Find purchase order by ID @@ -109,6 +128,16 @@ module Petstore # @param [Hash] opts the optional parameters # @return [Order] def get_order_by_id(order_id, opts = {}) + data, status_code, headers = get_order_by_id_with_http_info(order_id, opts) + return data + end + + # Find purchase order by ID + # For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + # @param order_id ID of pet that needs to be fetched + # @param [Hash] opts the optional parameters + # @return [Array<(Order, Fixnum, Hash)>] Order data, response status code and response headers + def get_order_by_id_with_http_info(order_id, opts = {}) if Configuration.debugging Configuration.logger.debug "Calling API: StoreApi#get_order_by_id ..." end @@ -141,7 +170,7 @@ module Petstore auth_names = [] - result = @api_client.call_api(:GET, path, + data, status_code, headers = @api_client.call_api(:GET, path, :header_params => header_params, :query_params => query_params, :form_params => form_params, @@ -149,9 +178,9 @@ module Petstore :auth_names => auth_names, :return_type => 'Order') if Configuration.debugging - Configuration.logger.debug "API called: StoreApi#get_order_by_id. Result: #{result.inspect}" + Configuration.logger.debug "API called: StoreApi#get_order_by_id\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end - return result + return data, status_code, headers end # Delete purchase order by ID @@ -160,6 +189,16 @@ module Petstore # @param [Hash] opts the optional parameters # @return [nil] def delete_order(order_id, opts = {}) + delete_order_with_http_info(order_id, opts) + return nil + end + + # Delete purchase order by ID + # For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + # @param order_id ID of the order that needs to be deleted + # @param [Hash] opts the optional parameters + # @return [Array<(nil, Fixnum, Hash)>] nil, response status code and response headers + def delete_order_with_http_info(order_id, opts = {}) if Configuration.debugging Configuration.logger.debug "Calling API: StoreApi#delete_order ..." end @@ -192,16 +231,16 @@ module Petstore auth_names = [] - @api_client.call_api(:DELETE, path, + data, status_code, headers = @api_client.call_api(:DELETE, path, :header_params => header_params, :query_params => query_params, :form_params => form_params, :body => post_body, :auth_names => auth_names) if Configuration.debugging - Configuration.logger.debug "API called: StoreApi#delete_order" + Configuration.logger.debug "API called: StoreApi#delete_order\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end - return nil + return data, status_code, headers end end end diff --git a/samples/client/petstore/ruby/lib/petstore/api/user_api.rb b/samples/client/petstore/ruby/lib/petstore/api/user_api.rb index 7f546330f3a..35623175f35 100644 --- a/samples/client/petstore/ruby/lib/petstore/api/user_api.rb +++ b/samples/client/petstore/ruby/lib/petstore/api/user_api.rb @@ -14,6 +14,16 @@ module Petstore # @option opts [User] :body Created user object # @return [nil] def create_user(opts = {}) + create_user_with_http_info(opts) + return nil + end + + # Create user + # This can only be done by the logged in user. + # @param [Hash] opts the optional parameters + # @option opts [User] :body Created user object + # @return [Array<(nil, Fixnum, Hash)>] nil, response status code and response headers + def create_user_with_http_info(opts = {}) if Configuration.debugging Configuration.logger.debug "Calling API: UserApi#create_user ..." end @@ -43,16 +53,16 @@ module Petstore auth_names = [] - @api_client.call_api(:POST, path, + data, status_code, headers = @api_client.call_api(:POST, path, :header_params => header_params, :query_params => query_params, :form_params => form_params, :body => post_body, :auth_names => auth_names) if Configuration.debugging - Configuration.logger.debug "API called: UserApi#create_user" + Configuration.logger.debug "API called: UserApi#create_user\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end - return nil + return data, status_code, headers end # Creates list of users with given input array @@ -61,6 +71,16 @@ module Petstore # @option opts [Array] :body List of user object # @return [nil] def create_users_with_array_input(opts = {}) + create_users_with_array_input_with_http_info(opts) + return nil + end + + # Creates list of users with given input array + # + # @param [Hash] opts the optional parameters + # @option opts [Array] :body List of user object + # @return [Array<(nil, Fixnum, Hash)>] nil, response status code and response headers + def create_users_with_array_input_with_http_info(opts = {}) if Configuration.debugging Configuration.logger.debug "Calling API: UserApi#create_users_with_array_input ..." end @@ -90,16 +110,16 @@ module Petstore auth_names = [] - @api_client.call_api(:POST, path, + data, status_code, headers = @api_client.call_api(:POST, path, :header_params => header_params, :query_params => query_params, :form_params => form_params, :body => post_body, :auth_names => auth_names) if Configuration.debugging - Configuration.logger.debug "API called: UserApi#create_users_with_array_input" + Configuration.logger.debug "API called: UserApi#create_users_with_array_input\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end - return nil + return data, status_code, headers end # Creates list of users with given input array @@ -108,6 +128,16 @@ module Petstore # @option opts [Array] :body List of user object # @return [nil] def create_users_with_list_input(opts = {}) + create_users_with_list_input_with_http_info(opts) + return nil + end + + # Creates list of users with given input array + # + # @param [Hash] opts the optional parameters + # @option opts [Array] :body List of user object + # @return [Array<(nil, Fixnum, Hash)>] nil, response status code and response headers + def create_users_with_list_input_with_http_info(opts = {}) if Configuration.debugging Configuration.logger.debug "Calling API: UserApi#create_users_with_list_input ..." end @@ -137,16 +167,16 @@ module Petstore auth_names = [] - @api_client.call_api(:POST, path, + data, status_code, headers = @api_client.call_api(:POST, path, :header_params => header_params, :query_params => query_params, :form_params => form_params, :body => post_body, :auth_names => auth_names) if Configuration.debugging - Configuration.logger.debug "API called: UserApi#create_users_with_list_input" + Configuration.logger.debug "API called: UserApi#create_users_with_list_input\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end - return nil + return data, status_code, headers end # Logs user into the system @@ -156,6 +186,17 @@ module Petstore # @option opts [String] :password The password for login in clear text # @return [String] def login_user(opts = {}) + data, status_code, headers = login_user_with_http_info(opts) + return data + end + + # Logs user into the system + # + # @param [Hash] opts the optional parameters + # @option opts [String] :username The user name for login + # @option opts [String] :password The password for login in clear text + # @return [Array<(String, Fixnum, Hash)>] String data, response status code and response headers + def login_user_with_http_info(opts = {}) if Configuration.debugging Configuration.logger.debug "Calling API: UserApi#login_user ..." end @@ -187,7 +228,7 @@ module Petstore auth_names = [] - result = @api_client.call_api(:GET, path, + data, status_code, headers = @api_client.call_api(:GET, path, :header_params => header_params, :query_params => query_params, :form_params => form_params, @@ -195,9 +236,9 @@ module Petstore :auth_names => auth_names, :return_type => 'String') if Configuration.debugging - Configuration.logger.debug "API called: UserApi#login_user. Result: #{result.inspect}" + Configuration.logger.debug "API called: UserApi#login_user\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end - return result + return data, status_code, headers end # Logs out current logged in user session @@ -205,6 +246,15 @@ module Petstore # @param [Hash] opts the optional parameters # @return [nil] def logout_user(opts = {}) + logout_user_with_http_info(opts) + return nil + end + + # Logs out current logged in user session + # + # @param [Hash] opts the optional parameters + # @return [Array<(nil, Fixnum, Hash)>] nil, response status code and response headers + def logout_user_with_http_info(opts = {}) if Configuration.debugging Configuration.logger.debug "Calling API: UserApi#logout_user ..." end @@ -234,16 +284,16 @@ module Petstore auth_names = [] - @api_client.call_api(:GET, path, + data, status_code, headers = @api_client.call_api(:GET, path, :header_params => header_params, :query_params => query_params, :form_params => form_params, :body => post_body, :auth_names => auth_names) if Configuration.debugging - Configuration.logger.debug "API called: UserApi#logout_user" + Configuration.logger.debug "API called: UserApi#logout_user\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end - return nil + return data, status_code, headers end # Get user by user name @@ -252,6 +302,16 @@ module Petstore # @param [Hash] opts the optional parameters # @return [User] def get_user_by_name(username, opts = {}) + data, status_code, headers = get_user_by_name_with_http_info(username, opts) + return data + end + + # Get user by user name + # + # @param username The name that needs to be fetched. Use user1 for testing. + # @param [Hash] opts the optional parameters + # @return [Array<(User, Fixnum, Hash)>] User data, response status code and response headers + def get_user_by_name_with_http_info(username, opts = {}) if Configuration.debugging Configuration.logger.debug "Calling API: UserApi#get_user_by_name ..." end @@ -284,7 +344,7 @@ module Petstore auth_names = [] - result = @api_client.call_api(:GET, path, + data, status_code, headers = @api_client.call_api(:GET, path, :header_params => header_params, :query_params => query_params, :form_params => form_params, @@ -292,9 +352,9 @@ module Petstore :auth_names => auth_names, :return_type => 'User') if Configuration.debugging - Configuration.logger.debug "API called: UserApi#get_user_by_name. Result: #{result.inspect}" + Configuration.logger.debug "API called: UserApi#get_user_by_name\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end - return result + return data, status_code, headers end # Updated user @@ -304,6 +364,17 @@ module Petstore # @option opts [User] :body Updated user object # @return [nil] def update_user(username, opts = {}) + update_user_with_http_info(username, opts) + return nil + end + + # Updated user + # This can only be done by the logged in user. + # @param username name that need to be deleted + # @param [Hash] opts the optional parameters + # @option opts [User] :body Updated user object + # @return [Array<(nil, Fixnum, Hash)>] nil, response status code and response headers + def update_user_with_http_info(username, opts = {}) if Configuration.debugging Configuration.logger.debug "Calling API: UserApi#update_user ..." end @@ -336,16 +407,16 @@ module Petstore auth_names = [] - @api_client.call_api(:PUT, path, + data, status_code, headers = @api_client.call_api(:PUT, path, :header_params => header_params, :query_params => query_params, :form_params => form_params, :body => post_body, :auth_names => auth_names) if Configuration.debugging - Configuration.logger.debug "API called: UserApi#update_user" + Configuration.logger.debug "API called: UserApi#update_user\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end - return nil + return data, status_code, headers end # Delete user @@ -354,6 +425,16 @@ module Petstore # @param [Hash] opts the optional parameters # @return [nil] def delete_user(username, opts = {}) + delete_user_with_http_info(username, opts) + return nil + end + + # Delete user + # This can only be done by the logged in user. + # @param username The name that needs to be deleted + # @param [Hash] opts the optional parameters + # @return [Array<(nil, Fixnum, Hash)>] nil, response status code and response headers + def delete_user_with_http_info(username, opts = {}) if Configuration.debugging Configuration.logger.debug "Calling API: UserApi#delete_user ..." end @@ -386,16 +467,16 @@ module Petstore auth_names = [] - @api_client.call_api(:DELETE, path, + data, status_code, headers = @api_client.call_api(:DELETE, path, :header_params => header_params, :query_params => query_params, :form_params => form_params, :body => post_body, :auth_names => auth_names) if Configuration.debugging - Configuration.logger.debug "API called: UserApi#delete_user" + Configuration.logger.debug "API called: UserApi#delete_user\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end - return nil + return data, status_code, headers end end end diff --git a/samples/client/petstore/ruby/lib/petstore/api_client.rb b/samples/client/petstore/ruby/lib/petstore/api_client.rb index 92a61bac4a6..412fb7946ad 100644 --- a/samples/client/petstore/ruby/lib/petstore/api_client.rb +++ b/samples/client/petstore/ruby/lib/petstore/api_client.rb @@ -15,9 +15,6 @@ module Petstore # @return [Hash] attr_accessor :default_headers - # Stores the HTTP response from the last API call using this API client. - attr_accessor :last_response - def initialize(host = nil) @host = host || Configuration.base_url @format = 'json' @@ -28,13 +25,14 @@ module Petstore } end + # Call an API with given options. + # + # @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements: + # the data deserialized from response body (could be nil), response status code and response headers. def call_api(http_method, path, opts = {}) request = build_request(http_method, path, opts) response = request.run - # record as last response - @last_response = response - if Configuration.debugging Configuration.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n" end @@ -47,10 +45,11 @@ module Petstore end if opts[:return_type] - deserialize(response, opts[:return_type]) + data = deserialize(response, opts[:return_type]) else - nil + data = nil end + return data, response.code, response.headers end def build_request(http_method, path, opts = {}) diff --git a/samples/client/petstore/ruby/spec/pet_spec.rb b/samples/client/petstore/ruby/spec/pet_spec.rb index 612fc536147..9426d2024b9 100644 --- a/samples/client/petstore/ruby/spec/pet_spec.rb +++ b/samples/client/petstore/ruby/spec/pet_spec.rb @@ -50,6 +50,17 @@ describe "Pet" do pet.category.name.should == "category test" end + it "should fetch a pet object with http info" do + pet, status_code, headers = @pet_api.get_pet_by_id_with_http_info(10002) + status_code.should == 200 + headers['Content-Type'].should == 'application/json' + pet.should be_a(Petstore::Pet) + pet.id.should == 10002 + pet.name.should == "RUBY UNIT TESTING" + pet.tags[0].name.should == "tag test" + pet.category.name.should == "category test" + end + it "should not find a pet that does not exist" do begin @pet_api.get_pet_by_id(-10002)