From fcd0b31d7d3b2d7a7a185481676a58942404a691 Mon Sep 17 00:00:00 2001 From: wing328 Date: Fri, 26 Jun 2015 17:06:30 +0800 Subject: [PATCH 1/9] add file response for php --- .../codegen/languages/PhpClientCodegen.java | 2 +- .../src/main/resources/php/ApiClient.mustache | 7 ++- .../resources/php/ObjectSerializer.mustache | 28 ++++++++++-- .../src/main/resources/php/api.mustache | 6 +-- .../main/resources/php/configuration.mustache | 14 ++++++ .../src/main/resources/php/model.mustache | 4 +- .../php/SwaggerClient-php/lib/Api/PetApi.php | 36 +++++++-------- .../SwaggerClient-php/lib/Api/StoreApi.php | 20 ++++----- .../php/SwaggerClient-php/lib/Api/UserApi.php | 24 +++++----- .../php/SwaggerClient-php/lib/ApiClient.php | 7 ++- .../SwaggerClient-php/lib/Configuration.php | 14 ++++++ .../SwaggerClient-php/lib/Model/Category.php | 4 +- .../php/SwaggerClient-php/lib/Model/Order.php | 4 +- .../php/SwaggerClient-php/lib/Model/Pet.php | 4 +- .../php/SwaggerClient-php/lib/Model/Tag.php | 4 +- .../php/SwaggerClient-php/lib/Model/User.php | 4 +- .../lib/ObjectSerializer.php | 28 ++++++++++-- .../php-coveralls/build/config/apigen.neon | 5 --- .../php-coveralls/build/config/phpcs.xml | 31 ------------- .../php-coveralls/build/config/phpmd.xml | 45 ------------------- .../satooshi/php-coveralls/travis/empty | 0 samples/client/petstore/php/test.php | 16 +++---- 22 files changed, 154 insertions(+), 153 deletions(-) delete mode 100644 samples/client/petstore/php/SwaggerClient/vendor/satooshi/php-coveralls/build/config/apigen.neon delete mode 100644 samples/client/petstore/php/SwaggerClient/vendor/satooshi/php-coveralls/build/config/phpcs.xml delete mode 100644 samples/client/petstore/php/SwaggerClient/vendor/satooshi/php-coveralls/build/config/phpmd.xml delete mode 100644 samples/client/petstore/php/SwaggerClient/vendor/satooshi/php-coveralls/travis/empty diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java index e2ddba4bf345..c6e6d65596c3 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java @@ -79,7 +79,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig { typeMapping.put("boolean", "bool"); typeMapping.put("date", "\\DateTime"); typeMapping.put("datetime", "\\DateTime"); - typeMapping.put("file", "string"); + typeMapping.put("file", "\\SplFileObject"); typeMapping.put("map", "map"); typeMapping.put("array", "array"); typeMapping.put("list", "array"); diff --git a/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache index 2862a0e0538e..3a4f8dfc8be3 100644 --- a/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache @@ -90,7 +90,7 @@ class ApiClient { * @throws \{{invokerPackage}}\ApiException on a non 2xx response * @return mixed */ - public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams) { + public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams, $responseType=null) { $headers = array(); @@ -174,6 +174,11 @@ class ApiClient { 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 ) { + // return raw body if response is a file + if ($responseType == 'SplFileObject') { + return array($http_body, $http_header); + } + $data = json_decode($http_body); if (json_last_error() > 0) { // if response is a string $data = $http_body; diff --git a/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache b/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache index 56a61e97c916..26999668b9e9 100644 --- a/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache +++ b/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache @@ -79,7 +79,11 @@ class ObjectSerializer { * @return string the form string */ public function toFormValue($value) { - return $this->toString($value); + if ($value instanceof SplFileObject) { + return $value->getRealPath(); + } else { + return $this->toString($value); + } } /** @@ -104,7 +108,7 @@ class ObjectSerializer { * @param string $class class name is passed as a string * @return object an instance of $class */ - public function deserialize($data, $class) { + public function deserialize($data, $class, $httpHeader=null) { if (null === $data) { $deserialized = null; } elseif (substr($class, 0, 4) == 'map[') { # for associative array e.g. map[string,int] @@ -129,6 +133,24 @@ class ObjectSerializer { } elseif (in_array($class, array('string', 'int', 'float', 'double', 'bool', 'object'))) { settype($data, $class); $deserialized = $data; + } elseif ($class === 'SplFileObject') { + # determine temp folder path + if (!isset(Configuration::$tempFolderPath) || '' === Configuration::$tempFolderPath) { + $tmpFolderPath = sys_get_temp_dir(); + } else { + $tmpFolderPath = Configuration::tempFolderPath; + } + + # determine file name + if (preg_match('/Content-Disposition: inline; filename=(.*)/i', $httpHeader, $match)) { + $filename = $tmpFolderPath.$match[1]; + } else { + $filename = tempnam($tmpFolderPath, ''); + } + $deserialized = new \SplFileObject($filename, "w"); + $byte_written = $deserialized->fwrite($data); + error_log("[INFO] Written $byte_written to $filename. Please move the file to a proper folder for further processing and delete the temp afterwards", 3, Configuration::$debug_file); + } else { $instance = new $class(); foreach ($instance::$swaggerTypes as $property => $type) { @@ -148,4 +170,4 @@ class ObjectSerializer { return $deserialized; } -} \ No newline at end of file +} diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index fb0a6f99e7ca..367ba037d598 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -134,13 +134,13 @@ class {{classname}} { {{/authMethods}} // make the API Call try { - $response = $this->apiClient->callAPI($resourcePath, $method, + $response = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, - $headerParams); + $headerParams{{#returnType}}, '{{returnType}}'{{/returnType}}); } catch (ApiException $e) { switch ($e->getCode()) { {{#responses}}{{#dataType}} case {{code}}: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '{{dataType}}'); + $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '{{dataType}}', $httpHeader); $e->setResponseObject($data); break;{{/dataType}}{{/responses}} } diff --git a/modules/swagger-codegen/src/main/resources/php/configuration.mustache b/modules/swagger-codegen/src/main/resources/php/configuration.mustache index b85ad289418c..687470669730 100644 --- a/modules/swagger-codegen/src/main/resources/php/configuration.mustache +++ b/modules/swagger-codegen/src/main/resources/php/configuration.mustache @@ -263,4 +263,18 @@ class Configuration { public static function setDefaultConfiguration(Configuration $config) { self::$defaultConfiguration = $config; } + + /* + * return the report for debuggin + */ + public static function toDebugReport() { + $report = "PHP SDK ({{invokerPackage}}) Debug Report:\n"; + $report .= " OS: ".php_uname()."\n"; + $report .= " PHP Version: ".phpversion()."\n"; + $report .= " Swagger Spec Version: {{version}}\n"; + $report .= " SDK Package Version: {{version}}\n"; + + return $report; + } + } diff --git a/modules/swagger-codegen/src/main/resources/php/model.mustache b/modules/swagger-codegen/src/main/resources/php/model.mustache index 35795bf8c0b7..1d241529538f 100644 --- a/modules/swagger-codegen/src/main/resources/php/model.mustache +++ b/modules/swagger-codegen/src/main/resources/php/model.mustache @@ -100,9 +100,9 @@ class {{classname}} implements ArrayAccess { public function __toString() { if (defined('JSON_PRETTY_PRINT')) { - return json_encode($this, JSON_PRETTY_PRINT); + return json_encode(get_object_vars($this), JSON_PRETTY_PRINT); } else { - return json_encode($this); + return json_encode(get_object_vars($this)); } } } 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 b6766d8d13f2..afbe1991690e 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php @@ -110,7 +110,7 @@ class PetApi { // make the API Call try { - $response = $this->apiClient->callAPI($resourcePath, $method, + $response = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams); } catch (ApiException $e) { @@ -171,7 +171,7 @@ class PetApi { // make the API Call try { - $response = $this->apiClient->callAPI($resourcePath, $method, + $response = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams); } catch (ApiException $e) { @@ -231,13 +231,13 @@ class PetApi { // make the API Call try { - $response = $this->apiClient->callAPI($resourcePath, $method, + $response = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, - $headerParams); + $headerParams, '\Swagger\Client\Model\Pet[]'); } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Pet[]'); + $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Pet[]', $httpHeader); $e->setResponseObject($data); break; } @@ -302,13 +302,13 @@ class PetApi { // make the API Call try { - $response = $this->apiClient->callAPI($resourcePath, $method, + $response = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, - $headerParams); + $headerParams, '\Swagger\Client\Model\Pet[]'); } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Pet[]'); + $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Pet[]', $httpHeader); $e->setResponseObject($data); break; } @@ -375,9 +375,6 @@ class PetApi { $httpBody = $formParams; } - //TODO support oauth - - $apiKey = $this->apiClient->getApiKeyWithPrefix('api_key'); if (isset($apiKey)) { $headerParams['api_key'] = $apiKey; @@ -385,15 +382,18 @@ class PetApi { + + //TODO support oauth + // make the API Call try { - $response = $this->apiClient->callAPI($resourcePath, $method, + $response = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, - $headerParams); + $headerParams, '\Swagger\Client\Model\Pet'); } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Pet'); + $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Pet', $httpHeader); $e->setResponseObject($data); break; } @@ -473,7 +473,7 @@ class PetApi { // make the API Call try { - $response = $this->apiClient->callAPI($resourcePath, $method, + $response = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams); } catch (ApiException $e) { @@ -544,7 +544,7 @@ class PetApi { // make the API Call try { - $response = $this->apiClient->callAPI($resourcePath, $method, + $response = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams); } catch (ApiException $e) { @@ -563,7 +563,7 @@ class PetApi { * * @param int $pet_id ID of pet to update (required) * @param string $additional_metadata Additional data to pass to server (required) - * @param string $file file to upload (required) + * @param \SplFileObject $file file to upload (required) * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ @@ -619,7 +619,7 @@ class PetApi { // make the API Call try { - $response = $this->apiClient->callAPI($resourcePath, $method, + $response = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams); } catch (ApiException $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 237ba3f1acf8..5c9d38a8b5e2 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php @@ -109,13 +109,13 @@ class StoreApi { // make the API Call try { - $response = $this->apiClient->callAPI($resourcePath, $method, + $response = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, - $headerParams); + $headerParams, 'map[string,int]'); } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), 'map[string,int]'); + $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), 'map[string,int]', $httpHeader); $e->setResponseObject($data); break; } @@ -178,13 +178,13 @@ class StoreApi { // make the API Call try { - $response = $this->apiClient->callAPI($resourcePath, $method, + $response = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, - $headerParams); + $headerParams, '\Swagger\Client\Model\Order'); } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Order'); + $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Order', $httpHeader); $e->setResponseObject($data); break; } @@ -253,13 +253,13 @@ class StoreApi { // make the API Call try { - $response = $this->apiClient->callAPI($resourcePath, $method, + $response = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, - $headerParams); + $headerParams, '\Swagger\Client\Model\Order'); } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Order'); + $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Order', $httpHeader); $e->setResponseObject($data); break; } @@ -328,7 +328,7 @@ class StoreApi { // make the API Call try { - $response = $this->apiClient->callAPI($resourcePath, $method, + $response = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams); } catch (ApiException $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 1d0765bbb815..a95d93bb55e4 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php @@ -107,7 +107,7 @@ class UserApi { // make the API Call try { - $response = $this->apiClient->callAPI($resourcePath, $method, + $response = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams); } catch (ApiException $e) { @@ -165,7 +165,7 @@ class UserApi { // make the API Call try { - $response = $this->apiClient->callAPI($resourcePath, $method, + $response = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams); } catch (ApiException $e) { @@ -223,7 +223,7 @@ class UserApi { // make the API Call try { - $response = $this->apiClient->callAPI($resourcePath, $method, + $response = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams); } catch (ApiException $e) { @@ -284,13 +284,13 @@ class UserApi { // make the API Call try { - $response = $this->apiClient->callAPI($resourcePath, $method, + $response = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, - $headerParams); + $headerParams, 'string'); } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), 'string'); + $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), 'string', $httpHeader); $e->setResponseObject($data); break; } @@ -348,7 +348,7 @@ class UserApi { // make the API Call try { - $response = $this->apiClient->callAPI($resourcePath, $method, + $response = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams); } catch (ApiException $e) { @@ -412,13 +412,13 @@ class UserApi { // make the API Call try { - $response = $this->apiClient->callAPI($resourcePath, $method, + $response = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, - $headerParams); + $headerParams, '\Swagger\Client\Model\User'); } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\User'); + $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\User', $httpHeader); $e->setResponseObject($data); break; } @@ -492,7 +492,7 @@ class UserApi { // make the API Call try { - $response = $this->apiClient->callAPI($resourcePath, $method, + $response = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams); } catch (ApiException $e) { @@ -556,7 +556,7 @@ class UserApi { // make the API Call try { - $response = $this->apiClient->callAPI($resourcePath, $method, + $response = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams); } catch (ApiException $e) { diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php b/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php index 66204f0c4f36..92d8c2aa1193 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php @@ -90,7 +90,7 @@ class ApiClient { * @throws \Swagger\Client\ApiException on a non 2xx response * @return mixed */ - public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams) { + public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams, $responseType=null) { $headers = array(); @@ -174,6 +174,11 @@ class ApiClient { 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 ) { + // return raw body if response is a file + if ($responseType == 'SplFileObject') { + return array($http_body, $http_header); + } + $data = json_decode($http_body); if (json_last_error() > 0) { // if response is a string $data = $http_body; diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php b/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php index a407fe4dd49b..f4ccef391ef7 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php @@ -263,4 +263,18 @@ class Configuration { public static function setDefaultConfiguration(Configuration $config) { self::$defaultConfiguration = $config; } + + /* + * return the report for debuggin + */ + public static function toDebugReport() { + $report = "PHP SDK (Swagger\Client) Debug Report:\n"; + $report .= " OS: ".php_uname()."\n"; + $report .= " PHP Version: ".phpversion()."\n"; + $report .= " Swagger Spec Version: 1.0.0\n"; + $report .= " SDK Package Version: 1.0.0\n"; + + return $report; + } + } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php index 75aaf2eeeada..9995dccdd4e0 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php @@ -119,9 +119,9 @@ class Category implements ArrayAccess { public function __toString() { if (defined('JSON_PRETTY_PRINT')) { - return json_encode($this, JSON_PRETTY_PRINT); + return json_encode(get_object_vars($this), JSON_PRETTY_PRINT); } else { - return json_encode($this); + return json_encode(get_object_vars($this)); } } } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php index c7a433c3d8c4..2e0386d0ed74 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php @@ -223,9 +223,9 @@ class Order implements ArrayAccess { public function __toString() { if (defined('JSON_PRETTY_PRINT')) { - return json_encode($this, JSON_PRETTY_PRINT); + return json_encode(get_object_vars($this), JSON_PRETTY_PRINT); } else { - return json_encode($this); + return json_encode(get_object_vars($this)); } } } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php index cbe27e1fce93..a7b259a2fbe8 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php @@ -223,9 +223,9 @@ class Pet implements ArrayAccess { public function __toString() { if (defined('JSON_PRETTY_PRINT')) { - return json_encode($this, JSON_PRETTY_PRINT); + return json_encode(get_object_vars($this), JSON_PRETTY_PRINT); } else { - return json_encode($this); + return json_encode(get_object_vars($this)); } } } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php index 3fd785f001bd..6e8ae3e27a1a 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php @@ -119,9 +119,9 @@ class Tag implements ArrayAccess { public function __toString() { if (defined('JSON_PRETTY_PRINT')) { - return json_encode($this, JSON_PRETTY_PRINT); + return json_encode(get_object_vars($this), JSON_PRETTY_PRINT); } else { - return json_encode($this); + return json_encode(get_object_vars($this)); } } } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php index 2bb31056bdef..b1e2d2b809ca 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php @@ -275,9 +275,9 @@ class User implements ArrayAccess { public function __toString() { if (defined('JSON_PRETTY_PRINT')) { - return json_encode($this, JSON_PRETTY_PRINT); + return json_encode(get_object_vars($this), JSON_PRETTY_PRINT); } else { - return json_encode($this); + return json_encode(get_object_vars($this)); } } } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php b/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php index 802a49bc01ad..d002b3368520 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php @@ -79,7 +79,11 @@ class ObjectSerializer { * @return string the form string */ public function toFormValue($value) { - return $this->toString($value); + if ($value instanceof SplFileObject) { + return $value->getRealPath(); + } else { + return $this->toString($value); + } } /** @@ -104,7 +108,7 @@ class ObjectSerializer { * @param string $class class name is passed as a string * @return object an instance of $class */ - public function deserialize($data, $class) { + public function deserialize($data, $class, $httpHeader=null) { if (null === $data) { $deserialized = null; } elseif (substr($class, 0, 4) == 'map[') { # for associative array e.g. map[string,int] @@ -129,6 +133,24 @@ class ObjectSerializer { } elseif (in_array($class, array('string', 'int', 'float', 'double', 'bool', 'object'))) { settype($data, $class); $deserialized = $data; + } elseif ($class === 'SplFileObject') { + # determine temp folder path + if (!isset(Configuration::$tempFolderPath) || '' === Configuration::$tempFolderPath) { + $tmpFolderPath = sys_get_temp_dir(); + } else { + $tmpFolderPath = Configuration::tempFolderPath; + } + + # determine file name + if (preg_match('/Content-Disposition: inline; filename=(.*)/i', $httpHeader, $match)) { + $filename = $tmpFolderPath.$match[1]; + } else { + $filename = tempnam($tmpFolderPath, ''); + } + $deserialized = new \SplFileObject($filename, "w"); + $byte_written = $deserialized->fwrite($data); + error_log("[INFO] Written $byte_written to $filename. Please move the file to a proper folder for further processing and delete the temp afterwards", 3, Configuration::$debug_file); + } else { $instance = new $class(); foreach ($instance::$swaggerTypes as $property => $type) { @@ -148,4 +170,4 @@ class ObjectSerializer { return $deserialized; } -} \ No newline at end of file +} diff --git a/samples/client/petstore/php/SwaggerClient/vendor/satooshi/php-coveralls/build/config/apigen.neon b/samples/client/petstore/php/SwaggerClient/vendor/satooshi/php-coveralls/build/config/apigen.neon deleted file mode 100644 index c067c2c290f2..000000000000 --- a/samples/client/petstore/php/SwaggerClient/vendor/satooshi/php-coveralls/build/config/apigen.neon +++ /dev/null @@ -1,5 +0,0 @@ -main: Contrib -title: php-coveralls -internal: yes -todo: yes -wipeout: yes diff --git a/samples/client/petstore/php/SwaggerClient/vendor/satooshi/php-coveralls/build/config/phpcs.xml b/samples/client/petstore/php/SwaggerClient/vendor/satooshi/php-coveralls/build/config/phpcs.xml deleted file mode 100644 index 82a58e1b3244..000000000000 --- a/samples/client/petstore/php/SwaggerClient/vendor/satooshi/php-coveralls/build/config/phpcs.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - The coding standard for standard PHP application - */img/* - */images/* - */less/* - */css/* - */js/* - *.html - *.twig - *.yml - *.xml - *.txt - *.less - *.css - *.js - *.jpg - *.jpeg - *.png - *.gif - - - - - - - - - - - diff --git a/samples/client/petstore/php/SwaggerClient/vendor/satooshi/php-coveralls/build/config/phpmd.xml b/samples/client/petstore/php/SwaggerClient/vendor/satooshi/php-coveralls/build/config/phpmd.xml deleted file mode 100644 index 27d3193e749f..000000000000 --- a/samples/client/petstore/php/SwaggerClient/vendor/satooshi/php-coveralls/build/config/phpmd.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - - My custom rule set that checks my code... - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/samples/client/petstore/php/SwaggerClient/vendor/satooshi/php-coveralls/travis/empty b/samples/client/petstore/php/SwaggerClient/vendor/satooshi/php-coveralls/travis/empty deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/samples/client/petstore/php/test.php b/samples/client/petstore/php/test.php index f5383a9a4dc5..55aae557a234 100644 --- a/samples/client/petstore/php/test.php +++ b/samples/client/petstore/php/test.php @@ -19,7 +19,7 @@ try { //$pet_api = new SwaggerClient\PetAPI($api_client); $pet_api = new Swagger\Client\Api\PetAPI(); // test default header - $pet_api->getApiClient()->addDefaultHeader("TEST_API_KEY", "09182sdkanafndsl903"); + //$pet_api->getApiClient()->addDefaultHeader("TEST_API_KEY", "09182sdkanafndsl903"); // return Pet (model) $response = $pet_api->getPetById($petId); // to test __toString() @@ -28,26 +28,26 @@ try { // add pet (post json) $new_pet_id = 10005; $new_pet = new Swagger\Client\Model\Pet; - $new_pet->id = $new_pet_id; - $new_pet->name = "PHP Unit Test"; + $new_pet->setId($new_pet_id); + $new_pet->setName("PHP Unit Test"); // new tag $tag= new Swagger\Client\Model\Tag; - $tag->id = $new_pet_id; // use the same id as pet + $tag->setId($new_pet_id); // use the same id as pet //$tag->name = "test php tag"; // new category $category = new Swagger\Client\Model\Category; - $category->id = 0; // use the same id as pet + $category->setId(10005); // use the same id as pet //$category->name = "test php category"; - $new_pet->tags = array($tag); - $new_pet->category = $category; + $new_pet->setTags(array($tag)); + $new_pet->setCategory($category); $pet_api = new Swagger\Client\Api\PetAPI(); // add a new pet (model) $add_response = $pet_api->addPet($new_pet); // test upload file (exception) - $upload_response = $pet_api->uploadFile($petId, "test meta", NULL); + //$upload_response = $pet_api->uploadFile($petId, "test meta", NULL); } catch (Swagger\Client\Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; From 7f31da734d94fd34d9d39070509d4ed536533190 Mon Sep 17 00:00:00 2001 From: wing328 Date: Fri, 26 Jun 2015 20:50:57 +0800 Subject: [PATCH 2/9] add file response for php, update test case --- .../src/main/resources/php/ApiClient.mustache | 4 ++-- .../resources/php/ObjectSerializer.mustache | 4 ++-- .../src/main/resources/php/api.mustache | 2 +- .../php/SwaggerClient-php/lib/Api/PetApi.php | 16 ++++++------- .../SwaggerClient-php/lib/Api/StoreApi.php | 8 +++---- .../php/SwaggerClient-php/lib/Api/UserApi.php | 16 ++++++------- .../php/SwaggerClient-php/lib/ApiClient.php | 4 ++-- .../lib/ObjectSerializer.php | 4 ++-- .../SwaggerClient-php/tests/PetApiTest.php | 8 ++++--- .../SwaggerClient-php/tests/StoreApiTest.php | 24 +++++++++++++++++-- 10 files changed, 56 insertions(+), 34 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache index 3a4f8dfc8be3..b43c83dd8844 100644 --- a/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache @@ -175,7 +175,7 @@ class ApiClient { 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 ) { // return raw body if response is a file - if ($responseType == 'SplFileObject') { + if ($responseType == '\SplFileObject') { return array($http_body, $http_header); } @@ -187,7 +187,7 @@ class ApiClient { throw new ApiException("[".$response_info['http_code']."] Error connecting to the API ($url)", $response_info['http_code'], $http_header, $http_body); } - return $data; + return array($data, $http_header); } /* diff --git a/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache b/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache index 26999668b9e9..8e433e6185bf 100644 --- a/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache +++ b/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache @@ -133,7 +133,7 @@ class ObjectSerializer { } elseif (in_array($class, array('string', 'int', 'float', 'double', 'bool', 'object'))) { settype($data, $class); $deserialized = $data; - } elseif ($class === 'SplFileObject') { + } elseif ($class === '\SplFileObject') { # determine temp folder path if (!isset(Configuration::$tempFolderPath) || '' === Configuration::$tempFolderPath) { $tmpFolderPath = sys_get_temp_dir(); @@ -149,7 +149,7 @@ class ObjectSerializer { } $deserialized = new \SplFileObject($filename, "w"); $byte_written = $deserialized->fwrite($data); - error_log("[INFO] Written $byte_written to $filename. Please move the file to a proper folder for further processing and delete the temp afterwards", 3, Configuration::$debug_file); + error_log("[INFO] Written $byte_written byte to $filename. Please move the file to a proper folder or delete the temp file afterwards", 3, Configuration::getDefaultConfiguration()->getDebugFile()); } else { $instance = new $class(); diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index 367ba037d598..dcbc8b4b3a61 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -134,7 +134,7 @@ class {{classname}} { {{/authMethods}} // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams{{#returnType}}, '{{returnType}}'{{/returnType}}); } catch (ApiException $e) { 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 afbe1991690e..64ef731c4b0f 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php @@ -110,7 +110,7 @@ class PetApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams); } catch (ApiException $e) { @@ -171,7 +171,7 @@ class PetApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams); } catch (ApiException $e) { @@ -231,7 +231,7 @@ class PetApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams, '\Swagger\Client\Model\Pet[]'); } catch (ApiException $e) { @@ -302,7 +302,7 @@ class PetApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams, '\Swagger\Client\Model\Pet[]'); } catch (ApiException $e) { @@ -387,7 +387,7 @@ class PetApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams, '\Swagger\Client\Model\Pet'); } catch (ApiException $e) { @@ -473,7 +473,7 @@ class PetApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams); } catch (ApiException $e) { @@ -544,7 +544,7 @@ class PetApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams); } catch (ApiException $e) { @@ -619,7 +619,7 @@ class PetApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams); } catch (ApiException $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 5c9d38a8b5e2..c047182133d5 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php @@ -109,7 +109,7 @@ class StoreApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams, 'map[string,int]'); } catch (ApiException $e) { @@ -178,7 +178,7 @@ class StoreApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams, '\Swagger\Client\Model\Order'); } catch (ApiException $e) { @@ -253,7 +253,7 @@ class StoreApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams, '\Swagger\Client\Model\Order'); } catch (ApiException $e) { @@ -328,7 +328,7 @@ class StoreApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams); } catch (ApiException $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 a95d93bb55e4..d9f2a08ccb8f 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php @@ -107,7 +107,7 @@ class UserApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams); } catch (ApiException $e) { @@ -165,7 +165,7 @@ class UserApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams); } catch (ApiException $e) { @@ -223,7 +223,7 @@ class UserApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams); } catch (ApiException $e) { @@ -284,7 +284,7 @@ class UserApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams, 'string'); } catch (ApiException $e) { @@ -348,7 +348,7 @@ class UserApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams); } catch (ApiException $e) { @@ -412,7 +412,7 @@ class UserApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams, '\Swagger\Client\Model\User'); } catch (ApiException $e) { @@ -492,7 +492,7 @@ class UserApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams); } catch (ApiException $e) { @@ -556,7 +556,7 @@ class UserApi { // make the API Call try { - $response = $this->apiClient->callApi($resourcePath, $method, + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, $headerParams); } catch (ApiException $e) { diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php b/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php index 92d8c2aa1193..b47e104ec1e1 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php @@ -175,7 +175,7 @@ class ApiClient { 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 ) { // return raw body if response is a file - if ($responseType == 'SplFileObject') { + if ($responseType == '\SplFileObject') { return array($http_body, $http_header); } @@ -187,7 +187,7 @@ class ApiClient { throw new ApiException("[".$response_info['http_code']."] Error connecting to the API ($url)", $response_info['http_code'], $http_header, $http_body); } - return $data; + return array($data, $http_header); } /* diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php b/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php index d002b3368520..59b7601d1407 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php @@ -133,7 +133,7 @@ class ObjectSerializer { } elseif (in_array($class, array('string', 'int', 'float', 'double', 'bool', 'object'))) { settype($data, $class); $deserialized = $data; - } elseif ($class === 'SplFileObject') { + } elseif ($class === '\SplFileObject') { # determine temp folder path if (!isset(Configuration::$tempFolderPath) || '' === Configuration::$tempFolderPath) { $tmpFolderPath = sys_get_temp_dir(); @@ -149,7 +149,7 @@ class ObjectSerializer { } $deserialized = new \SplFileObject($filename, "w"); $byte_written = $deserialized->fwrite($data); - error_log("[INFO] Written $byte_written to $filename. Please move the file to a proper folder for further processing and delete the temp afterwards", 3, Configuration::$debug_file); + error_log("[INFO] Written $byte_written byte to $filename. Please move the file to a proper folder or delete the temp file afterwards", 3, Configuration::getDefaultConfiguration()->getDebugFile()); } else { $instance = new $class(); diff --git a/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php b/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php index 3ac287722915..76c88d20c4e9 100644 --- a/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php @@ -10,9 +10,11 @@ class PetApiTest extends \PHPUnit_Framework_TestCase // for error reporting (need to run with php5.3 to get no warning) //ini_set('display_errors', 1); //error_reporting(~0); - ini_set('display_startup_errors',1); - ini_set('display_errors',1); - error_reporting(-1); + // when running with php5.5, comment out below to skip the warning about + // using @ to handle file upload + //ini_set('display_startup_errors',1); + //ini_set('display_errors',1); + //error_reporting(-1); // enable debugging //Swagger\Client\Configuration::$debug = true; diff --git a/samples/client/petstore/php/SwaggerClient-php/tests/StoreApiTest.php b/samples/client/petstore/php/SwaggerClient-php/tests/StoreApiTest.php index 05bd873c993d..fcba8adf20ad 100644 --- a/samples/client/petstore/php/SwaggerClient-php/tests/StoreApiTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/tests/StoreApiTest.php @@ -10,6 +10,27 @@ class StoreApiTest extends \PHPUnit_Framework_TestCase // for error reporting (need to run with php5.3 to get no warning) //ini_set('display_errors', 1); //error_reporting(~0); + // new pet + $new_pet_id = 10005; + $new_pet = new Swagger\Client\Model\Pet; + $new_pet->setId($new_pet_id); + $new_pet->setName("PHP Unit Test"); + $new_pet->setStatus("available"); + // new tag + $tag= new Swagger\Client\Model\Tag; + $tag->setId($new_pet_id); // use the same id as pet + $tag->setName("test php tag"); + // new category + $category = new Swagger\Client\Model\Category; + $category->setId($new_pet_id); // use the same id as pet + $category->setName("test php category"); + + $new_pet->setTags(array($tag)); + $new_pet->setCategory($category); + + $pet_api = new Swagger\Client\Api\PetAPI(); + // add a new pet (model) + $add_response = $pet_api->addPet($new_pet); } // test get inventory @@ -22,8 +43,7 @@ class StoreApiTest extends \PHPUnit_Framework_TestCase // get inventory $get_response = $store_api->getInventory(); - $this->assertInternalType("int", $get_response['sold']); - $this->assertInternalType("int", $get_response['pending']); + $this->assertInternalType("int", $get_response['available']); } From 259b31ccd44d534cddbcd54af82354a8662dfdf5 Mon Sep 17 00:00:00 2001 From: wing328 Date: Fri, 26 Jun 2015 23:55:51 +0800 Subject: [PATCH 3/9] temporary folder setting --- .../src/main/resources/php/ApiClient.mustache | 392 +++--- .../main/resources/php/ApiException.mustache | 92 +- .../resources/php/ObjectSerializer.mustache | 194 +-- .../src/main/resources/php/api.mustache | 252 ++-- .../src/main/resources/php/composer.mustache | 60 +- .../main/resources/php/configuration.mustache | 511 ++++---- .../src/main/resources/php/model.mustache | 148 +-- .../src/test/resources/2_0/petstore.json | 2 +- .../php/SwaggerClient-php/composer.json | 58 +- .../php/SwaggerClient-php/lib/Api/PetApi.php | 1165 ++++++++--------- .../SwaggerClient-php/lib/Api/StoreApi.php | 601 +++++---- .../php/SwaggerClient-php/lib/Api/UserApi.php | 1040 ++++++++------- .../php/SwaggerClient-php/lib/ApiClient.php | 392 +++--- .../SwaggerClient-php/lib/ApiException.php | 92 +- .../SwaggerClient-php/lib/Configuration.php | 532 ++++---- .../SwaggerClient-php/lib/Model/Category.php | 184 +-- .../php/SwaggerClient-php/lib/Model/Order.php | 390 +++--- .../php/SwaggerClient-php/lib/Model/Pet.php | 390 +++--- .../php/SwaggerClient-php/lib/Model/Tag.php | 184 +-- .../php/SwaggerClient-php/lib/Model/User.php | 494 +++---- .../lib/ObjectSerializer.php | 192 ++- samples/client/petstore/php/test.php | 3 + 22 files changed, 3697 insertions(+), 3671 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache index b43c83dd8844..158c9c662c00 100644 --- a/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache @@ -19,206 +19,206 @@ namespace {{invokerPackage}}; class ApiClient { - public static $PATCH = "PATCH"; - public static $POST = "POST"; - public static $GET = "GET"; - public static $PUT = "PUT"; - public static $DELETE = "DELETE"; - - /** @var Configuration */ - protected $config; - - /** @var ObjectSerializer */ - protected $serializer; - - /** - * @param Configuration $config config for this ApiClient - */ - function __construct(Configuration $config = null) { - if ($config == null) { - $config = Configuration::getDefaultConfiguration(); + public static $PATCH = "PATCH"; + public static $POST = "POST"; + public static $GET = "GET"; + public static $PUT = "PUT"; + public static $DELETE = "DELETE"; + + /** @var Configuration */ + protected $config; + + /** @var ObjectSerializer */ + protected $serializer; + + /** + * @param Configuration $config config for this ApiClient + */ + function __construct(Configuration $config = null) { + if ($config == null) { + $config = Configuration::getDefaultConfiguration(); + } + + $this->config = $config; + $this->serializer = new ObjectSerializer(); + } + + /** + * get the config + * @return Configuration + */ + public function getConfig() { + return $this->config; + } + + /** + * get the serializer + * @return ObjectSerializer + */ + public function getSerializer() { + return $this->serializer; + } + + /** + * Get API key (with prefix if set) + * @param string $apiKey name of apikey + * @return string API key with the prefix + */ + public function getApiKeyWithPrefix($apiKeyIdentifier) { + $prefix = $this->config->getApiKeyPrefix($apiKeyIdentifier); + $apiKey = $this->config->getApiKey($apiKeyIdentifier); + + if (!isset($apiKey)) { + return null; + } + + if (isset($prefix)) { + $keyWithPrefix = $prefix." ".$apiKey; + } else { + $keyWithPrefix = $apiKey; + } + + return $keyWithPrefix; } - $this->config = $config; - $this->serializer = new ObjectSerializer(); - } - - /** - * get the config - * @return Configuration - */ - public function getConfig() { - return $this->config; - } - - /** - * get the serializer - * @return ObjectSerializer - */ - public function getSerializer() { - return $this->serializer; - } - - /** - * Get API key (with prefix if set) - * @param string $apiKey name of apikey - * @return string API key with the prefix - */ - public function getApiKeyWithPrefix($apiKey) { - $prefix = $this->config->getApiKeyPrefix($apiKey); - $apiKey = $this->config->getApiKey($apiKey); - - if (!isset($apiKey)) { - return null; - } - - if (isset($prefix)) { - $keyWithPrefix = $prefix." ".$apiKey; - } else { - $keyWithPrefix = $apiKey; - } - - return $keyWithPrefix; - } + /** + * @param string $resourcePath path to method endpoint + * @param string $method method to call + * @param array $queryParams parameters to be place in query URL + * @param array $postData parameters to be placed in POST body + * @param array $headerParams parameters to be place in request header + * @throws \{{invokerPackage}}\ApiException on a non 2xx response + * @return mixed + */ + public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams, $responseType=null) { - /** - * @param string $resourcePath path to method endpoint - * @param string $method method to call - * @param array $queryParams parameters to be place in query URL - * @param array $postData parameters to be placed in POST body - * @param array $headerParams parameters to be place in request header - * @throws \{{invokerPackage}}\ApiException on a non 2xx response - * @return mixed - */ - public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams, $responseType=null) { - - $headers = array(); - - # construct the http header - $headerParams = array_merge((array)$this->config->getDefaultHeaders(), (array)$headerParams); - - foreach ($headerParams as $key => $val) { - $headers[] = "$key: $val"; + $headers = array(); + + # construct the http header + $headerParams = array_merge((array)$this->config->getDefaultHeaders(), (array)$headerParams); + + foreach ($headerParams as $key => $val) { + $headers[] = "$key: $val"; + } + + // 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 + $postData = json_encode($this->serializer->sanitizeForSerialization($postData)); + } + + $url = $this->config->getHost() . $resourcePath; + + $curl = curl_init(); + // set timeout, if needed + if ($this->config->getCurlTimeout() != 0) { + curl_setopt($curl, CURLOPT_TIMEOUT, $this->config->getCurlTimeout()); + } + // return the result on success, rather than just TRUE + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + + curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); + + if (! empty($queryParams)) { + $url = ($url . '?' . http_build_query($queryParams)); + } + + if ($method == self::$POST) { + curl_setopt($curl, CURLOPT_POST, true); + curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); + } else if ($method == self::$PATCH) { + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH"); + curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); + } else if ($method == self::$PUT) { + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); + curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); + } else if ($method == self::$DELETE) { + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); + curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); + } else if ($method != self::$GET) { + throw new ApiException('Method ' . $method . ' is not recognized.'); + } + curl_setopt($curl, CURLOPT_URL, $url); + + // Set user agent + curl_setopt($curl, CURLOPT_USERAGENT, $this->config->getUserAgent()); + + // debugging for curl + if ($this->config->getDebug()) { + error_log("[DEBUG] HTTP Request body ~BEGIN~\n".print_r($postData, true)."\n~END~\n", 3, $this->config->getDebugFile()); + + curl_setopt($curl, CURLOPT_VERBOSE, 1); + curl_setopt($curl, CURLOPT_STDERR, fopen($this->config->getDebugFile(), 'a')); + } else { + curl_setopt($curl, CURLOPT_VERBOSE, 0); + } + + // obtain the HTTP response headers + curl_setopt($curl, CURLOPT_HEADER, 1); + + // 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_body = substr($response, $http_header_size); + $response_info = curl_getinfo($curl); + + // debug HTTP response body + if ($this->config->getDebug()) { + error_log("[DEBUG] HTTP Response body ~BEGIN~\n".print_r($http_body, true)."\n~END~\n", 3, $this->config->getDebugFile()); + } + + // 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 ) { + // return raw body if response is a file + if ($responseType == '\SplFileObject') { + return array($http_body, $http_header); + } + + $data = json_decode($http_body); + if (json_last_error() > 0) { // if response is a string + $data = $http_body; + } + } else { + throw new ApiException("[".$response_info['http_code']."] Error connecting to the API ($url)", + $response_info['http_code'], $http_header, $http_body); + } + return array($data, $http_header); } - - // form data - if ($postData and in_array('Content-Type: application/x-www-form-urlencoded', $headers)) { - $postData = http_build_query($postData); + + /* + * return the header 'Accept' based on an array of Accept provided + * + * @param string[] $accept Array of header + * @return string Accept (e.g. application/json) + */ + public static function selectHeaderAccept($accept) { + if (count($accept) === 0 or (count($accept) === 1 and $accept[0] === '')) { + return NULL; + } elseif (preg_grep("/application\/json/i", $accept)) { + return 'application/json'; + } else { + return implode(',', $accept); + } } - else if ((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)); + + /* + * return the content type based on an array of content-type provided + * + * @param string[] content_type_array Array fo content-type + * @return string Content-Type (e.g. application/json) + */ + public static function selectHeaderContentType($content_type) { + if (count($content_type) === 0 or (count($content_type) === 1 and $content_type[0] === '')) { + return 'application/json'; + } elseif (preg_grep("/application\/json/i", $content_type)) { + return 'application/json'; + } else { + return implode(',', $content_type); + } } - - $url = $this->config->getHost() . $resourcePath; - - $curl = curl_init(); - // set timeout, if needed - if ($this->config->getCurlTimeout() != 0) { - curl_setopt($curl, CURLOPT_TIMEOUT, $this->config->getCurlTimeout()); - } - // return the result on success, rather than just TRUE - curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); - - curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); - - if (! empty($queryParams)) { - $url = ($url . '?' . http_build_query($queryParams)); - } - - if ($method == self::$POST) { - curl_setopt($curl, CURLOPT_POST, true); - curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method == self::$PATCH) { - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH"); - curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method == self::$PUT) { - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); - curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method == self::$DELETE) { - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); - curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method != self::$GET) { - throw new ApiException('Method ' . $method . ' is not recognized.'); - } - curl_setopt($curl, CURLOPT_URL, $url); - - // Set user agent - curl_setopt($curl, CURLOPT_USERAGENT, $this->config->getUserAgent()); - - // debugging for curl - if ($this->config->getDebug()) { - error_log("[DEBUG] HTTP Request body ~BEGIN~\n".print_r($postData, true)."\n~END~\n", 3, $this->config->getDebugFile()); - - curl_setopt($curl, CURLOPT_VERBOSE, 1); - curl_setopt($curl, CURLOPT_STDERR, fopen($this->config->getDebugFile(), 'a')); - } else { - curl_setopt($curl, CURLOPT_VERBOSE, 0); - } - - // obtain the HTTP response headers - curl_setopt($curl, CURLOPT_HEADER, 1); - - // 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_body = substr($response, $http_header_size); - $response_info = curl_getinfo($curl); - - // debug HTTP response body - if ($this->config->getDebug()) { - error_log("[DEBUG] HTTP Response body ~BEGIN~\n".print_r($http_body, true)."\n~END~\n", 3, $this->config->getDebugFile()); - } - - // 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 ) { - // return raw body if response is a file - if ($responseType == '\SplFileObject') { - return array($http_body, $http_header); - } - - $data = json_decode($http_body); - if (json_last_error() > 0) { // if response is a string - $data = $http_body; - } - } else { - throw new ApiException("[".$response_info['http_code']."] Error connecting to the API ($url)", - $response_info['http_code'], $http_header, $http_body); - } - return array($data, $http_header); - } - - /* - * return the header 'Accept' based on an array of Accept provided - * - * @param string[] $accept Array of header - * @return string Accept (e.g. application/json) - */ - public static function selectHeaderAccept($accept) { - if (count($accept) === 0 or (count($accept) === 1 and $accept[0] === '')) { - return NULL; - } elseif (preg_grep("/application\/json/i", $accept)) { - return 'application/json'; - } else { - return implode(',', $accept); - } - } - - /* - * return the content type based on an array of content-type provided - * - * @param string[] content_type_array Array fo content-type - * @return string Content-Type (e.g. application/json) - */ - public static function selectHeaderContentType($content_type) { - if (count($content_type) === 0 or (count($content_type) === 1 and $content_type[0] === '')) { - return 'application/json'; - } elseif (preg_grep("/application\/json/i", $content_type)) { - return 'application/json'; - } else { - return implode(',', $content_type); - } - } } diff --git a/modules/swagger-codegen/src/main/resources/php/ApiException.mustache b/modules/swagger-codegen/src/main/resources/php/ApiException.mustache index 6d5415f798d4..c57310ccece4 100644 --- a/modules/swagger-codegen/src/main/resources/php/ApiException.mustache +++ b/modules/swagger-codegen/src/main/resources/php/ApiException.mustache @@ -21,50 +21,50 @@ use \Exception; class ApiException extends Exception { - /** @var string The HTTP body of the server response. */ - protected $responseBody; - - /** @var string[] The HTTP header of the server response. */ - protected $responseHeaders; - - /** - * The deserialized response object - */ - protected $responseObject; - - public function __construct($message="", $code=0, $responseHeaders=null, $responseBody=null) { - parent::__construct($message, $code); - $this->responseHeaders = $responseHeaders; - $this->responseBody = $responseBody; - } - - /** - * Get the HTTP response header - * - * @return string HTTP response header - */ - public function getResponseHeaders() { - return $this->responseHeaders; - } - - /** - * Get the HTTP response body - * - * @return string HTTP response body - */ - public function getResponseBody() { - return $this->responseBody; - } - - /** - * sets the deseralized response object (during deserialization) - * @param mixed $obj - */ - public function setResponseObject($obj) { - $this->responseObject = $obj; - } - - public function getResponseObject() { - return $this->responseObject; - } + /** @var string The HTTP body of the server response. */ + protected $responseBody; + + /** @var string[] The HTTP header of the server response. */ + protected $responseHeaders; + + /** + * The deserialized response object + */ + protected $responseObject; + + public function __construct($message="", $code=0, $responseHeaders=null, $responseBody=null) { + parent::__construct($message, $code); + $this->responseHeaders = $responseHeaders; + $this->responseBody = $responseBody; + } + + /** + * Get the HTTP response header + * + * @return string HTTP response header + */ + public function getResponseHeaders() { + return $this->responseHeaders; + } + + /** + * Get the HTTP response body + * + * @return string HTTP response body + */ + public function getResponseBody() { + return $this->responseBody; + } + + /** + * sets the deseralized response object (during deserialization) + * @param mixed $obj + */ + public function setResponseObject($obj) { + $this->responseObject = $obj; + } + + public function getResponseObject() { + return $this->responseObject; + } } diff --git a/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache b/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache index 8e433e6185bf..4463236063a9 100644 --- a/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache +++ b/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache @@ -9,29 +9,29 @@ class ObjectSerializer { * @return string serialized form of $data */ public function sanitizeForSerialization($data) { - if (is_scalar($data) || null === $data) { - $sanitized = $data; - } else if ($data instanceof \DateTime) { - $sanitized = $data->format(\DateTime::ISO8601); - } else if (is_array($data)) { - foreach ($data as $property => $value) { - $data[$property] = $this->sanitizeForSerialization($value); + if (is_scalar($data) || null === $data) { + $sanitized = $data; + } else if ($data instanceof \DateTime) { + $sanitized = $data->format(\DateTime::ISO8601); + } else if (is_array($data)) { + foreach ($data as $property => $value) { + $data[$property] = $this->sanitizeForSerialization($value); + } + $sanitized = $data; + } else if (is_object($data)) { + $values = array(); + foreach (array_keys($data::$swaggerTypes) as $property) { + $getter = $data::$getters[$property]; + if ($data->$getter() !== null) { + $values[$data::$attributeMap[$property]] = $this->sanitizeForSerialization($data->$getter()); + } + } + $sanitized = $values; + } else { + $sanitized = (string)$data; } - $sanitized = $data; - } else if (is_object($data)) { - $values = array(); - foreach (array_keys($data::$swaggerTypes) as $property) { - $getter = $data::$getters[$property]; - if ($data->$getter() !== null) { - $values[$data::$attributeMap[$property]] = $this->sanitizeForSerialization($data->$getter()); - } - } - $sanitized = $values; - } else { - $sanitized = (string)$data; - } - return $sanitized; + return $sanitized; } /** @@ -41,7 +41,7 @@ class ObjectSerializer { * @return string the serialized object */ public function toPathValue($value) { - return rawurlencode($this->toString($value)); + return rawurlencode($this->toString($value)); } /** @@ -53,11 +53,11 @@ class ObjectSerializer { * @return string the serialized object */ public function toQueryValue($object) { - if (is_array($object)) { - return implode(',', $object); - } else { - return $this->toString($object); - } + if (is_array($object)) { + return implode(',', $object); + } else { + return $this->toString($object); + } } /** @@ -68,7 +68,7 @@ class ObjectSerializer { * @return string the header string */ public function toHeaderValue($value) { - return $this->toString($value); + return $this->toString($value); } /** @@ -79,11 +79,11 @@ class ObjectSerializer { * @return string the form string */ public function toFormValue($value) { - if ($value instanceof SplFileObject) { - return $value->getRealPath(); - } else { - return $this->toString($value); - } + if ($value instanceof SplFileObject) { + return $value->getRealPath(); + } else { + return $this->toString($value); + } } /** @@ -94,11 +94,11 @@ class ObjectSerializer { * @return string the header string */ public function toString($value) { - if ($value instanceof \DateTime) { // datetime in ISO8601 format - return $value->format(\DateTime::ISO8601); - } else { - return $value; - } + if ($value instanceof \DateTime) { // datetime in ISO8601 format + return $value->format(\DateTime::ISO8601); + } else { + return $value; + } } /** @@ -109,65 +109,65 @@ class ObjectSerializer { * @return object an instance of $class */ public function deserialize($data, $class, $httpHeader=null) { - if (null === $data) { - $deserialized = null; - } elseif (substr($class, 0, 4) == 'map[') { # for associative array e.g. map[string,int] - $inner = substr($class, 4, -1); - $deserialized = array(); - if(strrpos($inner, ",") !== false) { - $subClass_array = explode(',', $inner, 2); - $subClass = $subClass_array[1]; - foreach ($data as $key => $value) { - $deserialized[$key] = $this->deserialize($value, $subClass); - } + if (null === $data) { + $deserialized = null; + } elseif (substr($class, 0, 4) == 'map[') { # for associative array e.g. map[string,int] + $inner = substr($class, 4, -1); + $deserialized = array(); + if(strrpos($inner, ",") !== false) { + $subClass_array = explode(',', $inner, 2); + $subClass = $subClass_array[1]; + foreach ($data as $key => $value) { + $deserialized[$key] = $this->deserialize($value, $subClass); + } + } + } elseif (strcasecmp(substr($class, -2),'[]') == 0) { + $subClass = substr($class, 0, -2); + $values = array(); + foreach ($data as $key => $value) { + $values[] = $this->deserialize($value, $subClass); + } + $deserialized = $values; + } elseif ($class == 'DateTime') { + $deserialized = new \DateTime($data); + } elseif (in_array($class, array('string', 'int', 'float', 'double', 'bool', 'object'))) { + settype($data, $class); + $deserialized = $data; + } elseif ($class === '\SplFileObject') { + # determine temp folder path + if (!isset(Configuration::getDefaultConfig->$tempFolderPath) || '' === Configuration::$tempFolderPath) { + $tmpFolderPath = sys_get_temp_dir(); + } else { + $tmpFolderPath = Configuration::tempFolderPath; + } + + # determine file name + if (preg_match('/Content-Disposition: inline; filename=(.*)/i', $httpHeader, $match)) { + $filename = $tmpFolderPath.$match[1]; + } else { + $filename = tempnam($tmpFolderPath, ''); + } + $deserialized = new \SplFileObject($filename, "w"); + $byte_written = $deserialized->fwrite($data); + error_log("[INFO] Written $byte_written byte to $filename. Please move the file to a proper folder or delete the temp file afterwards", 3, Configuration::getDefaultConfiguration()->getDebugFile()); + + } else { + $instance = new $class(); + foreach ($instance::$swaggerTypes as $property => $type) { + $propertySetter = $instance::$setters[$property]; + + if (!isset($propertySetter) || !isset($data->{$instance::$attributeMap[$property]})) { + continue; + } + + $propertyValue = $data->{$instance::$attributeMap[$property]}; + if (isset($propertyValue)) { + $instance->$propertySetter($this->deserialize($propertyValue, $type)); + } + } + $deserialized = $instance; } - } elseif (strcasecmp(substr($class, -2),'[]') == 0) { - $subClass = substr($class, 0, -2); - $values = array(); - foreach ($data as $key => $value) { - $values[] = $this->deserialize($value, $subClass); - } - $deserialized = $values; - } elseif ($class == 'DateTime') { - $deserialized = new \DateTime($data); - } elseif (in_array($class, array('string', 'int', 'float', 'double', 'bool', 'object'))) { - settype($data, $class); - $deserialized = $data; - } elseif ($class === '\SplFileObject') { - # determine temp folder path - if (!isset(Configuration::$tempFolderPath) || '' === Configuration::$tempFolderPath) { - $tmpFolderPath = sys_get_temp_dir(); - } else { - $tmpFolderPath = Configuration::tempFolderPath; - } - - # determine file name - if (preg_match('/Content-Disposition: inline; filename=(.*)/i', $httpHeader, $match)) { - $filename = $tmpFolderPath.$match[1]; - } else { - $filename = tempnam($tmpFolderPath, ''); - } - $deserialized = new \SplFileObject($filename, "w"); - $byte_written = $deserialized->fwrite($data); - error_log("[INFO] Written $byte_written byte to $filename. Please move the file to a proper folder or delete the temp file afterwards", 3, Configuration::getDefaultConfiguration()->getDebugFile()); - - } else { - $instance = new $class(); - foreach ($instance::$swaggerTypes as $property => $type) { - $propertySetter = $instance::$setters[$property]; - - if (!isset($propertySetter) || !isset($data->{$instance::$attributeMap[$property]})) { - continue; - } - - $propertyValue = $data->{$instance::$attributeMap[$property]}; - if (isset($propertyValue)) { - $instance->$propertySetter($this->deserialize($propertyValue, $type)); - } - } - $deserialized = $instance; - } - - return $deserialized; + + return $deserialized; } } diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index dcbc8b4b3a61..5a97244bfe88 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -30,132 +30,132 @@ use \{{invokerPackage}}\ObjectSerializer; {{#operations}} class {{classname}} { - /** @var \{{invokerPackage}}\ApiClient instance of the ApiClient */ - private $apiClient; - - /** - * @param \{{invokerPackage}}\ApiClient|null $apiClient The api client to use - */ - function __construct($apiClient = null) { - if ($apiClient == null) { - $apiClient = new ApiClient(); - $apiClient->getConfig()->setHost('{{basePath}}'); - } - - $this->apiClient = $apiClient; - } - - /** - * @return \{{invokerPackage}}\ApiClient get the API client - */ - public function getApiClient() { - return $this->apiClient; - } - - /** - * @param \{{invokerPackage}}\ApiClient $apiClient set the API client - * @return {{classname}} - */ - public function setApiClient(ApiClient $apiClient) { - $this->apiClient = $apiClient; - return $this; - } - - {{#operation}} - /** - * {{{nickname}}} - * - * {{{summary}}} - * -{{#allParams}} * @param {{dataType}} ${{paramName}} {{description}} {{#required}}(required){{/required}}{{^required}}(optional){{/required}} -{{/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}}) { - {{#allParams}}{{#required}} - // verify the required parameter '{{paramName}}' is set - if (${{paramName}} === null) { - throw new \InvalidArgumentException('Missing the required parameter ${{paramName}} when calling {{nickname}}'); - } - {{/required}}{{/allParams}} - - // parse inputs - $resourcePath = "{{path}}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "{{httpMethod}}"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = ApiClient::selectHeaderAccept(array({{#produces}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/produces}})); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array({{#consumes}}'{{mediaType}}'{{#hasMore}},{{/hasMore}}{{/consumes}})); - - {{#queryParams}}// query params - if(${{paramName}} !== null) { - $queryParams['{{baseName}}'] = $this->apiClient->getSerializer()->toQueryValue(${{paramName}}); - }{{/queryParams}} - {{#headerParams}}// header params - if(${{paramName}} !== null) { - $headerParams['{{baseName}}'] = $this->apiClient->getSerializer()->toHeaderValue(${{paramName}}); - }{{/headerParams}} - {{#pathParams}}// path params - if(${{paramName}} !== null) { - $resourcePath = str_replace("{" . "{{baseName}}" . "}", - $this->apiClient->getSerializer()->toPathValue(${{paramName}}), - $resourcePath); - }{{/pathParams}} - {{#formParams}}// form params - if (${{paramName}} !== null) { - $formParams['{{baseName}}'] = {{#isFile}}'@' . {{/isFile}}$this->apiClient->getSerializer()->toFormValue(${{paramName}}); - }{{/formParams}} - {{#bodyParams}}// body params - $_tempBody = null; - if (isset(${{paramName}})) { - $_tempBody = ${{paramName}}; - }{{/bodyParams}} - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - {{#authMethods}}{{#isApiKey}} - $apiKey = $this->apiClient->getApiKeyWithPrefix('{{keyParamName}}'); - if (isset($apiKey)) { - {{#isKeyInHeader}}$headerParams['{{keyParamName}}'] = $apiKey;{{/isKeyInHeader}}{{#isKeyInQuery}}$queryParams['{{keyParamName}}'] = $apiKey;{{/isKeyInQuery}} - }{{/isApiKey}} - {{#isBasic}}$headerParams['Authorization'] = 'Basic '.base64_encode($this->apiClient->getConfig()->getUsername().":".$this->apiClient->getConfig()->getPassword());{{/isBasic}} - {{#isOAuth}}//TODO support oauth{{/isOAuth}} - {{/authMethods}} - // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams{{#returnType}}, '{{returnType}}'{{/returnType}}); - } catch (ApiException $e) { - switch ($e->getCode()) { {{#responses}}{{#dataType}} - case {{code}}: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '{{dataType}}', $httpHeader); - $e->setResponseObject($data); - break;{{/dataType}}{{/responses}} + /** @var \{{invokerPackage}}\ApiClient instance of the ApiClient */ + private $apiClient; + + /** + * @param \{{invokerPackage}}\ApiClient|null $apiClient The api client to use + */ + function __construct($apiClient = null) { + if ($apiClient == null) { + $apiClient = new ApiClient(); + $apiClient->getConfig()->setHost('{{basePath}}'); } - - throw $e; - } - {{#returnType}} - if (!$response) { - return null; - } - - $responseObject = $this->apiClient->getSerializer()->deserialize($response,'{{returnType}}'); - return $responseObject; - {{/returnType}} - } - {{/operation}} + + $this->apiClient = $apiClient; + } + + /** + * @return \{{invokerPackage}}\ApiClient get the API client + */ + public function getApiClient() { + return $this->apiClient; + } + + /** + * @param \{{invokerPackage}}\ApiClient $apiClient set the API client + * @return {{classname}} + */ + public function setApiClient(ApiClient $apiClient) { + $this->apiClient = $apiClient; + return $this; + } + + {{#operation}} + /** + * {{{nickname}}} + * + * {{{summary}}} + * + {{#allParams}} * @param {{dataType}} ${{paramName}} {{description}} {{#required}}(required){{/required}}{{^required}}(optional){{/required}} + {{/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}}) { + {{#allParams}}{{#required}} + // verify the required parameter '{{paramName}}' is set + if (${{paramName}} === null) { + throw new \InvalidArgumentException('Missing the required parameter ${{paramName}} when calling {{nickname}}'); +>>>>>>> temporary folder setting + } + {{/required}}{{/allParams}} + + // parse inputs + $resourcePath = "{{path}}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "{{httpMethod}}"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = ApiClient::selectHeaderAccept(array({{#produces}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/produces}})); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array({{#consumes}}'{{mediaType}}'{{#hasMore}},{{/hasMore}}{{/consumes}})); + + {{#queryParams}}// query params + if(${{paramName}} !== null) { + $queryParams['{{baseName}}'] = $this->apiClient->getSerializer()->toQueryValue(${{paramName}}); + }{{/queryParams}} + {{#headerParams}}// header params + if(${{paramName}} !== null) { + $headerParams['{{baseName}}'] = $this->apiClient->getSerializer()->toHeaderValue(${{paramName}}); + }{{/headerParams}} + {{#pathParams}}// path params + if(${{paramName}} !== null) { + $resourcePath = str_replace("{" . "{{baseName}}" . "}", + $this->apiClient->getSerializer()->toPathValue(${{paramName}}), + $resourcePath); + }{{/pathParams}} + {{#formParams}}// form params + if (${{paramName}} !== null) { + $formParams['{{baseName}}'] = {{#isFile}}'@' . {{/isFile}}$this->apiClient->getSerializer()->toFormValue(${{paramName}}); + }{{/formParams}} + {{#bodyParams}}// body params + $_tempBody = null; + if (isset(${{paramName}})) { + $_tempBody = ${{paramName}}; + }{{/bodyParams}} + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; + } + {{#authMethods}}{{#isApiKey}} + $apiKey = $this->apiClient->getApiKeyWithPrefix('{{keyParamName}}'); + if (isset($apiKey)) { + {{#isKeyInHeader}}$headerParams['{{keyParamName}}'] = $apiKey;{{/isKeyInHeader}}{{#isKeyInQuery}}$queryParams['{{keyParamName}}'] = $apiKey;{{/isKeyInQuery}} + }{{/isApiKey}} + {{#isBasic}}$headerParams['Authorization'] = 'Basic '.base64_encode($this->apiClient->getConfig()->getUsername().":".$this->apiClient->getConfig()->getPassword());{{/isBasic}} + {{#isOAuth}}//TODO support oauth{{/isOAuth}} + {{/authMethods}} + // make the API Call + try { + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, + $queryParams, $httpBody, + $headerParams{{#returnType}}, '{{returnType}}'{{/returnType}}); + } catch (ApiException $e) { + switch ($e->getCode()) { {{#responses}}{{#dataType}} + case {{code}}: + $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '{{dataType}}', $httpHeader); + $e->setResponseObject($data); + break;{{/dataType}}{{/responses}} + } + + throw $e; + } + {{#returnType}} + if (!$response) { + return null; + } + + return $this->apiClient->getSerializer()->deserialize($response,'{{returnType}}'); + {{/returnType}} + } + {{/operation}} } {{/operations}} diff --git a/modules/swagger-codegen/src/main/resources/php/composer.mustache b/modules/swagger-codegen/src/main/resources/php/composer.mustache index d36267617c4d..52425899ce74 100644 --- a/modules/swagger-codegen/src/main/resources/php/composer.mustache +++ b/modules/swagger-codegen/src/main/resources/php/composer.mustache @@ -1,33 +1,33 @@ { - "name": "{{groupId}}/{{artifactId}}",{{#artifactVersion}} - "version": "{{artifactVersion}}",{{/artifactVersion}} - "description": "{{description}}", - "keywords": [ - "swagger", - "php", - "sdk", - "api" - ], - "homepage": "http://swagger.io", - "license": "Apache v2", - "authors": [ - { - "name": "Swagger and contributors", - "homepage": "https://github.com/swagger-api/swagger-codegen" + "name": "{{groupId}}/{{artifactId}}",{{#artifactVersion}} + "version": "{{artifactVersion}}",{{/artifactVersion}} + "description": "{{description}}", + "keywords": [ + "swagger", + "php", + "sdk", + "api" + ], + "homepage": "http://swagger.io", + "license": "Apache v2", + "authors": [ + { + "name": "Swagger and contributors", + "homepage": "https://github.com/swagger-api/swagger-codegen" + } + ], + "require": { + "php": ">=5.3.3", + "ext-curl": "*", + "ext-json": "*", + "ext-mbstring": "*" + }, + "require-dev": { + "phpunit/phpunit": "~4.0", + "satooshi/php-coveralls": "~0.6.1", + "squizlabs/php_codesniffer": "~2.0" + }, + "autoload": { + "psr-4": { "{{escapedInvokerPackage}}\\" : "{{srcBasePath}}/" } } - ], - "require": { - "php": ">=5.3.3", - "ext-curl": "*", - "ext-json": "*", - "ext-mbstring": "*" - }, - "require-dev": { - "phpunit/phpunit": "~4.0", - "satooshi/php-coveralls": "~0.6.1", - "squizlabs/php_codesniffer": "~2.0" - }, - "autoload": { - "psr-4": { "{{escapedInvokerPackage}}\\" : "{{srcBasePath}}/" } - } } diff --git a/modules/swagger-codegen/src/main/resources/php/configuration.mustache b/modules/swagger-codegen/src/main/resources/php/configuration.mustache index 687470669730..94e0165b4a83 100644 --- a/modules/swagger-codegen/src/main/resources/php/configuration.mustache +++ b/modules/swagger-codegen/src/main/resources/php/configuration.mustache @@ -19,262 +19,265 @@ namespace {{invokerPackage}}; class Configuration { - private static $defaultConfiguration = null; - - /** @var string[] Associate array to store API key(s) */ - protected $apiKeys = array(); - - /** string[] Associate array to store API prefix (e.g. Bearer) */ - protected $apiKeyPrefixes = array(); - - /** @var string Username for HTTP basic authentication */ - protected $username = ''; - - /** @var string Password for HTTP basic authentication */ - protected $password = ''; - - /** @var \{{invokerPackage}}\ApiClient The default instance of ApiClient */ - protected $defaultHeaders = array(); - - /** @var string The host */ - protected $host = 'http://localhost'; - - /** @var string timeout (second) of the HTTP request, by default set to 0, no timeout */ - protected $curlTimeout = 0; - - /** @var string user agent of the HTTP request, set to "PHP-Swagger" by default */ - protected $userAgent = "PHP-Swagger"; - - /** @var bool Debug switch (default set to false) */ - protected $debug = false; - - /** @var string Debug file location (log to STDOUT by default) */ - protected $debugFile = 'php://output'; - - /** - * @param string $key - * @param string $value - * @return Configuration - */ - public function setApiKey($key, $value) { - $this->apiKeys[$key] = $value; - return $this; - } - - /** - * @param $key - * @return string - */ - public function getApiKey($key) { - return isset($this->apiKeys[$key]) ? $this->apiKeys[$key] : null; - } - - /** - * @param string $key - * @param string $value - * @return Configuration - */ - public function setApiKeyPrefix($key, $value) { - $this->apiKeyPrefixes[$key] = $value; - return $this; - } - - /** - * @param $key - * @return string - */ - public function getApiKeyPrefix($key) { - return isset($this->apiKeyPrefixes[$key]) ? $this->apiKeyPrefixes[$key] : null; - } - - /** - * @param string $username - * @return Configuration - */ - public function setUsername($username) { - $this->username = $username; - return $this; - } - - /** - * @return string - */ - public function getUsername() { - return $this->username; - } - - /** - * @param string $password - * @return Configuration - */ - public function setPassword($password) { - $this->password = $password; - return $this; - } - - /** - * @return string - */ - public function getPassword() { - return $this->password; - } - - /** - * add default header - * - * @param string $headerName header name (e.g. Token) - * @param string $headerValue header value (e.g. 1z8wp3) - * @return ApiClient - */ - public function addDefaultHeader($headerName, $headerValue) { - if (!is_string($headerName)) { - throw new \InvalidArgumentException('Header name must be a string.'); + private static $defaultConfiguration = null; + + /** @var string[] Associate array to store API key(s) */ + protected $apiKeys = array(); + + /** string[] Associate array to store API prefix (e.g. Bearer) */ + protected $apiKeyPrefixes = array(); + + /** @var string Username for HTTP basic authentication */ + protected $username = ''; + + /** @var string Password for HTTP basic authentication */ + protected $password = ''; + + /** @var \{{invokerPackage}}\ApiClient The default instance of ApiClient */ + protected $defaultHeaders = array(); + + /** @var string The host */ + protected $host = 'http://localhost'; + + /** @var string timeout (second) of the HTTP request, by default set to 0, no timeout */ + protected $curlTimeout = 0; + + /** @var string user agent of the HTTP request, set to "PHP-Swagger" by default */ + protected $userAgent = "PHP-Swagger"; + + /** @var bool Debug switch (default set to false) */ + protected $debug = false; + + /** @var string Debug file location (log to STDOUT by default) */ + protected $debugFile = 'php://output'; + + /** + * @param string $key + * @param string $value + * @return Configuration + */ + public function setApiKey($key, $value) { + $this->apiKeys[$key] = $value; + return $this; } - - $this->defaultHeaders[$headerName] = $headerValue; - return $this; - } - - /** - * get the default header - * - * @return array default header - */ - public function getDefaultHeaders() { - return $this->defaultHeaders; - } - - /** - * delete a default header - * @param string $headerName the header to delete - * @return Configuration - */ - public function deleteDefaultHeader($headerName) { - unset($this->defaultHeaders[$headerName]); - } - - /** - * @param string $host - * @return Configuration - */ - public function setHost($host) { - $this->host = $host; - return $this; - } - - /** - * @return string - */ - public function getHost() { - return $this->host; - } - - /** - * set the user agent of the api client - * - * @param string $userAgent the user agent of the api client - * @return ApiClient - */ - public function setUserAgent($userAgent) { - if (!is_string($userAgent)) { - throw new \InvalidArgumentException('User-agent must be a string.'); + + /** + * @param $key + * @return string + */ + public function getApiKey($key) { + return isset($this->apiKeys[$key]) ? $this->apiKeys[$key] : null; } - - $this->userAgent = $userAgent; - return $this; - } - - /** - * get the user agent of the api client - * - * @return string user agent - */ - public function getUserAgent() { - return $this->userAgent; - } - - /** - * set the HTTP timeout value - * - * @param integer $seconds Number of seconds before timing out [set to 0 for no timeout] - * @return ApiClient - */ - public function setCurlTimeout($seconds) { - if (!is_numeric($seconds) || $seconds < 0) { - throw new \InvalidArgumentException('Timeout value must be numeric and a non-negative number.'); + + /** + * @param string $key + * @param string $value + * @return Configuration + */ + public function setApiKeyPrefix($key, $value) { + $this->apiKeyPrefixes[$key] = $value; + return $this; } - - $this->curlTimeout = $seconds; - return $this; - } - - /** - * get the HTTP timeout value - * - * @return string HTTP timeout value - */ - public function getCurlTimeout() { - return $this->curlTimeout; - } - - /** - * @param bool $debug - * @return Configuration - */ - public function setDebug($debug) { - $this->debug = $debug; - return $this; - } - - /** - * @return bool - */ - public function getDebug() { - return $this->debug; - } - - /** - * @param string $debugFile - * @return Configuration - */ - public function setDebugFile($debugFile) { - $this->debugFile = $debugFile; - return $this; - } - - /** - * @return string - */ - public function getDebugFile() { - return $this->debugFile; - } - - /** - * @return Configuration - */ - public static function getDefaultConfiguration() { - if (self::$defaultConfiguration == null) { - return new Configuration(); + + /** + * @param $key + * @return string + */ + public function getApiKeyPrefix($key) { + return isset($this->apiKeyPrefixes[$key]) ? $this->apiKeyPrefixes[$key] : null; } - - return self::$defaultConfiguration; - } - - public static function setDefaultConfiguration(Configuration $config) { - self::$defaultConfiguration = $config; - } - - /* - * return the report for debuggin - */ - public static function toDebugReport() { - $report = "PHP SDK ({{invokerPackage}}) Debug Report:\n"; - $report .= " OS: ".php_uname()."\n"; - $report .= " PHP Version: ".phpversion()."\n"; - $report .= " Swagger Spec Version: {{version}}\n"; - $report .= " SDK Package Version: {{version}}\n"; - - return $report; - } - + + /** + * @param string $username + * @return Configuration + */ + public function setUsername($username) { + $this->username = $username; + return $this; + } + + /** + * @return string + */ + public function getUsername() { + return $this->username; + } + + /** + * @param string $password + * @return Configuration + */ + public function setPassword($password) { + $this->password = $password; + return $this; + } + + /** + * @return string + */ + public function getPassword() { + return $this->password; + } + + /** + * add default header + * + * @param string $headerName header name (e.g. Token) + * @param string $headerValue header value (e.g. 1z8wp3) + * @return ApiClient + */ + public function addDefaultHeader($headerName, $headerValue) { + if (!is_string($headerName)) { + throw new \InvalidArgumentException('Header name must be a string.'); + } + + $this->defaultHeaders[$headerName] = $headerValue; + return $this; + } + + /** + * get the default header + * + * @return array default header + */ + public function getDefaultHeaders() { + return $this->defaultHeaders; + } + + /** + * delete a default header + * @param string $headerName the header to delete + * @return Configuration + */ + public function deleteDefaultHeader($headerName) { + unset($this->defaultHeaders[$headerName]); + } + + /** + * @param string $host + * @return Configuration + */ + public function setHost($host) { + $this->host = $host; + return $this; + } + + /** + * @return string + */ + public function getHost() { + return $this->host; + } + + /** + * set the user agent of the api client + * + * @param string $userAgent the user agent of the api client + * @return ApiClient + */ + public function setUserAgent($userAgent) { + if (!is_string($userAgent)) { + throw new \InvalidArgumentException('User-agent must be a string.'); + } + + $this->userAgent = $userAgent; + return $this; + } + + /** + * get the user agent of the api client + * + * @return string user agent + */ + public function getUserAgent() { + return $this->userAgent; + } + + /** + * set the HTTP timeout value + * + * @param integer $seconds Number of seconds before timing out [set to 0 for no timeout] + * @return ApiClient + */ + public function setCurlTimeout($seconds) { + if (!is_numeric($seconds) || $seconds < 0) { + throw new \InvalidArgumentException('Timeout value must be numeric and a non-negative number.'); + } + + $this->curlTimeout = $seconds; + return $this; + } + + /** + * get the HTTP timeout value + * + * @return string HTTP timeout value + */ + public function getCurlTimeout() { + return $this->curlTimeout; + } + + /** + * @param bool $debug + * @return Configuration + */ + public function setDebug($debug) { + $this->debug = $debug; + return $this; + } + + /** + * @return bool + */ + public function getDebug() { + return $this->debug; + } + + /** + * @param string $debugFile + * @return Configuration + */ + public function setDebugFile($debugFile) { + $this->debugFile = $debugFile; + return $this; + } + + /** + * @return string + */ + public function getDebugFile() { + return $this->debugFile; + } + + /** + * @return Configuration + */ + public static function getDefaultConfiguration() { + if (self::$defaultConfiguration == null) { + return new Configuration(); + } + + return self::$defaultConfiguration; + } + + /** + * @param Configuration $config + */ + public static function setDefaultConfiguration(Configuration $config) { + self::$defaultConfiguration = $config; + } + + /* + * return the report for debugging + */ + public static function toDebugReport() { + $report = "PHP SDK ({{invokerPackage}}) Debug Report:\n"; + $report .= " OS: ".php_uname()."\n"; + $report .= " PHP Version: ".phpversion()."\n"; + $report .= " Swagger Spec Version: {{version}}\n"; + $report .= " SDK Package Version: {{version}}\n"; + + return $report; + } + } diff --git a/modules/swagger-codegen/src/main/resources/php/model.mustache b/modules/swagger-codegen/src/main/resources/php/model.mustache index 1d241529538f..9b8307f6ec47 100644 --- a/modules/swagger-codegen/src/main/resources/php/model.mustache +++ b/modules/swagger-codegen/src/main/resources/php/model.mustache @@ -29,82 +29,82 @@ namespace {{modelPackage}}; use \ArrayAccess; class {{classname}} implements ArrayAccess { - /** @var string[] Array of property to type mappings. Used for (de)serialization */ - static $swaggerTypes = array( - {{#vars}}'{{name}}' => '{{{datatype}}}'{{#hasMore}}, - {{/hasMore}}{{/vars}} - ); - - /** @var string[] Array of attributes where the key is the local name, and the value is the original name */ - static $attributeMap = array( - {{#vars}}'{{name}}' => '{{baseName}}'{{#hasMore}}, - {{/hasMore}}{{/vars}} - ); - - /** @var string[] Array of attributes to setter functions (for deserialization of responses) */ - static $setters = array( - {{#vars}}'{{name}}' => '{{setter}}'{{#hasMore}}, - {{/hasMore}}{{/vars}} - ); - - /** @var string[] Array of attributes to getter functions (for serialization of requests) */ - static $getters = array( - {{#vars}}'{{name}}' => '{{getter}}'{{#hasMore}}, - {{/hasMore}}{{/vars}} - ); - - {{#vars}} - /** @var {{datatype}} ${{name}} {{#description}}{{{description}}} {{/description}}*/ - protected ${{name}}; - {{/vars}} - public function __construct(array $data = null) { - if ($data != null) { - {{#vars}}$this->{{name}} = $data["{{name}}"];{{#hasMore}} - {{/hasMore}}{{/vars}} + /** @var string[] Array of property to type mappings. Used for (de)serialization */ + static $swaggerTypes = array( + {{#vars}}'{{name}}' => '{{{datatype}}}'{{#hasMore}}, + {{/hasMore}}{{/vars}} + ); + + /** @var string[] Array of attributes where the key is the local name, and the value is the original name */ + static $attributeMap = array( + {{#vars}}'{{name}}' => '{{baseName}}'{{#hasMore}}, + {{/hasMore}}{{/vars}} + ); + + /** @var string[] Array of attributes to setter functions (for deserialization of responses) */ + static $setters = array( + {{#vars}}'{{name}}' => '{{setter}}'{{#hasMore}}, + {{/hasMore}}{{/vars}} + ); + + /** @var string[] Array of attributes to getter functions (for serialization of requests) */ + static $getters = array( + {{#vars}}'{{name}}' => '{{getter}}'{{#hasMore}}, + {{/hasMore}}{{/vars}} + ); + + {{#vars}} + /** @var {{datatype}} ${{name}} {{#description}}{{{description}}} {{/description}}*/ + protected ${{name}}; + {{/vars}} + public function __construct(array $data = null) { + if ($data != null) { + {{#vars}}$this->{{name}} = $data["{{name}}"];{{#hasMore}} + {{/hasMore}}{{/vars}} + } } - } - {{#vars}} - /** - * get {{name}} - * @return {{datatype}} - */ - public function {{getter}}() { - return $this->{{name}}; - } - - /** - * set {{name}} - * @param {{datatype}} ${{name}} - * @return $this - */ - public function {{setter}}(${{name}}) { - $this->{{name}} = ${{name}}; - return $this; - } - {{/vars}} - public function offsetExists($offset) { - return isset($this->$offset); - } - - public function offsetGet($offset) { - return $this->$offset; - } - - public function offsetSet($offset, $value) { - $this->$offset = $value; - } - - public function offsetUnset($offset) { - unset($this->$offset); - } - - public function __toString() { - if (defined('JSON_PRETTY_PRINT')) { - return json_encode(get_object_vars($this), JSON_PRETTY_PRINT); - } else { - return json_encode(get_object_vars($this)); + {{#vars}} + /** + * get {{name}} + * @return {{datatype}} + */ + public function {{getter}}() { + return $this->{{name}}; + } + + /** + * set {{name}} + * @param {{datatype}} ${{name}} + * @return $this + */ + public function {{setter}}(${{name}}) { + $this->{{name}} = ${{name}}; + return $this; + } + {{/vars}} + public function offsetExists($offset) { + return isset($this->$offset); + } + + public function offsetGet($offset) { + return $this->$offset; + } + + public function offsetSet($offset, $value) { + $this->$offset = $value; + } + + public function offsetUnset($offset) { + unset($this->$offset); + } + + public function __toString() { + if (defined('JSON_PRETTY_PRINT')) { + return json_encode(get_object_vars($this), JSON_PRETTY_PRINT); + } else { + return json_encode(get_object_vars($this)); + } } - } } {{/model}} {{/models}} diff --git a/modules/swagger-codegen/src/test/resources/2_0/petstore.json b/modules/swagger-codegen/src/test/resources/2_0/petstore.json index 66762d74b2bc..df781a90c494 100644 --- a/modules/swagger-codegen/src/test/resources/2_0/petstore.json +++ b/modules/swagger-codegen/src/test/resources/2_0/petstore.json @@ -235,7 +235,7 @@ "200": { "description": "successful operation", "schema": { - "$ref": "#/definitions/Pet" + "type": "file" } }, "400": { diff --git a/samples/client/petstore/php/SwaggerClient-php/composer.json b/samples/client/petstore/php/SwaggerClient-php/composer.json index db0fe7cd5b93..5a76d804876b 100644 --- a/samples/client/petstore/php/SwaggerClient-php/composer.json +++ b/samples/client/petstore/php/SwaggerClient-php/composer.json @@ -1,32 +1,32 @@ { - "name": "swagger/swagger-client", - "description": "", - "keywords": [ - "swagger", - "php", - "sdk", - "api" - ], - "homepage": "http://swagger.io", - "license": "Apache v2", - "authors": [ - { - "name": "Swagger and contributors", - "homepage": "https://github.com/swagger-api/swagger-codegen" + "name": "swagger/swagger-client", + "description": "", + "keywords": [ + "swagger", + "php", + "sdk", + "api" + ], + "homepage": "http://swagger.io", + "license": "Apache v2", + "authors": [ + { + "name": "Swagger and contributors", + "homepage": "https://github.com/swagger-api/swagger-codegen" + } + ], + "require": { + "php": ">=5.3.3", + "ext-curl": "*", + "ext-json": "*", + "ext-mbstring": "*" + }, + "require-dev": { + "phpunit/phpunit": "~4.0", + "satooshi/php-coveralls": "~0.6.1", + "squizlabs/php_codesniffer": "~2.0" + }, + "autoload": { + "psr-4": { "Swagger\\Client\\" : "lib/" } } - ], - "require": { - "php": ">=5.3.3", - "ext-curl": "*", - "ext-json": "*", - "ext-mbstring": "*" - }, - "require-dev": { - "phpunit/phpunit": "~4.0", - "satooshi/php-coveralls": "~0.6.1", - "squizlabs/php_codesniffer": "~2.0" - }, - "autoload": { - "psr-4": { "Swagger\\Client\\" : "lib/" } - } } 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 64ef731c4b0f..54926f3c9f74 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php @@ -29,606 +29,603 @@ use \Swagger\Client\ObjectSerializer; class PetApi { - /** @var \Swagger\Client\ApiClient instance of the ApiClient */ - private $apiClient; - - /** - * @param \Swagger\Client\ApiClient|null $apiClient The api client to use - */ - function __construct($apiClient = null) { - if ($apiClient == null) { - $apiClient = new ApiClient(); - $apiClient->getConfig()->setHost('http://petstore.swagger.io/v2'); + /** @var \Swagger\Client\ApiClient instance of the ApiClient */ + private $apiClient; + + /** + * @param \Swagger\Client\ApiClient|null $apiClient The api client to use + */ + function __construct($apiClient = null) { + if ($apiClient == null) { + $apiClient = new ApiClient(); + $apiClient->getConfig()->setHost('http://petstore.swagger.io/v2'); + } + + $this->apiClient = $apiClient; } - - $this->apiClient = $apiClient; - } - - /** - * @return \Swagger\Client\ApiClient get the API client - */ - public function getApiClient() { - return $this->apiClient; - } - - /** - * @param \Swagger\Client\ApiClient $apiClient set the API client - * @return PetApi - */ - public function setApiClient(ApiClient $apiClient) { - $this->apiClient = $apiClient; - return $this; - } - - /** - * updatePet - * - * Update an existing pet - * - * @param \Swagger\Client\Model\Pet $body Pet object that needs to be added to the store (required) - * @return void - * @throws \Swagger\Client\ApiException on non-2xx response - */ - public function updatePet($body) { - - - // parse inputs - $resourcePath = "/pet"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "PUT"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array('application/json','application/xml')); - - - - - - // body params - $_tempBody = null; - if (isset($body)) { - $_tempBody = $body; - } - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - - //TODO support oauth - - // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - } catch (ApiException $e) { - switch ($e->getCode()) { + /** + * @return \Swagger\Client\ApiClient get the API client + */ + public function getApiClient() { + return $this->apiClient; + } + + /** + * @param \Swagger\Client\ApiClient $apiClient set the API client + * @return PetApi + */ + public function setApiClient(ApiClient $apiClient) { + $this->apiClient = $apiClient; + return $this; + } + + + /** + * updatePet + * + * Update an existing pet + * + * @param \Swagger\Client\Model\Pet $body Pet object that needs to be added to the store (required) + * @return void + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function updatePet($body) { + + + // parse inputs + $resourcePath = "/pet"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "PUT"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; } - - throw $e; - } - - } + $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array('application/json','application/xml')); - /** - * addPet - * - * Add a new pet to the store - * - * @param \Swagger\Client\Model\Pet $body Pet object that needs to be added to the store (required) - * @return void - * @throws \Swagger\Client\ApiException on non-2xx response - */ - public function addPet($body) { - - - // parse inputs - $resourcePath = "/pet"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array('application/json','application/xml')); - - - - - - // body params - $_tempBody = null; - if (isset($body)) { - $_tempBody = $body; - } - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - - //TODO support oauth - - // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - } catch (ApiException $e) { - switch ($e->getCode()) { + + + + + // body params + $_tempBody = null; + if (isset($body)) { + $_tempBody = $body; } - - throw $e; - } - - } - /** - * findPetsByStatus - * - * Finds Pets by status - * - * @param string[] $status Status values that need to be considered for filter (required) - * @return \Swagger\Client\Model\Pet[] - * @throws \Swagger\Client\ApiException on non-2xx response - */ - public function findPetsByStatus($status) { - - - // parse inputs - $resourcePath = "/pet/findByStatus"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array()); - - // query params - if($status !== null) { - $queryParams['status'] = $this->apiClient->getSerializer()->toQueryValue($status); - } - - - - - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - - //TODO support oauth - - // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams, '\Swagger\Client\Model\Pet[]'); - } catch (ApiException $e) { - switch ($e->getCode()) { - case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Pet[]', $httpHeader); - $e->setResponseObject($data); - break; + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; } - - throw $e; - } - - if (!$response) { - return null; - } - - $responseObject = $this->apiClient->getSerializer()->deserialize($response,'\Swagger\Client\Model\Pet[]'); - return $responseObject; - - } + + + //TODO support oauth + + // make the API Call + try { + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + } catch (ApiException $e) { + switch ($e->getCode()) { + } - /** - * findPetsByTags - * - * Finds Pets by tags - * - * @param string[] $tags Tags to filter by (required) - * @return \Swagger\Client\Model\Pet[] - * @throws \Swagger\Client\ApiException on non-2xx response - */ - public function findPetsByTags($tags) { - - - // parse inputs - $resourcePath = "/pet/findByTags"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array()); - - // query params - if($tags !== null) { - $queryParams['tags'] = $this->apiClient->getSerializer()->toQueryValue($tags); - } - - - - - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - - //TODO support oauth - - // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams, '\Swagger\Client\Model\Pet[]'); - } catch (ApiException $e) { - switch ($e->getCode()) { - case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Pet[]', $httpHeader); - $e->setResponseObject($data); - break; + throw $e; } - - throw $e; - } - - if (!$response) { - return null; - } - - $responseObject = $this->apiClient->getSerializer()->deserialize($response,'\Swagger\Client\Model\Pet[]'); - return $responseObject; - - } + + } + + /** + * addPet + * + * Add a new pet to the store + * + * @param \Swagger\Client\Model\Pet $body Pet object that needs to be added to the store (required) + * @return void + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function addPet($body) { + - /** - * getPetById - * - * Find pet by ID - * - * @param int $pet_id ID of pet that needs to be fetched (required) - * @return \Swagger\Client\Model\Pet - * @throws \Swagger\Client\ApiException on non-2xx response - */ - public function getPetById($pet_id) { - - // verify the required parameter 'pet_id' is set - if ($pet_id === null) { - throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling getPetById'); - } - - - // parse inputs - $resourcePath = "/pet/{petId}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array()); - - - - // path params - if($pet_id !== null) { - $resourcePath = str_replace("{" . "petId" . "}", - $this->apiClient->getSerializer()->toPathValue($pet_id), - $resourcePath); - } - - - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - $apiKey = $this->apiClient->getApiKeyWithPrefix('api_key'); - if (isset($apiKey)) { - $headerParams['api_key'] = $apiKey; - } - - - - - //TODO support oauth - - // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams, '\Swagger\Client\Model\Pet'); - } catch (ApiException $e) { - switch ($e->getCode()) { - case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Pet', $httpHeader); - $e->setResponseObject($data); - break; + // parse inputs + $resourcePath = "/pet"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "POST"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; } - - throw $e; - } - - if (!$response) { - return null; - } - - $responseObject = $this->apiClient->getSerializer()->deserialize($response,'\Swagger\Client\Model\Pet'); - return $responseObject; - - } + $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array('application/json','application/xml')); - /** - * updatePetWithForm - * - * 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 (required) - * @param string $status Updated status of the pet (required) - * @return void - * @throws \Swagger\Client\ApiException on non-2xx response - */ - public function updatePetWithForm($pet_id, $name, $status) { - - // verify the required parameter 'pet_id' is set - if ($pet_id === null) { - throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling updatePetWithForm'); - } - - - // parse inputs - $resourcePath = "/pet/{petId}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array('application/x-www-form-urlencoded')); - - - - // path params - if($pet_id !== null) { - $resourcePath = str_replace("{" . "petId" . "}", - $this->apiClient->getSerializer()->toPathValue($pet_id), - $resourcePath); - } - // form params - if ($name !== null) { - $formParams['name'] = $this->apiClient->getSerializer()->toFormValue($name); - }// form params - if ($status !== null) { - $formParams['status'] = $this->apiClient->getSerializer()->toFormValue($status); - } - - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - - //TODO support oauth - - // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - } catch (ApiException $e) { - switch ($e->getCode()) { + + + + + // body params + $_tempBody = null; + if (isset($body)) { + $_tempBody = $body; } - - throw $e; - } - - } - /** - * deletePet - * - * Deletes a pet - * - * @param string $api_key (required) - * @param int $pet_id Pet id to delete (required) - * @return void - * @throws \Swagger\Client\ApiException on non-2xx response - */ - public function deletePet($api_key, $pet_id) { - - // verify the required parameter 'pet_id' is set - if ($pet_id === null) { - throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling deletePet'); - } - - - // parse inputs - $resourcePath = "/pet/{petId}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "DELETE"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array()); - - - // header params - if($api_key !== null) { - $headerParams['api_key'] = $this->apiClient->getSerializer()->toHeaderValue($api_key); - } - // path params - if($pet_id !== null) { - $resourcePath = str_replace("{" . "petId" . "}", - $this->apiClient->getSerializer()->toPathValue($pet_id), - $resourcePath); - } - - - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - - //TODO support oauth - - // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - } catch (ApiException $e) { - switch ($e->getCode()) { + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; } - - throw $e; - } - - } + + + //TODO support oauth + + // make the API Call + try { + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + } catch (ApiException $e) { + switch ($e->getCode()) { + } - /** - * uploadFile - * - * uploads an image - * - * @param int $pet_id ID of pet to update (required) - * @param string $additional_metadata Additional data to pass to server (required) - * @param \SplFileObject $file file to upload (required) - * @return void - * @throws \Swagger\Client\ApiException on non-2xx response - */ - public function uploadFile($pet_id, $additional_metadata, $file) { - - // verify the required parameter 'pet_id' is set - if ($pet_id === null) { - throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling uploadFile'); - } - - - // parse inputs - $resourcePath = "/pet/{petId}/uploadImage"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array('multipart/form-data')); - - - - // path params - if($pet_id !== null) { - $resourcePath = str_replace("{" . "petId" . "}", - $this->apiClient->getSerializer()->toPathValue($pet_id), - $resourcePath); - } - // form params - if ($additional_metadata !== null) { - $formParams['additionalMetadata'] = $this->apiClient->getSerializer()->toFormValue($additional_metadata); - }// form params - if ($file !== null) { - $formParams['file'] = '@' . $this->apiClient->getSerializer()->toFormValue($file); - } - - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - - //TODO support oauth - - // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - } catch (ApiException $e) { - switch ($e->getCode()) { + throw $e; } - - throw $e; - } - - } + + } + + /** + * findPetsByStatus + * + * Finds Pets by status + * + * @param string[] $status Status values that need to be considered for filter (required) + * @return \Swagger\Client\Model\Pet[] + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function findPetsByStatus($status) { + + // parse inputs + $resourcePath = "/pet/findByStatus"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "GET"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array()); + + // query params + if($status !== null) { + $queryParams['status'] = $this->apiClient->getSerializer()->toQueryValue($status); + } + + + + + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; + } + + + //TODO support oauth + + // make the API Call + try { + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, + $queryParams, $httpBody, + $headerParams, '\Swagger\Client\Model\Pet[]'); + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Pet[]', $httpHeader); + $e->setResponseObject($data); + break; + } + + throw $e; + } + + if (!$response) { + return null; + } + + return $this->apiClient->getSerializer()->deserialize($response,'\Swagger\Client\Model\Pet[]'); + + } + + /** + * findPetsByTags + * + * Finds Pets by tags + * + * @param string[] $tags Tags to filter by (required) + * @return \Swagger\Client\Model\Pet[] + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function findPetsByTags($tags) { + + + // parse inputs + $resourcePath = "/pet/findByTags"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "GET"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array()); + + // query params + if($tags !== null) { + $queryParams['tags'] = $this->apiClient->getSerializer()->toQueryValue($tags); + } + + + + + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; + } + + + //TODO support oauth + + // make the API Call + try { + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, + $queryParams, $httpBody, + $headerParams, '\Swagger\Client\Model\Pet[]'); + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Pet[]', $httpHeader); + $e->setResponseObject($data); + break; + } + + throw $e; + } + + if (!$response) { + return null; + } + + return $this->apiClient->getSerializer()->deserialize($response,'\Swagger\Client\Model\Pet[]'); + + } + + /** + * getPetById + * + * Find pet by ID + * + * @param int $pet_id ID of pet that needs to be fetched (required) + * @return \SplFileObject + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function getPetById($pet_id) { + + // verify the required parameter 'pet_id' is set + if ($pet_id === null) { + throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling getPetById'); + } + + + // parse inputs + $resourcePath = "/pet/{petId}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "GET"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array()); + + + + // path params + if($pet_id !== null) { + $resourcePath = str_replace("{" . "petId" . "}", + $this->apiClient->getSerializer()->toPathValue($pet_id), + $resourcePath); + } + + + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; + } + + $apiKey = $this->apiClient->getApiKeyWithPrefix('api_key'); + if (isset($apiKey)) { + $headerParams['api_key'] = $apiKey; + } + + + + + //TODO support oauth + + // make the API Call + try { + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, + $queryParams, $httpBody, + $headerParams, '\SplFileObject'); + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\SplFileObject', $httpHeader); + $e->setResponseObject($data); + break; + } + + throw $e; + } + + if (!$response) { + return null; + } + + return $this->apiClient->getSerializer()->deserialize($response,'\SplFileObject'); + + } + + /** + * updatePetWithForm + * + * 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 (required) + * @param string $status Updated status of the pet (required) + * @return void + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function updatePetWithForm($pet_id, $name, $status) { + + // verify the required parameter 'pet_id' is set + if ($pet_id === null) { + throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling updatePetWithForm'); + } + + + // parse inputs + $resourcePath = "/pet/{petId}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "POST"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array('application/x-www-form-urlencoded')); + + + + // path params + if($pet_id !== null) { + $resourcePath = str_replace("{" . "petId" . "}", + $this->apiClient->getSerializer()->toPathValue($pet_id), + $resourcePath); + } + // form params + if ($name !== null) { + $formParams['name'] = $this->apiClient->getSerializer()->toFormValue($name); + }// form params + if ($status !== null) { + $formParams['status'] = $this->apiClient->getSerializer()->toFormValue($status); + } + + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; + } + + + //TODO support oauth + + // make the API Call + try { + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + } catch (ApiException $e) { + switch ($e->getCode()) { + } + + throw $e; + } + + } + + /** + * deletePet + * + * Deletes a pet + * + * @param string $api_key (required) + * @param int $pet_id Pet id to delete (required) + * @return void + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function deletePet($api_key, $pet_id) { + + // verify the required parameter 'pet_id' is set + if ($pet_id === null) { + throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling deletePet'); + } + + + // parse inputs + $resourcePath = "/pet/{petId}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "DELETE"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array()); + + + // header params + if($api_key !== null) { + $headerParams['api_key'] = $this->apiClient->getSerializer()->toHeaderValue($api_key); + } + // path params + if($pet_id !== null) { + $resourcePath = str_replace("{" . "petId" . "}", + $this->apiClient->getSerializer()->toPathValue($pet_id), + $resourcePath); + } + + + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; + } + + + //TODO support oauth + + // make the API Call + try { + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + } catch (ApiException $e) { + switch ($e->getCode()) { + } + + throw $e; + } + + } + + /** + * uploadFile + * + * uploads an image + * + * @param int $pet_id ID of pet to update (required) + * @param string $additional_metadata Additional data to pass to server (required) + * @param \SplFileObject $file file to upload (required) + * @return void + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function uploadFile($pet_id, $additional_metadata, $file) { + + // verify the required parameter 'pet_id' is set + if ($pet_id === null) { + throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling uploadFile'); + } + + + // parse inputs + $resourcePath = "/pet/{petId}/uploadImage"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "POST"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array('multipart/form-data')); + + + + // path params + if($pet_id !== null) { + $resourcePath = str_replace("{" . "petId" . "}", + $this->apiClient->getSerializer()->toPathValue($pet_id), + $resourcePath); + } + // form params + if ($additional_metadata !== null) { + $formParams['additionalMetadata'] = $this->apiClient->getSerializer()->toFormValue($additional_metadata); + }// form params + if ($file !== null) { + $formParams['file'] = '@' . $this->apiClient->getSerializer()->toFormValue($file); + } + + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; + } + + + //TODO support oauth + + // make the API Call + try { + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + } 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 c047182133d5..a132b3e3ef5d 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php @@ -29,315 +29,312 @@ use \Swagger\Client\ObjectSerializer; class StoreApi { - /** @var \Swagger\Client\ApiClient instance of the ApiClient */ - private $apiClient; - - /** - * @param \Swagger\Client\ApiClient|null $apiClient The api client to use - */ - function __construct($apiClient = null) { - if ($apiClient == null) { - $apiClient = new ApiClient(); - $apiClient->getConfig()->setHost('http://petstore.swagger.io/v2'); + /** @var \Swagger\Client\ApiClient instance of the ApiClient */ + private $apiClient; + + /** + * @param \Swagger\Client\ApiClient|null $apiClient The api client to use + */ + function __construct($apiClient = null) { + if ($apiClient == null) { + $apiClient = new ApiClient(); + $apiClient->getConfig()->setHost('http://petstore.swagger.io/v2'); + } + + $this->apiClient = $apiClient; } - - $this->apiClient = $apiClient; - } - - /** - * @return \Swagger\Client\ApiClient get the API client - */ - public function getApiClient() { - return $this->apiClient; - } - - /** - * @param \Swagger\Client\ApiClient $apiClient set the API client - * @return StoreApi - */ - public function setApiClient(ApiClient $apiClient) { - $this->apiClient = $apiClient; - return $this; - } - - /** - * getInventory - * - * Returns pet inventories by status - * - * @return map[string,int] - * @throws \Swagger\Client\ApiException on non-2xx response - */ - public function getInventory() { - - - // parse inputs - $resourcePath = "/store/inventory"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array()); - - - - - - - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - $apiKey = $this->apiClient->getApiKeyWithPrefix('api_key'); - if (isset($apiKey)) { - $headerParams['api_key'] = $apiKey; - } - - - - // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams, 'map[string,int]'); - } catch (ApiException $e) { - switch ($e->getCode()) { - case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), 'map[string,int]', $httpHeader); - $e->setResponseObject($data); - break; + /** + * @return \Swagger\Client\ApiClient get the API client + */ + public function getApiClient() { + return $this->apiClient; + } + + /** + * @param \Swagger\Client\ApiClient $apiClient set the API client + * @return StoreApi + */ + public function setApiClient(ApiClient $apiClient) { + $this->apiClient = $apiClient; + return $this; + } + + + /** + * getInventory + * + * Returns pet inventories by status + * + * @return map[string,int] + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function getInventory() { + + + // parse inputs + $resourcePath = "/store/inventory"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "GET"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; } - - throw $e; - } - - if (!$response) { - return null; - } - - $responseObject = $this->apiClient->getSerializer()->deserialize($response,'map[string,int]'); - return $responseObject; - - } + $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array()); - /** - * placeOrder - * - * Place an order for a pet - * - * @param \Swagger\Client\Model\Order $body order placed for purchasing the pet (required) - * @return \Swagger\Client\Model\Order - * @throws \Swagger\Client\ApiException on non-2xx response - */ - public function placeOrder($body) { - - - // parse inputs - $resourcePath = "/store/order"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array()); - - - - - - // body params - $_tempBody = null; - if (isset($body)) { - $_tempBody = $body; - } - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams, '\Swagger\Client\Model\Order'); - } catch (ApiException $e) { - switch ($e->getCode()) { - case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Order', $httpHeader); - $e->setResponseObject($data); - break; + + + + + + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; } - - throw $e; - } - - if (!$response) { - return null; - } - - $responseObject = $this->apiClient->getSerializer()->deserialize($response,'\Swagger\Client\Model\Order'); - return $responseObject; - - } - - /** - * getOrderById - * - * Find purchase order by ID - * - * @param string $order_id ID of pet that needs to be fetched (required) - * @return \Swagger\Client\Model\Order - * @throws \Swagger\Client\ApiException on non-2xx response - */ - public function getOrderById($order_id) { - - // verify the required parameter 'order_id' is set - if ($order_id === null) { - throw new \InvalidArgumentException('Missing the required parameter $order_id when calling getOrderById'); - } - - - // parse inputs - $resourcePath = "/store/order/{orderId}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array()); - - - - // path params - if($order_id !== null) { - $resourcePath = str_replace("{" . "orderId" . "}", - $this->apiClient->getSerializer()->toPathValue($order_id), - $resourcePath); - } - - - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams, '\Swagger\Client\Model\Order'); - } catch (ApiException $e) { - switch ($e->getCode()) { - case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Order', $httpHeader); - $e->setResponseObject($data); - break; + + $apiKey = $this->apiClient->getApiKeyWithPrefix('api_key'); + if (isset($apiKey)) { + $headerParams['api_key'] = $apiKey; } - - throw $e; - } - - if (!$response) { - return null; - } - - $responseObject = $this->apiClient->getSerializer()->deserialize($response,'\Swagger\Client\Model\Order'); - return $responseObject; - - } + + + + // make the API Call + try { + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, + $queryParams, $httpBody, + $headerParams, 'map[string,int]'); + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), 'map[string,int]', $httpHeader); + $e->setResponseObject($data); + break; + } - /** - * deleteOrder - * - * Delete purchase order by ID - * - * @param string $order_id ID of the order that needs to be deleted (required) - * @return void - * @throws \Swagger\Client\ApiException on non-2xx response - */ - public function deleteOrder($order_id) { - - // verify the required parameter 'order_id' is set - if ($order_id === null) { - throw new \InvalidArgumentException('Missing the required parameter $order_id when calling deleteOrder'); - } - - - // parse inputs - $resourcePath = "/store/order/{orderId}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "DELETE"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array()); - - - - // path params - if($order_id !== null) { - $resourcePath = str_replace("{" . "orderId" . "}", - $this->apiClient->getSerializer()->toPathValue($order_id), - $resourcePath); - } - - - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - } catch (ApiException $e) { - switch ($e->getCode()) { + throw $e; + } + + if (!$response) { + return null; } - - throw $e; - } - - } + return $this->apiClient->getSerializer()->deserialize($response,'map[string,int]'); + + } + + /** + * placeOrder + * + * Place an order for a pet + * + * @param \Swagger\Client\Model\Order $body order placed for purchasing the pet (required) + * @return \Swagger\Client\Model\Order + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function placeOrder($body) { + + + // parse inputs + $resourcePath = "/store/order"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "POST"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array()); + + + + + + // body params + $_tempBody = null; + if (isset($body)) { + $_tempBody = $body; + } + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; + } + + // make the API Call + try { + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, + $queryParams, $httpBody, + $headerParams, '\Swagger\Client\Model\Order'); + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Order', $httpHeader); + $e->setResponseObject($data); + break; + } + + throw $e; + } + + if (!$response) { + return null; + } + + return $this->apiClient->getSerializer()->deserialize($response,'\Swagger\Client\Model\Order'); + + } + + /** + * getOrderById + * + * Find purchase order by ID + * + * @param string $order_id ID of pet that needs to be fetched (required) + * @return \Swagger\Client\Model\Order + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function getOrderById($order_id) { + + // verify the required parameter 'order_id' is set + if ($order_id === null) { + throw new \InvalidArgumentException('Missing the required parameter $order_id when calling getOrderById'); + } + + + // parse inputs + $resourcePath = "/store/order/{orderId}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "GET"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array()); + + + + // path params + if($order_id !== null) { + $resourcePath = str_replace("{" . "orderId" . "}", + $this->apiClient->getSerializer()->toPathValue($order_id), + $resourcePath); + } + + + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; + } + + // make the API Call + try { + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, + $queryParams, $httpBody, + $headerParams, '\Swagger\Client\Model\Order'); + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Order', $httpHeader); + $e->setResponseObject($data); + break; + } + + throw $e; + } + + if (!$response) { + return null; + } + + return $this->apiClient->getSerializer()->deserialize($response,'\Swagger\Client\Model\Order'); + + } + + /** + * deleteOrder + * + * Delete purchase order by ID + * + * @param string $order_id ID of the order that needs to be deleted (required) + * @return void + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function deleteOrder($order_id) { + + // verify the required parameter 'order_id' is set + if ($order_id === null) { + throw new \InvalidArgumentException('Missing the required parameter $order_id when calling deleteOrder'); + } + + + // parse inputs + $resourcePath = "/store/order/{orderId}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "DELETE"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array()); + + + + // path params + if($order_id !== null) { + $resourcePath = str_replace("{" . "orderId" . "}", + $this->apiClient->getSerializer()->toPathValue($order_id), + $resourcePath); + } + + + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; + } + + // make the API Call + try { + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + } 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 d9f2a08ccb8f..62204e182e79 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php @@ -29,543 +29,541 @@ use \Swagger\Client\ObjectSerializer; class UserApi { - /** @var \Swagger\Client\ApiClient instance of the ApiClient */ - private $apiClient; - - /** - * @param \Swagger\Client\ApiClient|null $apiClient The api client to use - */ - function __construct($apiClient = null) { - if ($apiClient == null) { - $apiClient = new ApiClient(); - $apiClient->getConfig()->setHost('http://petstore.swagger.io/v2'); + /** @var \Swagger\Client\ApiClient instance of the ApiClient */ + private $apiClient; + + /** + * @param \Swagger\Client\ApiClient|null $apiClient The api client to use + */ + function __construct($apiClient = null) { + if ($apiClient == null) { + $apiClient = new ApiClient(); + $apiClient->getConfig()->setHost('http://petstore.swagger.io/v2'); + } + + $this->apiClient = $apiClient; } - - $this->apiClient = $apiClient; - } - - /** - * @return \Swagger\Client\ApiClient get the API client - */ - public function getApiClient() { - return $this->apiClient; - } - - /** - * @param \Swagger\Client\ApiClient $apiClient set the API client - * @return UserApi - */ - public function setApiClient(ApiClient $apiClient) { - $this->apiClient = $apiClient; - return $this; - } - - /** - * createUser - * - * Create user - * - * @param \Swagger\Client\Model\User $body Created user object (required) - * @return void - * @throws \Swagger\Client\ApiException on non-2xx response - */ - public function createUser($body) { - - - // parse inputs - $resourcePath = "/user"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array()); - - - - - - // body params - $_tempBody = null; - if (isset($body)) { - $_tempBody = $body; - } - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - } catch (ApiException $e) { - switch ($e->getCode()) { + /** + * @return \Swagger\Client\ApiClient get the API client + */ + public function getApiClient() { + return $this->apiClient; + } + + /** + * @param \Swagger\Client\ApiClient $apiClient set the API client + * @return UserApi + */ + public function setApiClient(ApiClient $apiClient) { + $this->apiClient = $apiClient; + return $this; + } + + + /** + * createUser + * + * Create user + * + * @param \Swagger\Client\Model\User $body Created user object (required) + * @return void + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function createUser($body) { + + + // parse inputs + $resourcePath = "/user"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "POST"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; } - - throw $e; - } - - } + $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array()); - /** - * createUsersWithArrayInput - * - * Creates list of users with given input array - * - * @param \Swagger\Client\Model\User[] $body List of user object (required) - * @return void - * @throws \Swagger\Client\ApiException on non-2xx response - */ - public function createUsersWithArrayInput($body) { - - - // parse inputs - $resourcePath = "/user/createWithArray"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array()); - - - - - - // body params - $_tempBody = null; - if (isset($body)) { - $_tempBody = $body; - } - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - } catch (ApiException $e) { - switch ($e->getCode()) { + + + + + // body params + $_tempBody = null; + if (isset($body)) { + $_tempBody = $body; } - - throw $e; - } - - } - /** - * createUsersWithListInput - * - * Creates list of users with given input array - * - * @param \Swagger\Client\Model\User[] $body List of user object (required) - * @return void - * @throws \Swagger\Client\ApiException on non-2xx response - */ - public function createUsersWithListInput($body) { - - - // parse inputs - $resourcePath = "/user/createWithList"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array()); - - - - - - // body params - $_tempBody = null; - if (isset($body)) { - $_tempBody = $body; - } - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - } catch (ApiException $e) { - switch ($e->getCode()) { + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; } - - throw $e; - } - - } + + // make the API Call + try { + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + } catch (ApiException $e) { + switch ($e->getCode()) { + } - /** - * loginUser - * - * Logs user into the system - * - * @param string $username The user name for login (required) - * @param string $password The password for login in clear text (required) - * @return string - * @throws \Swagger\Client\ApiException on non-2xx response - */ - public function loginUser($username, $password) { - - - // parse inputs - $resourcePath = "/user/login"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array()); - - // query params - if($username !== null) { - $queryParams['username'] = $this->apiClient->getSerializer()->toQueryValue($username); - }// query params - if($password !== null) { - $queryParams['password'] = $this->apiClient->getSerializer()->toQueryValue($password); - } - - - - - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams, 'string'); - } catch (ApiException $e) { - switch ($e->getCode()) { - case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), 'string', $httpHeader); - $e->setResponseObject($data); - break; + throw $e; } - - throw $e; - } - - if (!$response) { - return null; - } - - $responseObject = $this->apiClient->getSerializer()->deserialize($response,'string'); - return $responseObject; - - } + + } + + /** + * createUsersWithArrayInput + * + * Creates list of users with given input array + * + * @param \Swagger\Client\Model\User[] $body List of user object (required) + * @return void + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function createUsersWithArrayInput($body) { + - /** - * logoutUser - * - * Logs out current logged in user session - * - * @return void - * @throws \Swagger\Client\ApiException on non-2xx response - */ - public function logoutUser() { - - - // parse inputs - $resourcePath = "/user/logout"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array()); - - - - - - - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - } catch (ApiException $e) { - switch ($e->getCode()) { + // parse inputs + $resourcePath = "/user/createWithArray"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "POST"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; } - - throw $e; - } - - } + $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array()); - /** - * getUserByName - * - * Get user by user name - * - * @param string $username The name that needs to be fetched. Use user1 for testing. (required) - * @return \Swagger\Client\Model\User - * @throws \Swagger\Client\ApiException on non-2xx response - */ - public function getUserByName($username) { - - // verify the required parameter 'username' is set - if ($username === null) { - throw new \InvalidArgumentException('Missing the required parameter $username when calling getUserByName'); - } - - - // parse inputs - $resourcePath = "/user/{username}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array()); - - - - // path params - if($username !== null) { - $resourcePath = str_replace("{" . "username" . "}", - $this->apiClient->getSerializer()->toPathValue($username), - $resourcePath); - } - - - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams, '\Swagger\Client\Model\User'); - } catch (ApiException $e) { - switch ($e->getCode()) { - case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\User', $httpHeader); - $e->setResponseObject($data); - break; + + + + + // body params + $_tempBody = null; + if (isset($body)) { + $_tempBody = $body; } - - throw $e; - } - - if (!$response) { - return null; - } - - $responseObject = $this->apiClient->getSerializer()->deserialize($response,'\Swagger\Client\Model\User'); - return $responseObject; - - } - /** - * updateUser - * - * Updated user - * - * @param string $username name that need to be deleted (required) - * @param \Swagger\Client\Model\User $body Updated user object (required) - * @return void - * @throws \Swagger\Client\ApiException on non-2xx response - */ - public function updateUser($username, $body) { - - // verify the required parameter 'username' is set - if ($username === null) { - throw new \InvalidArgumentException('Missing the required parameter $username when calling updateUser'); - } - - - // parse inputs - $resourcePath = "/user/{username}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "PUT"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array()); - - - - // path params - if($username !== null) { - $resourcePath = str_replace("{" . "username" . "}", - $this->apiClient->getSerializer()->toPathValue($username), - $resourcePath); - } - - // body params - $_tempBody = null; - if (isset($body)) { - $_tempBody = $body; - } - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - } catch (ApiException $e) { - switch ($e->getCode()) { + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; } - - throw $e; - } - - } + + // make the API Call + try { + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + } catch (ApiException $e) { + switch ($e->getCode()) { + } - /** - * deleteUser - * - * Delete user - * - * @param string $username The name that needs to be deleted (required) - * @return void - * @throws \Swagger\Client\ApiException on non-2xx response - */ - public function deleteUser($username) { - - // verify the required parameter 'username' is set - if ($username === null) { - throw new \InvalidArgumentException('Missing the required parameter $username when calling deleteUser'); - } - - - // parse inputs - $resourcePath = "/user/{username}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "DELETE"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array()); - - - - // path params - if($username !== null) { - $resourcePath = str_replace("{" . "username" . "}", - $this->apiClient->getSerializer()->toPathValue($username), - $resourcePath); - } - - - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - } catch (ApiException $e) { - switch ($e->getCode()) { + throw $e; } - - throw $e; - } - - } + + } + + /** + * createUsersWithListInput + * + * Creates list of users with given input array + * + * @param \Swagger\Client\Model\User[] $body List of user object (required) + * @return void + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function createUsersWithListInput($body) { + + // parse inputs + $resourcePath = "/user/createWithList"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "POST"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array()); + + + + + + // body params + $_tempBody = null; + if (isset($body)) { + $_tempBody = $body; + } + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; + } + + // make the API Call + try { + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + } catch (ApiException $e) { + switch ($e->getCode()) { + } + + throw $e; + } + + } + + /** + * loginUser + * + * Logs user into the system + * + * @param string $username The user name for login (required) + * @param string $password The password for login in clear text (required) + * @return string + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function loginUser($username, $password) { + + + // parse inputs + $resourcePath = "/user/login"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "GET"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array()); + + // query params + if($username !== null) { + $queryParams['username'] = $this->apiClient->getSerializer()->toQueryValue($username); + }// query params + if($password !== null) { + $queryParams['password'] = $this->apiClient->getSerializer()->toQueryValue($password); + } + + + + + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; + } + + // make the API Call + try { + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, + $queryParams, $httpBody, + $headerParams, 'string'); + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), 'string', $httpHeader); + $e->setResponseObject($data); + break; + } + + throw $e; + } + + if (!$response) { + return null; + } + + return $this->apiClient->getSerializer()->deserialize($response,'string'); + + } + + /** + * logoutUser + * + * Logs out current logged in user session + * + * @return void + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function logoutUser() { + + + // parse inputs + $resourcePath = "/user/logout"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "GET"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array()); + + + + + + + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; + } + + // make the API Call + try { + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + } catch (ApiException $e) { + switch ($e->getCode()) { + } + + throw $e; + } + + } + + /** + * getUserByName + * + * Get user by user name + * + * @param string $username The name that needs to be fetched. Use user1 for testing. (required) + * @return \Swagger\Client\Model\User + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function getUserByName($username) { + + // verify the required parameter 'username' is set + if ($username === null) { + throw new \InvalidArgumentException('Missing the required parameter $username when calling getUserByName'); + } + + + // parse inputs + $resourcePath = "/user/{username}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "GET"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array()); + + + + // path params + if($username !== null) { + $resourcePath = str_replace("{" . "username" . "}", + $this->apiClient->getSerializer()->toPathValue($username), + $resourcePath); + } + + + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; + } + + // make the API Call + try { + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, + $queryParams, $httpBody, + $headerParams, '\Swagger\Client\Model\User'); + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\User', $httpHeader); + $e->setResponseObject($data); + break; + } + + throw $e; + } + + if (!$response) { + return null; + } + + return $this->apiClient->getSerializer()->deserialize($response,'\Swagger\Client\Model\User'); + + } + + /** + * updateUser + * + * Updated user + * + * @param string $username name that need to be deleted (required) + * @param \Swagger\Client\Model\User $body Updated user object (required) + * @return void + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function updateUser($username, $body) { + + // verify the required parameter 'username' is set + if ($username === null) { + throw new \InvalidArgumentException('Missing the required parameter $username when calling updateUser'); + } + + + // parse inputs + $resourcePath = "/user/{username}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "PUT"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array()); + + + + // path params + if($username !== null) { + $resourcePath = str_replace("{" . "username" . "}", + $this->apiClient->getSerializer()->toPathValue($username), + $resourcePath); + } + + // body params + $_tempBody = null; + if (isset($body)) { + $_tempBody = $body; + } + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; + } + + // make the API Call + try { + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + } catch (ApiException $e) { + switch ($e->getCode()) { + } + + throw $e; + } + + } + + /** + * deleteUser + * + * Delete user + * + * @param string $username The name that needs to be deleted (required) + * @return void + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function deleteUser($username) { + + // verify the required parameter 'username' is set + if ($username === null) { + throw new \InvalidArgumentException('Missing the required parameter $username when calling deleteUser'); + } + + + // parse inputs + $resourcePath = "/user/{username}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "DELETE"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = ApiClient::selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array()); + + + + // path params + if($username !== null) { + $resourcePath = str_replace("{" . "username" . "}", + $this->apiClient->getSerializer()->toPathValue($username), + $resourcePath); + } + + + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; + } + + // make the API Call + try { + list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + } 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 b47e104ec1e1..1f466389cfdb 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php @@ -19,206 +19,206 @@ namespace Swagger\Client; class ApiClient { - public static $PATCH = "PATCH"; - public static $POST = "POST"; - public static $GET = "GET"; - public static $PUT = "PUT"; - public static $DELETE = "DELETE"; - - /** @var Configuration */ - protected $config; - - /** @var ObjectSerializer */ - protected $serializer; - - /** - * @param Configuration $config config for this ApiClient - */ - function __construct(Configuration $config = null) { - if ($config == null) { - $config = Configuration::getDefaultConfiguration(); + public static $PATCH = "PATCH"; + public static $POST = "POST"; + public static $GET = "GET"; + public static $PUT = "PUT"; + public static $DELETE = "DELETE"; + + /** @var Configuration */ + protected $config; + + /** @var ObjectSerializer */ + protected $serializer; + + /** + * @param Configuration $config config for this ApiClient + */ + function __construct(Configuration $config = null) { + if ($config == null) { + $config = Configuration::getDefaultConfiguration(); + } + + $this->config = $config; + $this->serializer = new ObjectSerializer(); + } + + /** + * get the config + * @return Configuration + */ + public function getConfig() { + return $this->config; + } + + /** + * get the serializer + * @return ObjectSerializer + */ + public function getSerializer() { + return $this->serializer; + } + + /** + * Get API key (with prefix if set) + * @param string $apiKey name of apikey + * @return string API key with the prefix + */ + public function getApiKeyWithPrefix($apiKeyIdentifier) { + $prefix = $this->config->getApiKeyPrefix($apiKeyIdentifier); + $apiKey = $this->config->getApiKey($apiKeyIdentifier); + + if (!isset($apiKey)) { + return null; + } + + if (isset($prefix)) { + $keyWithPrefix = $prefix." ".$apiKey; + } else { + $keyWithPrefix = $apiKey; + } + + return $keyWithPrefix; } - $this->config = $config; - $this->serializer = new ObjectSerializer(); - } - - /** - * get the config - * @return Configuration - */ - public function getConfig() { - return $this->config; - } - - /** - * get the serializer - * @return ObjectSerializer - */ - public function getSerializer() { - return $this->serializer; - } - - /** - * Get API key (with prefix if set) - * @param string $apiKey name of apikey - * @return string API key with the prefix - */ - public function getApiKeyWithPrefix($apiKey) { - $prefix = $this->config->getApiKeyPrefix($apiKey); - $apiKey = $this->config->getApiKey($apiKey); - - if (!isset($apiKey)) { - return null; - } - - if (isset($prefix)) { - $keyWithPrefix = $prefix." ".$apiKey; - } else { - $keyWithPrefix = $apiKey; - } - - return $keyWithPrefix; - } + /** + * @param string $resourcePath path to method endpoint + * @param string $method method to call + * @param array $queryParams parameters to be place in query URL + * @param array $postData parameters to be placed in POST body + * @param array $headerParams parameters to be place in request header + * @throws \Swagger\Client\ApiException on a non 2xx response + * @return mixed + */ + public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams, $responseType=null) { - /** - * @param string $resourcePath path to method endpoint - * @param string $method method to call - * @param array $queryParams parameters to be place in query URL - * @param array $postData parameters to be placed in POST body - * @param array $headerParams parameters to be place in request header - * @throws \Swagger\Client\ApiException on a non 2xx response - * @return mixed - */ - public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams, $responseType=null) { - - $headers = array(); - - # construct the http header - $headerParams = array_merge((array)$this->config->getDefaultHeaders(), (array)$headerParams); - - foreach ($headerParams as $key => $val) { - $headers[] = "$key: $val"; + $headers = array(); + + # construct the http header + $headerParams = array_merge((array)$this->config->getDefaultHeaders(), (array)$headerParams); + + foreach ($headerParams as $key => $val) { + $headers[] = "$key: $val"; + } + + // 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 + $postData = json_encode($this->serializer->sanitizeForSerialization($postData)); + } + + $url = $this->config->getHost() . $resourcePath; + + $curl = curl_init(); + // set timeout, if needed + if ($this->config->getCurlTimeout() != 0) { + curl_setopt($curl, CURLOPT_TIMEOUT, $this->config->getCurlTimeout()); + } + // return the result on success, rather than just TRUE + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + + curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); + + if (! empty($queryParams)) { + $url = ($url . '?' . http_build_query($queryParams)); + } + + if ($method == self::$POST) { + curl_setopt($curl, CURLOPT_POST, true); + curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); + } else if ($method == self::$PATCH) { + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH"); + curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); + } else if ($method == self::$PUT) { + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); + curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); + } else if ($method == self::$DELETE) { + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); + curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); + } else if ($method != self::$GET) { + throw new ApiException('Method ' . $method . ' is not recognized.'); + } + curl_setopt($curl, CURLOPT_URL, $url); + + // Set user agent + curl_setopt($curl, CURLOPT_USERAGENT, $this->config->getUserAgent()); + + // debugging for curl + if ($this->config->getDebug()) { + error_log("[DEBUG] HTTP Request body ~BEGIN~\n".print_r($postData, true)."\n~END~\n", 3, $this->config->getDebugFile()); + + curl_setopt($curl, CURLOPT_VERBOSE, 1); + curl_setopt($curl, CURLOPT_STDERR, fopen($this->config->getDebugFile(), 'a')); + } else { + curl_setopt($curl, CURLOPT_VERBOSE, 0); + } + + // obtain the HTTP response headers + curl_setopt($curl, CURLOPT_HEADER, 1); + + // 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_body = substr($response, $http_header_size); + $response_info = curl_getinfo($curl); + + // debug HTTP response body + if ($this->config->getDebug()) { + error_log("[DEBUG] HTTP Response body ~BEGIN~\n".print_r($http_body, true)."\n~END~\n", 3, $this->config->getDebugFile()); + } + + // 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 ) { + // return raw body if response is a file + if ($responseType == '\SplFileObject') { + return array($http_body, $http_header); + } + + $data = json_decode($http_body); + if (json_last_error() > 0) { // if response is a string + $data = $http_body; + } + } else { + throw new ApiException("[".$response_info['http_code']."] Error connecting to the API ($url)", + $response_info['http_code'], $http_header, $http_body); + } + return array($data, $http_header); } - - // form data - if ($postData and in_array('Content-Type: application/x-www-form-urlencoded', $headers)) { - $postData = http_build_query($postData); + + /* + * return the header 'Accept' based on an array of Accept provided + * + * @param string[] $accept Array of header + * @return string Accept (e.g. application/json) + */ + public static function selectHeaderAccept($accept) { + if (count($accept) === 0 or (count($accept) === 1 and $accept[0] === '')) { + return NULL; + } elseif (preg_grep("/application\/json/i", $accept)) { + return 'application/json'; + } else { + return implode(',', $accept); + } } - else if ((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)); + + /* + * return the content type based on an array of content-type provided + * + * @param string[] content_type_array Array fo content-type + * @return string Content-Type (e.g. application/json) + */ + public static function selectHeaderContentType($content_type) { + if (count($content_type) === 0 or (count($content_type) === 1 and $content_type[0] === '')) { + return 'application/json'; + } elseif (preg_grep("/application\/json/i", $content_type)) { + return 'application/json'; + } else { + return implode(',', $content_type); + } } - - $url = $this->config->getHost() . $resourcePath; - - $curl = curl_init(); - // set timeout, if needed - if ($this->config->getCurlTimeout() != 0) { - curl_setopt($curl, CURLOPT_TIMEOUT, $this->config->getCurlTimeout()); - } - // return the result on success, rather than just TRUE - curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); - - curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); - - if (! empty($queryParams)) { - $url = ($url . '?' . http_build_query($queryParams)); - } - - if ($method == self::$POST) { - curl_setopt($curl, CURLOPT_POST, true); - curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method == self::$PATCH) { - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH"); - curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method == self::$PUT) { - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); - curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method == self::$DELETE) { - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); - curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method != self::$GET) { - throw new ApiException('Method ' . $method . ' is not recognized.'); - } - curl_setopt($curl, CURLOPT_URL, $url); - - // Set user agent - curl_setopt($curl, CURLOPT_USERAGENT, $this->config->getUserAgent()); - - // debugging for curl - if ($this->config->getDebug()) { - error_log("[DEBUG] HTTP Request body ~BEGIN~\n".print_r($postData, true)."\n~END~\n", 3, $this->config->getDebugFile()); - - curl_setopt($curl, CURLOPT_VERBOSE, 1); - curl_setopt($curl, CURLOPT_STDERR, fopen($this->config->getDebugFile(), 'a')); - } else { - curl_setopt($curl, CURLOPT_VERBOSE, 0); - } - - // obtain the HTTP response headers - curl_setopt($curl, CURLOPT_HEADER, 1); - - // 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_body = substr($response, $http_header_size); - $response_info = curl_getinfo($curl); - - // debug HTTP response body - if ($this->config->getDebug()) { - error_log("[DEBUG] HTTP Response body ~BEGIN~\n".print_r($http_body, true)."\n~END~\n", 3, $this->config->getDebugFile()); - } - - // 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 ) { - // return raw body if response is a file - if ($responseType == '\SplFileObject') { - return array($http_body, $http_header); - } - - $data = json_decode($http_body); - if (json_last_error() > 0) { // if response is a string - $data = $http_body; - } - } else { - throw new ApiException("[".$response_info['http_code']."] Error connecting to the API ($url)", - $response_info['http_code'], $http_header, $http_body); - } - return array($data, $http_header); - } - - /* - * return the header 'Accept' based on an array of Accept provided - * - * @param string[] $accept Array of header - * @return string Accept (e.g. application/json) - */ - public static function selectHeaderAccept($accept) { - if (count($accept) === 0 or (count($accept) === 1 and $accept[0] === '')) { - return NULL; - } elseif (preg_grep("/application\/json/i", $accept)) { - return 'application/json'; - } else { - return implode(',', $accept); - } - } - - /* - * return the content type based on an array of content-type provided - * - * @param string[] content_type_array Array fo content-type - * @return string Content-Type (e.g. application/json) - */ - public static function selectHeaderContentType($content_type) { - if (count($content_type) === 0 or (count($content_type) === 1 and $content_type[0] === '')) { - return 'application/json'; - } elseif (preg_grep("/application\/json/i", $content_type)) { - return 'application/json'; - } else { - return implode(',', $content_type); - } - } } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/ApiException.php b/samples/client/petstore/php/SwaggerClient-php/lib/ApiException.php index 51774137aed2..b1342921a0a1 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/ApiException.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/ApiException.php @@ -21,50 +21,50 @@ use \Exception; class ApiException extends Exception { - /** @var string The HTTP body of the server response. */ - protected $responseBody; - - /** @var string[] The HTTP header of the server response. */ - protected $responseHeaders; - - /** - * The deserialized response object - */ - protected $responseObject; - - public function __construct($message="", $code=0, $responseHeaders=null, $responseBody=null) { - parent::__construct($message, $code); - $this->responseHeaders = $responseHeaders; - $this->responseBody = $responseBody; - } - - /** - * Get the HTTP response header - * - * @return string HTTP response header - */ - public function getResponseHeaders() { - return $this->responseHeaders; - } - - /** - * Get the HTTP response body - * - * @return string HTTP response body - */ - public function getResponseBody() { - return $this->responseBody; - } - - /** - * sets the deseralized response object (during deserialization) - * @param mixed $obj - */ - public function setResponseObject($obj) { - $this->responseObject = $obj; - } - - public function getResponseObject() { - return $this->responseObject; - } + /** @var string The HTTP body of the server response. */ + protected $responseBody; + + /** @var string[] The HTTP header of the server response. */ + protected $responseHeaders; + + /** + * The deserialized response object + */ + protected $responseObject; + + public function __construct($message="", $code=0, $responseHeaders=null, $responseBody=null) { + parent::__construct($message, $code); + $this->responseHeaders = $responseHeaders; + $this->responseBody = $responseBody; + } + + /** + * Get the HTTP response header + * + * @return string HTTP response header + */ + public function getResponseHeaders() { + return $this->responseHeaders; + } + + /** + * Get the HTTP response body + * + * @return string HTTP response body + */ + public function getResponseBody() { + return $this->responseBody; + } + + /** + * sets the deseralized response object (during deserialization) + * @param mixed $obj + */ + public function setResponseObject($obj) { + $this->responseObject = $obj; + } + + public function getResponseObject() { + return $this->responseObject; + } } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php b/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php index f4ccef391ef7..5f40dcfe3bdd 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php @@ -19,262 +19,292 @@ namespace Swagger\Client; class Configuration { - private static $defaultConfiguration = null; + private static $defaultConfiguration = null; + + /** @var string[] Associate array to store API key(s) */ + protected $apiKeys = array(); + + /** string[] Associate array to store API prefix (e.g. Bearer) */ + protected $apiKeyPrefixes = array(); + + /** @var string Username for HTTP basic authentication */ + protected $username = ''; + + /** @var string Password for HTTP basic authentication */ + protected $password = ''; + + /** @var \Swagger\Client\ApiClient The default instance of ApiClient */ + protected $defaultHeaders = array(); + + /** @var string The host */ + protected $host = 'http://localhost'; + + /** @var string timeout (second) of the HTTP request, by default set to 0, no timeout */ + protected $curlTimeout = 0; + + /** @var string user agent of the HTTP request, set to "PHP-Swagger" by default */ + protected $userAgent = "PHP-Swagger"; + + /** @var bool Debug switch (default set to false) */ + protected $debug = false; + + /** @var string Debug file location (log to STDOUT by default) */ + protected $debugFile = 'php://output'; + + /** @var string Debug file location (log to STDOUT by default) */ + protected $tempFolderPath; - /** @var string[] Associate array to store API key(s) */ - protected $apiKeys = array(); + /** + * @param string $tempFolderPath + */ + public function __construct() { + $this->tempFolderPath = sys_get_temp_dir(); + } + - /** string[] Associate array to store API prefix (e.g. Bearer) */ - protected $apiKeyPrefixes = array(); - - /** @var string Username for HTTP basic authentication */ - protected $username = ''; - - /** @var string Password for HTTP basic authentication */ - protected $password = ''; - - /** @var \Swagger\Client\ApiClient The default instance of ApiClient */ - protected $defaultHeaders = array(); - - /** @var string The host */ - protected $host = 'http://localhost'; - - /** @var string timeout (second) of the HTTP request, by default set to 0, no timeout */ - protected $curlTimeout = 0; - - /** @var string user agent of the HTTP request, set to "PHP-Swagger" by default */ - protected $userAgent = "PHP-Swagger"; - - /** @var bool Debug switch (default set to false) */ - protected $debug = false; - - /** @var string Debug file location (log to STDOUT by default) */ - protected $debugFile = 'php://output'; - - /** - * @param string $key - * @param string $value - * @return Configuration - */ - public function setApiKey($key, $value) { - $this->apiKeys[$key] = $value; - return $this; - } - - /** - * @param $key - * @return string - */ - public function getApiKey($key) { - return isset($this->apiKeys[$key]) ? $this->apiKeys[$key] : null; - } - - /** - * @param string $key - * @param string $value - * @return Configuration - */ - public function setApiKeyPrefix($key, $value) { - $this->apiKeyPrefixes[$key] = $value; - return $this; - } - - /** - * @param $key - * @return string - */ - public function getApiKeyPrefix($key) { - return isset($this->apiKeyPrefixes[$key]) ? $this->apiKeyPrefixes[$key] : null; - } - - /** - * @param string $username - * @return Configuration - */ - public function setUsername($username) { - $this->username = $username; - return $this; - } - - /** - * @return string - */ - public function getUsername() { - return $this->username; - } - - /** - * @param string $password - * @return Configuration - */ - public function setPassword($password) { - $this->password = $password; - return $this; - } - - /** - * @return string - */ - public function getPassword() { - return $this->password; - } - - /** - * add default header - * - * @param string $headerName header name (e.g. Token) - * @param string $headerValue header value (e.g. 1z8wp3) - * @return ApiClient - */ - public function addDefaultHeader($headerName, $headerValue) { - if (!is_string($headerName)) { - throw new \InvalidArgumentException('Header name must be a string.'); + /** + * @param string $key + * @param string $value + * @return Configuration + */ + public function setApiKey($key, $value) { + $this->apiKeys[$key] = $value; + return $this; + } + + /** + * @param $key + * @return string + */ + public function getApiKey($key) { + return isset($this->apiKeys[$key]) ? $this->apiKeys[$key] : null; + } + + /** + * @param string $key + * @param string $value + * @return Configuration + */ + public function setApiKeyPrefix($key, $value) { + $this->apiKeyPrefixes[$key] = $value; + return $this; + } + + /** + * @param $key + * @return string + */ + public function getApiKeyPrefix($key) { + return isset($this->apiKeyPrefixes[$key]) ? $this->apiKeyPrefixes[$key] : null; + } + + /** + * @param string $username + * @return Configuration + */ + public function setUsername($username) { + $this->username = $username; + return $this; + } + + /** + * @return string + */ + public function getUsername() { + return $this->username; + } + + /** + * @param string $password + * @return Configuration + */ + public function setPassword($password) { + $this->password = $password; + return $this; + } + + /** + * @return string + */ + public function getPassword() { + return $this->password; + } + + /** + * add default header + * + * @param string $headerName header name (e.g. Token) + * @param string $headerValue header value (e.g. 1z8wp3) + * @return ApiClient + */ + public function addDefaultHeader($headerName, $headerValue) { + if (!is_string($headerName)) { + throw new \InvalidArgumentException('Header name must be a string.'); + } + + $this->defaultHeaders[$headerName] = $headerValue; + return $this; + } + + /** + * get the default header + * + * @return array default header + */ + public function getDefaultHeaders() { + return $this->defaultHeaders; + } + + /** + * delete a default header + * @param string $headerName the header to delete + * @return Configuration + */ + public function deleteDefaultHeader($headerName) { + unset($this->defaultHeaders[$headerName]); + } + + /** + * @param string $host + * @return Configuration + */ + public function setHost($host) { + $this->host = $host; + return $this; + } + + /** + * @return string + */ + public function getHost() { + return $this->host; + } + + /** + * set the user agent of the api client + * + * @param string $userAgent the user agent of the api client + * @return ApiClient + */ + public function setUserAgent($userAgent) { + if (!is_string($userAgent)) { + throw new \InvalidArgumentException('User-agent must be a string.'); + } + + $this->userAgent = $userAgent; + return $this; + } + + /** + * get the user agent of the api client + * + * @return string user agent + */ + public function getUserAgent() { + return $this->userAgent; + } + + /** + * set the HTTP timeout value + * + * @param integer $seconds Number of seconds before timing out [set to 0 for no timeout] + * @return ApiClient + */ + public function setCurlTimeout($seconds) { + if (!is_numeric($seconds) || $seconds < 0) { + throw new \InvalidArgumentException('Timeout value must be numeric and a non-negative number.'); + } + + $this->curlTimeout = $seconds; + return $this; + } + + /** + * get the HTTP timeout value + * + * @return string HTTP timeout value + */ + public function getCurlTimeout() { + return $this->curlTimeout; + } + + /** + * @param bool $debug + * @return Configuration + */ + public function setDebug($debug) { + $this->debug = $debug; + return $this; + } + + /** + * @return bool + */ + public function getDebug() { + return $this->debug; + } + + /** + * @param string $debugFile + * @return Configuration + */ + public function setDebugFile($debugFile) { + $this->debugFile = $debugFile; + return $this; + } + + /** + * @return string + */ + public function getDebugFile() { + return $this->debugFile; + } + + /** + * @param string $debugFile + * @return Configuration + */ + public function setTempFolderPath($tempFolderPath) { + $this->tempFolderPath = $tempFolderPath; + return $this; + } + + /** + * @return string + */ + public function getTempFolderPath() { + return $this->tempFolderPath; } - $this->defaultHeaders[$headerName] = $headerValue; - return $this; - } - - /** - * get the default header - * - * @return array default header - */ - public function getDefaultHeaders() { - return $this->defaultHeaders; - } - - /** - * delete a default header - * @param string $headerName the header to delete - * @return Configuration - */ - public function deleteDefaultHeader($headerName) { - unset($this->defaultHeaders[$headerName]); - } - - /** - * @param string $host - * @return Configuration - */ - public function setHost($host) { - $this->host = $host; - return $this; - } - - /** - * @return string - */ - public function getHost() { - return $this->host; - } - - /** - * set the user agent of the api client - * - * @param string $userAgent the user agent of the api client - * @return ApiClient - */ - public function setUserAgent($userAgent) { - if (!is_string($userAgent)) { - throw new \InvalidArgumentException('User-agent must be a string.'); + /** + * @return Configuration + */ + public static function getDefaultConfiguration() { + if (self::$defaultConfiguration == null) { + return new Configuration(); + } + + return self::$defaultConfiguration; } - - $this->userAgent = $userAgent; - return $this; - } - - /** - * get the user agent of the api client - * - * @return string user agent - */ - public function getUserAgent() { - return $this->userAgent; - } - - /** - * set the HTTP timeout value - * - * @param integer $seconds Number of seconds before timing out [set to 0 for no timeout] - * @return ApiClient - */ - public function setCurlTimeout($seconds) { - if (!is_numeric($seconds) || $seconds < 0) { - throw new \InvalidArgumentException('Timeout value must be numeric and a non-negative number.'); + + /** + * @param Configuration $config + */ + public static function setDefaultConfiguration(Configuration $config) { + self::$defaultConfiguration = $config; } - - $this->curlTimeout = $seconds; - return $this; - } - - /** - * get the HTTP timeout value - * - * @return string HTTP timeout value - */ - public function getCurlTimeout() { - return $this->curlTimeout; - } - - /** - * @param bool $debug - * @return Configuration - */ - public function setDebug($debug) { - $this->debug = $debug; - return $this; - } - - /** - * @return bool - */ - public function getDebug() { - return $this->debug; - } - - /** - * @param string $debugFile - * @return Configuration - */ - public function setDebugFile($debugFile) { - $this->debugFile = $debugFile; - return $this; - } - - /** - * @return string - */ - public function getDebugFile() { - return $this->debugFile; - } - - /** - * @return Configuration - */ - public static function getDefaultConfiguration() { - if (self::$defaultConfiguration == null) { - return new Configuration(); + + /* + * return the report for debugging + */ + public static function toDebugReport() { + $report = "PHP SDK (Swagger\Client) Debug Report:\n"; + $report .= " OS: ".php_uname()."\n"; + $report .= " PHP Version: ".phpversion()."\n"; + $report .= " Swagger Spec Version: 1.0.0\n"; + $report .= " SDK Package Version: 1.0.0\n"; + + return $report; } - - return self::$defaultConfiguration; - } - - public static function setDefaultConfiguration(Configuration $config) { - self::$defaultConfiguration = $config; - } - - /* - * return the report for debuggin - */ - public static function toDebugReport() { - $report = "PHP SDK (Swagger\Client) Debug Report:\n"; - $report .= " OS: ".php_uname()."\n"; - $report .= " PHP Version: ".phpversion()."\n"; - $report .= " Swagger Spec Version: 1.0.0\n"; - $report .= " SDK Package Version: 1.0.0\n"; - - return $report; - } - + } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php index 9995dccdd4e0..eb6603043df1 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php @@ -27,101 +27,101 @@ namespace Swagger\Client\Model; use \ArrayAccess; class Category implements ArrayAccess { - /** @var string[] Array of property to type mappings. Used for (de)serialization */ - static $swaggerTypes = array( - 'id' => 'int', - 'name' => 'string' - ); - - /** @var string[] Array of attributes where the key is the local name, and the value is the original name */ - static $attributeMap = array( - 'id' => 'id', - 'name' => 'name' - ); - - /** @var string[] Array of attributes to setter functions (for deserialization of responses) */ - static $setters = array( - 'id' => 'setId', - 'name' => 'setName' - ); - - /** @var string[] Array of attributes to getter functions (for serialization of requests) */ - static $getters = array( - 'id' => 'getId', - 'name' => 'getName' - ); - + /** @var string[] Array of property to type mappings. Used for (de)serialization */ + static $swaggerTypes = array( + 'id' => 'int', + 'name' => 'string' + ); - /** @var int $id */ - protected $id; + /** @var string[] Array of attributes where the key is the local name, and the value is the original name */ + static $attributeMap = array( + 'id' => 'id', + 'name' => 'name' + ); - /** @var string $name */ - protected $name; + /** @var string[] Array of attributes to setter functions (for deserialization of responses) */ + static $setters = array( + 'id' => 'setId', + 'name' => 'setName' + ); - public function __construct(array $data = null) { - if ($data != null) { - $this->id = $data["id"]; - $this->name = $data["name"]; + /** @var string[] Array of attributes to getter functions (for serialization of requests) */ + static $getters = array( + 'id' => 'getId', + 'name' => 'getName' + ); + + + /** @var int $id */ + protected $id; + + /** @var string $name */ + protected $name; + + public function __construct(array $data = null) { + if ($data != null) { + $this->id = $data["id"]; + $this->name = $data["name"]; + } } - } - - /** - * get id - * @return int - */ - public function getId() { - return $this->id; - } - - /** - * set id - * @param int $id - * @return $this - */ - public function setId($id) { - $this->id = $id; - return $this; - } - - /** - * get name - * @return string - */ - public function getName() { - return $this->name; - } - - /** - * set name - * @param string $name - * @return $this - */ - public function setName($name) { - $this->name = $name; - return $this; - } - - public function offsetExists($offset) { - return isset($this->$offset); - } - - public function offsetGet($offset) { - return $this->$offset; - } - - public function offsetSet($offset, $value) { - $this->$offset = $value; - } - - public function offsetUnset($offset) { - unset($this->$offset); - } - - public function __toString() { - if (defined('JSON_PRETTY_PRINT')) { - return json_encode(get_object_vars($this), JSON_PRETTY_PRINT); - } else { - return json_encode(get_object_vars($this)); + + /** + * get id + * @return int + */ + public function getId() { + return $this->id; + } + + /** + * set id + * @param int $id + * @return $this + */ + public function setId($id) { + $this->id = $id; + return $this; + } + + /** + * get name + * @return string + */ + public function getName() { + return $this->name; + } + + /** + * set name + * @param string $name + * @return $this + */ + public function setName($name) { + $this->name = $name; + return $this; + } + + public function offsetExists($offset) { + return isset($this->$offset); + } + + public function offsetGet($offset) { + return $this->$offset; + } + + public function offsetSet($offset, $value) { + $this->$offset = $value; + } + + public function offsetUnset($offset) { + unset($this->$offset); + } + + public function __toString() { + if (defined('JSON_PRETTY_PRINT')) { + return json_encode(get_object_vars($this), JSON_PRETTY_PRINT); + } else { + return json_encode(get_object_vars($this)); + } } - } } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php index 2e0386d0ed74..bcea02d96862 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php @@ -27,205 +27,205 @@ namespace Swagger\Client\Model; use \ArrayAccess; class Order implements ArrayAccess { - /** @var string[] Array of property to type mappings. Used for (de)serialization */ - static $swaggerTypes = array( - 'id' => 'int', - 'pet_id' => 'int', - 'quantity' => 'int', - 'ship_date' => '\DateTime', - 'status' => 'string', - 'complete' => 'bool' - ); - - /** @var string[] Array of attributes where the key is the local name, and the value is the original name */ - static $attributeMap = array( - 'id' => 'id', - 'pet_id' => 'petId', - 'quantity' => 'quantity', - 'ship_date' => 'shipDate', - 'status' => 'status', - 'complete' => 'complete' - ); - - /** @var string[] Array of attributes to setter functions (for deserialization of responses) */ - static $setters = array( - 'id' => 'setId', - 'pet_id' => 'setPetId', - 'quantity' => 'setQuantity', - 'ship_date' => 'setShipDate', - 'status' => 'setStatus', - 'complete' => 'setComplete' - ); - - /** @var string[] Array of attributes to getter functions (for serialization of requests) */ - static $getters = array( - 'id' => 'getId', - 'pet_id' => 'getPetId', - 'quantity' => 'getQuantity', - 'ship_date' => 'getShipDate', - 'status' => 'getStatus', - 'complete' => 'getComplete' - ); - + /** @var string[] Array of property to type mappings. Used for (de)serialization */ + static $swaggerTypes = array( + 'id' => 'int', + 'pet_id' => 'int', + 'quantity' => 'int', + 'ship_date' => '\DateTime', + 'status' => 'string', + 'complete' => 'bool' + ); - /** @var int $id */ - protected $id; + /** @var string[] Array of attributes where the key is the local name, and the value is the original name */ + static $attributeMap = array( + 'id' => 'id', + 'pet_id' => 'petId', + 'quantity' => 'quantity', + 'ship_date' => 'shipDate', + 'status' => 'status', + 'complete' => 'complete' + ); - /** @var int $pet_id */ - protected $pet_id; + /** @var string[] Array of attributes to setter functions (for deserialization of responses) */ + static $setters = array( + 'id' => 'setId', + 'pet_id' => 'setPetId', + 'quantity' => 'setQuantity', + 'ship_date' => 'setShipDate', + 'status' => 'setStatus', + 'complete' => 'setComplete' + ); - /** @var int $quantity */ - protected $quantity; + /** @var string[] Array of attributes to getter functions (for serialization of requests) */ + static $getters = array( + 'id' => 'getId', + 'pet_id' => 'getPetId', + 'quantity' => 'getQuantity', + 'ship_date' => 'getShipDate', + 'status' => 'getStatus', + 'complete' => 'getComplete' + ); - /** @var \DateTime $ship_date */ - protected $ship_date; - - /** @var string $status Order Status */ - protected $status; - - /** @var bool $complete */ - protected $complete; - - public function __construct(array $data = null) { - if ($data != null) { - $this->id = $data["id"]; - $this->pet_id = $data["pet_id"]; - $this->quantity = $data["quantity"]; - $this->ship_date = $data["ship_date"]; - $this->status = $data["status"]; - $this->complete = $data["complete"]; + + /** @var int $id */ + protected $id; + + /** @var int $pet_id */ + protected $pet_id; + + /** @var int $quantity */ + protected $quantity; + + /** @var \DateTime $ship_date */ + protected $ship_date; + + /** @var string $status Order Status */ + protected $status; + + /** @var bool $complete */ + protected $complete; + + public function __construct(array $data = null) { + if ($data != null) { + $this->id = $data["id"]; + $this->pet_id = $data["pet_id"]; + $this->quantity = $data["quantity"]; + $this->ship_date = $data["ship_date"]; + $this->status = $data["status"]; + $this->complete = $data["complete"]; + } } - } - - /** - * get id - * @return int - */ - public function getId() { - return $this->id; - } - - /** - * set id - * @param int $id - * @return $this - */ - public function setId($id) { - $this->id = $id; - return $this; - } - - /** - * get pet_id - * @return int - */ - public function getPetId() { - return $this->pet_id; - } - - /** - * set pet_id - * @param int $pet_id - * @return $this - */ - public function setPetId($pet_id) { - $this->pet_id = $pet_id; - return $this; - } - - /** - * get quantity - * @return int - */ - public function getQuantity() { - return $this->quantity; - } - - /** - * set quantity - * @param int $quantity - * @return $this - */ - public function setQuantity($quantity) { - $this->quantity = $quantity; - return $this; - } - - /** - * get ship_date - * @return \DateTime - */ - public function getShipDate() { - return $this->ship_date; - } - - /** - * set ship_date - * @param \DateTime $ship_date - * @return $this - */ - public function setShipDate($ship_date) { - $this->ship_date = $ship_date; - return $this; - } - - /** - * get status - * @return string - */ - public function getStatus() { - return $this->status; - } - - /** - * set status - * @param string $status - * @return $this - */ - public function setStatus($status) { - $this->status = $status; - return $this; - } - - /** - * get complete - * @return bool - */ - public function getComplete() { - return $this->complete; - } - - /** - * set complete - * @param bool $complete - * @return $this - */ - public function setComplete($complete) { - $this->complete = $complete; - return $this; - } - - public function offsetExists($offset) { - return isset($this->$offset); - } - - public function offsetGet($offset) { - return $this->$offset; - } - - public function offsetSet($offset, $value) { - $this->$offset = $value; - } - - public function offsetUnset($offset) { - unset($this->$offset); - } - - public function __toString() { - if (defined('JSON_PRETTY_PRINT')) { - return json_encode(get_object_vars($this), JSON_PRETTY_PRINT); - } else { - return json_encode(get_object_vars($this)); + + /** + * get id + * @return int + */ + public function getId() { + return $this->id; + } + + /** + * set id + * @param int $id + * @return $this + */ + public function setId($id) { + $this->id = $id; + return $this; + } + + /** + * get pet_id + * @return int + */ + public function getPetId() { + return $this->pet_id; + } + + /** + * set pet_id + * @param int $pet_id + * @return $this + */ + public function setPetId($pet_id) { + $this->pet_id = $pet_id; + return $this; + } + + /** + * get quantity + * @return int + */ + public function getQuantity() { + return $this->quantity; + } + + /** + * set quantity + * @param int $quantity + * @return $this + */ + public function setQuantity($quantity) { + $this->quantity = $quantity; + return $this; + } + + /** + * get ship_date + * @return \DateTime + */ + public function getShipDate() { + return $this->ship_date; + } + + /** + * set ship_date + * @param \DateTime $ship_date + * @return $this + */ + public function setShipDate($ship_date) { + $this->ship_date = $ship_date; + return $this; + } + + /** + * get status + * @return string + */ + public function getStatus() { + return $this->status; + } + + /** + * set status + * @param string $status + * @return $this + */ + public function setStatus($status) { + $this->status = $status; + return $this; + } + + /** + * get complete + * @return bool + */ + public function getComplete() { + return $this->complete; + } + + /** + * set complete + * @param bool $complete + * @return $this + */ + public function setComplete($complete) { + $this->complete = $complete; + return $this; + } + + public function offsetExists($offset) { + return isset($this->$offset); + } + + public function offsetGet($offset) { + return $this->$offset; + } + + public function offsetSet($offset, $value) { + $this->$offset = $value; + } + + public function offsetUnset($offset) { + unset($this->$offset); + } + + public function __toString() { + if (defined('JSON_PRETTY_PRINT')) { + return json_encode(get_object_vars($this), JSON_PRETTY_PRINT); + } else { + return json_encode(get_object_vars($this)); + } } - } } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php index a7b259a2fbe8..2e6947144c97 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php @@ -27,205 +27,205 @@ namespace Swagger\Client\Model; use \ArrayAccess; class Pet implements ArrayAccess { - /** @var string[] Array of property to type mappings. Used for (de)serialization */ - static $swaggerTypes = array( - 'id' => 'int', - 'category' => '\Swagger\Client\Model\Category', - 'name' => 'string', - 'photo_urls' => 'string[]', - 'tags' => '\Swagger\Client\Model\Tag[]', - 'status' => 'string' - ); - - /** @var string[] Array of attributes where the key is the local name, and the value is the original name */ - static $attributeMap = array( - 'id' => 'id', - 'category' => 'category', - 'name' => 'name', - 'photo_urls' => 'photoUrls', - 'tags' => 'tags', - 'status' => 'status' - ); - - /** @var string[] Array of attributes to setter functions (for deserialization of responses) */ - static $setters = array( - 'id' => 'setId', - 'category' => 'setCategory', - 'name' => 'setName', - 'photo_urls' => 'setPhotoUrls', - 'tags' => 'setTags', - 'status' => 'setStatus' - ); - - /** @var string[] Array of attributes to getter functions (for serialization of requests) */ - static $getters = array( - 'id' => 'getId', - 'category' => 'getCategory', - 'name' => 'getName', - 'photo_urls' => 'getPhotoUrls', - 'tags' => 'getTags', - 'status' => 'getStatus' - ); - + /** @var string[] Array of property to type mappings. Used for (de)serialization */ + static $swaggerTypes = array( + 'id' => 'int', + 'category' => '\Swagger\Client\Model\Category', + 'name' => 'string', + 'photo_urls' => 'string[]', + 'tags' => '\Swagger\Client\Model\Tag[]', + 'status' => 'string' + ); - /** @var int $id */ - protected $id; + /** @var string[] Array of attributes where the key is the local name, and the value is the original name */ + static $attributeMap = array( + 'id' => 'id', + 'category' => 'category', + 'name' => 'name', + 'photo_urls' => 'photoUrls', + 'tags' => 'tags', + 'status' => 'status' + ); - /** @var \Swagger\Client\Model\Category $category */ - protected $category; + /** @var string[] Array of attributes to setter functions (for deserialization of responses) */ + static $setters = array( + 'id' => 'setId', + 'category' => 'setCategory', + 'name' => 'setName', + 'photo_urls' => 'setPhotoUrls', + 'tags' => 'setTags', + 'status' => 'setStatus' + ); - /** @var string $name */ - protected $name; + /** @var string[] Array of attributes to getter functions (for serialization of requests) */ + static $getters = array( + 'id' => 'getId', + 'category' => 'getCategory', + 'name' => 'getName', + 'photo_urls' => 'getPhotoUrls', + 'tags' => 'getTags', + 'status' => 'getStatus' + ); - /** @var string[] $photo_urls */ - protected $photo_urls; - - /** @var \Swagger\Client\Model\Tag[] $tags */ - protected $tags; - - /** @var string $status pet status in the store */ - protected $status; - - public function __construct(array $data = null) { - if ($data != null) { - $this->id = $data["id"]; - $this->category = $data["category"]; - $this->name = $data["name"]; - $this->photo_urls = $data["photo_urls"]; - $this->tags = $data["tags"]; - $this->status = $data["status"]; + + /** @var int $id */ + protected $id; + + /** @var \Swagger\Client\Model\Category $category */ + protected $category; + + /** @var string $name */ + protected $name; + + /** @var string[] $photo_urls */ + protected $photo_urls; + + /** @var \Swagger\Client\Model\Tag[] $tags */ + protected $tags; + + /** @var string $status pet status in the store */ + protected $status; + + public function __construct(array $data = null) { + if ($data != null) { + $this->id = $data["id"]; + $this->category = $data["category"]; + $this->name = $data["name"]; + $this->photo_urls = $data["photo_urls"]; + $this->tags = $data["tags"]; + $this->status = $data["status"]; + } } - } - - /** - * get id - * @return int - */ - public function getId() { - return $this->id; - } - - /** - * set id - * @param int $id - * @return $this - */ - public function setId($id) { - $this->id = $id; - return $this; - } - - /** - * get category - * @return \Swagger\Client\Model\Category - */ - public function getCategory() { - return $this->category; - } - - /** - * set category - * @param \Swagger\Client\Model\Category $category - * @return $this - */ - public function setCategory($category) { - $this->category = $category; - return $this; - } - - /** - * get name - * @return string - */ - public function getName() { - return $this->name; - } - - /** - * set name - * @param string $name - * @return $this - */ - public function setName($name) { - $this->name = $name; - return $this; - } - - /** - * get photo_urls - * @return string[] - */ - public function getPhotoUrls() { - return $this->photo_urls; - } - - /** - * set photo_urls - * @param string[] $photo_urls - * @return $this - */ - public function setPhotoUrls($photo_urls) { - $this->photo_urls = $photo_urls; - return $this; - } - - /** - * get tags - * @return \Swagger\Client\Model\Tag[] - */ - public function getTags() { - return $this->tags; - } - - /** - * set tags - * @param \Swagger\Client\Model\Tag[] $tags - * @return $this - */ - public function setTags($tags) { - $this->tags = $tags; - return $this; - } - - /** - * get status - * @return string - */ - public function getStatus() { - return $this->status; - } - - /** - * set status - * @param string $status - * @return $this - */ - public function setStatus($status) { - $this->status = $status; - return $this; - } - - public function offsetExists($offset) { - return isset($this->$offset); - } - - public function offsetGet($offset) { - return $this->$offset; - } - - public function offsetSet($offset, $value) { - $this->$offset = $value; - } - - public function offsetUnset($offset) { - unset($this->$offset); - } - - public function __toString() { - if (defined('JSON_PRETTY_PRINT')) { - return json_encode(get_object_vars($this), JSON_PRETTY_PRINT); - } else { - return json_encode(get_object_vars($this)); + + /** + * get id + * @return int + */ + public function getId() { + return $this->id; + } + + /** + * set id + * @param int $id + * @return $this + */ + public function setId($id) { + $this->id = $id; + return $this; + } + + /** + * get category + * @return \Swagger\Client\Model\Category + */ + public function getCategory() { + return $this->category; + } + + /** + * set category + * @param \Swagger\Client\Model\Category $category + * @return $this + */ + public function setCategory($category) { + $this->category = $category; + return $this; + } + + /** + * get name + * @return string + */ + public function getName() { + return $this->name; + } + + /** + * set name + * @param string $name + * @return $this + */ + public function setName($name) { + $this->name = $name; + return $this; + } + + /** + * get photo_urls + * @return string[] + */ + public function getPhotoUrls() { + return $this->photo_urls; + } + + /** + * set photo_urls + * @param string[] $photo_urls + * @return $this + */ + public function setPhotoUrls($photo_urls) { + $this->photo_urls = $photo_urls; + return $this; + } + + /** + * get tags + * @return \Swagger\Client\Model\Tag[] + */ + public function getTags() { + return $this->tags; + } + + /** + * set tags + * @param \Swagger\Client\Model\Tag[] $tags + * @return $this + */ + public function setTags($tags) { + $this->tags = $tags; + return $this; + } + + /** + * get status + * @return string + */ + public function getStatus() { + return $this->status; + } + + /** + * set status + * @param string $status + * @return $this + */ + public function setStatus($status) { + $this->status = $status; + return $this; + } + + public function offsetExists($offset) { + return isset($this->$offset); + } + + public function offsetGet($offset) { + return $this->$offset; + } + + public function offsetSet($offset, $value) { + $this->$offset = $value; + } + + public function offsetUnset($offset) { + unset($this->$offset); + } + + public function __toString() { + if (defined('JSON_PRETTY_PRINT')) { + return json_encode(get_object_vars($this), JSON_PRETTY_PRINT); + } else { + return json_encode(get_object_vars($this)); + } } - } } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php index 6e8ae3e27a1a..bdd133810c57 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php @@ -27,101 +27,101 @@ namespace Swagger\Client\Model; use \ArrayAccess; class Tag implements ArrayAccess { - /** @var string[] Array of property to type mappings. Used for (de)serialization */ - static $swaggerTypes = array( - 'id' => 'int', - 'name' => 'string' - ); - - /** @var string[] Array of attributes where the key is the local name, and the value is the original name */ - static $attributeMap = array( - 'id' => 'id', - 'name' => 'name' - ); - - /** @var string[] Array of attributes to setter functions (for deserialization of responses) */ - static $setters = array( - 'id' => 'setId', - 'name' => 'setName' - ); - - /** @var string[] Array of attributes to getter functions (for serialization of requests) */ - static $getters = array( - 'id' => 'getId', - 'name' => 'getName' - ); - + /** @var string[] Array of property to type mappings. Used for (de)serialization */ + static $swaggerTypes = array( + 'id' => 'int', + 'name' => 'string' + ); - /** @var int $id */ - protected $id; + /** @var string[] Array of attributes where the key is the local name, and the value is the original name */ + static $attributeMap = array( + 'id' => 'id', + 'name' => 'name' + ); - /** @var string $name */ - protected $name; + /** @var string[] Array of attributes to setter functions (for deserialization of responses) */ + static $setters = array( + 'id' => 'setId', + 'name' => 'setName' + ); - public function __construct(array $data = null) { - if ($data != null) { - $this->id = $data["id"]; - $this->name = $data["name"]; + /** @var string[] Array of attributes to getter functions (for serialization of requests) */ + static $getters = array( + 'id' => 'getId', + 'name' => 'getName' + ); + + + /** @var int $id */ + protected $id; + + /** @var string $name */ + protected $name; + + public function __construct(array $data = null) { + if ($data != null) { + $this->id = $data["id"]; + $this->name = $data["name"]; + } } - } - - /** - * get id - * @return int - */ - public function getId() { - return $this->id; - } - - /** - * set id - * @param int $id - * @return $this - */ - public function setId($id) { - $this->id = $id; - return $this; - } - - /** - * get name - * @return string - */ - public function getName() { - return $this->name; - } - - /** - * set name - * @param string $name - * @return $this - */ - public function setName($name) { - $this->name = $name; - return $this; - } - - public function offsetExists($offset) { - return isset($this->$offset); - } - - public function offsetGet($offset) { - return $this->$offset; - } - - public function offsetSet($offset, $value) { - $this->$offset = $value; - } - - public function offsetUnset($offset) { - unset($this->$offset); - } - - public function __toString() { - if (defined('JSON_PRETTY_PRINT')) { - return json_encode(get_object_vars($this), JSON_PRETTY_PRINT); - } else { - return json_encode(get_object_vars($this)); + + /** + * get id + * @return int + */ + public function getId() { + return $this->id; + } + + /** + * set id + * @param int $id + * @return $this + */ + public function setId($id) { + $this->id = $id; + return $this; + } + + /** + * get name + * @return string + */ + public function getName() { + return $this->name; + } + + /** + * set name + * @param string $name + * @return $this + */ + public function setName($name) { + $this->name = $name; + return $this; + } + + public function offsetExists($offset) { + return isset($this->$offset); + } + + public function offsetGet($offset) { + return $this->$offset; + } + + public function offsetSet($offset, $value) { + $this->$offset = $value; + } + + public function offsetUnset($offset) { + unset($this->$offset); + } + + public function __toString() { + if (defined('JSON_PRETTY_PRINT')) { + return json_encode(get_object_vars($this), JSON_PRETTY_PRINT); + } else { + return json_encode(get_object_vars($this)); + } } - } } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php index b1e2d2b809ca..160d93e8f58d 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php @@ -27,257 +27,257 @@ namespace Swagger\Client\Model; use \ArrayAccess; class User implements ArrayAccess { - /** @var string[] Array of property to type mappings. Used for (de)serialization */ - static $swaggerTypes = array( - 'id' => 'int', - 'username' => 'string', - 'first_name' => 'string', - 'last_name' => 'string', - 'email' => 'string', - 'password' => 'string', - 'phone' => 'string', - 'user_status' => 'int' - ); - - /** @var string[] Array of attributes where the key is the local name, and the value is the original name */ - static $attributeMap = array( - 'id' => 'id', - 'username' => 'username', - 'first_name' => 'firstName', - 'last_name' => 'lastName', - 'email' => 'email', - 'password' => 'password', - 'phone' => 'phone', - 'user_status' => 'userStatus' - ); - - /** @var string[] Array of attributes to setter functions (for deserialization of responses) */ - static $setters = array( - 'id' => 'setId', - 'username' => 'setUsername', - 'first_name' => 'setFirstName', - 'last_name' => 'setLastName', - 'email' => 'setEmail', - 'password' => 'setPassword', - 'phone' => 'setPhone', - 'user_status' => 'setUserStatus' - ); - - /** @var string[] Array of attributes to getter functions (for serialization of requests) */ - static $getters = array( - 'id' => 'getId', - 'username' => 'getUsername', - 'first_name' => 'getFirstName', - 'last_name' => 'getLastName', - 'email' => 'getEmail', - 'password' => 'getPassword', - 'phone' => 'getPhone', - 'user_status' => 'getUserStatus' - ); - + /** @var string[] Array of property to type mappings. Used for (de)serialization */ + static $swaggerTypes = array( + 'id' => 'int', + 'username' => 'string', + 'first_name' => 'string', + 'last_name' => 'string', + 'email' => 'string', + 'password' => 'string', + 'phone' => 'string', + 'user_status' => 'int' + ); - /** @var int $id */ - protected $id; + /** @var string[] Array of attributes where the key is the local name, and the value is the original name */ + static $attributeMap = array( + 'id' => 'id', + 'username' => 'username', + 'first_name' => 'firstName', + 'last_name' => 'lastName', + 'email' => 'email', + 'password' => 'password', + 'phone' => 'phone', + 'user_status' => 'userStatus' + ); - /** @var string $username */ - protected $username; + /** @var string[] Array of attributes to setter functions (for deserialization of responses) */ + static $setters = array( + 'id' => 'setId', + 'username' => 'setUsername', + 'first_name' => 'setFirstName', + 'last_name' => 'setLastName', + 'email' => 'setEmail', + 'password' => 'setPassword', + 'phone' => 'setPhone', + 'user_status' => 'setUserStatus' + ); - /** @var string $first_name */ - protected $first_name; + /** @var string[] Array of attributes to getter functions (for serialization of requests) */ + static $getters = array( + 'id' => 'getId', + 'username' => 'getUsername', + 'first_name' => 'getFirstName', + 'last_name' => 'getLastName', + 'email' => 'getEmail', + 'password' => 'getPassword', + 'phone' => 'getPhone', + 'user_status' => 'getUserStatus' + ); - /** @var string $last_name */ - protected $last_name; - - /** @var string $email */ - protected $email; - - /** @var string $password */ - protected $password; - - /** @var string $phone */ - protected $phone; - - /** @var int $user_status User Status */ - protected $user_status; - - public function __construct(array $data = null) { - if ($data != null) { - $this->id = $data["id"]; - $this->username = $data["username"]; - $this->first_name = $data["first_name"]; - $this->last_name = $data["last_name"]; - $this->email = $data["email"]; - $this->password = $data["password"]; - $this->phone = $data["phone"]; - $this->user_status = $data["user_status"]; + + /** @var int $id */ + protected $id; + + /** @var string $username */ + protected $username; + + /** @var string $first_name */ + protected $first_name; + + /** @var string $last_name */ + protected $last_name; + + /** @var string $email */ + protected $email; + + /** @var string $password */ + protected $password; + + /** @var string $phone */ + protected $phone; + + /** @var int $user_status User Status */ + protected $user_status; + + public function __construct(array $data = null) { + if ($data != null) { + $this->id = $data["id"]; + $this->username = $data["username"]; + $this->first_name = $data["first_name"]; + $this->last_name = $data["last_name"]; + $this->email = $data["email"]; + $this->password = $data["password"]; + $this->phone = $data["phone"]; + $this->user_status = $data["user_status"]; + } } - } - - /** - * get id - * @return int - */ - public function getId() { - return $this->id; - } - - /** - * set id - * @param int $id - * @return $this - */ - public function setId($id) { - $this->id = $id; - return $this; - } - - /** - * get username - * @return string - */ - public function getUsername() { - return $this->username; - } - - /** - * set username - * @param string $username - * @return $this - */ - public function setUsername($username) { - $this->username = $username; - return $this; - } - - /** - * get first_name - * @return string - */ - public function getFirstName() { - return $this->first_name; - } - - /** - * set first_name - * @param string $first_name - * @return $this - */ - public function setFirstName($first_name) { - $this->first_name = $first_name; - return $this; - } - - /** - * get last_name - * @return string - */ - public function getLastName() { - return $this->last_name; - } - - /** - * set last_name - * @param string $last_name - * @return $this - */ - public function setLastName($last_name) { - $this->last_name = $last_name; - return $this; - } - - /** - * get email - * @return string - */ - public function getEmail() { - return $this->email; - } - - /** - * set email - * @param string $email - * @return $this - */ - public function setEmail($email) { - $this->email = $email; - return $this; - } - - /** - * get password - * @return string - */ - public function getPassword() { - return $this->password; - } - - /** - * set password - * @param string $password - * @return $this - */ - public function setPassword($password) { - $this->password = $password; - return $this; - } - - /** - * get phone - * @return string - */ - public function getPhone() { - return $this->phone; - } - - /** - * set phone - * @param string $phone - * @return $this - */ - public function setPhone($phone) { - $this->phone = $phone; - return $this; - } - - /** - * get user_status - * @return int - */ - public function getUserStatus() { - return $this->user_status; - } - - /** - * set user_status - * @param int $user_status - * @return $this - */ - public function setUserStatus($user_status) { - $this->user_status = $user_status; - return $this; - } - - public function offsetExists($offset) { - return isset($this->$offset); - } - - public function offsetGet($offset) { - return $this->$offset; - } - - public function offsetSet($offset, $value) { - $this->$offset = $value; - } - - public function offsetUnset($offset) { - unset($this->$offset); - } - - public function __toString() { - if (defined('JSON_PRETTY_PRINT')) { - return json_encode(get_object_vars($this), JSON_PRETTY_PRINT); - } else { - return json_encode(get_object_vars($this)); + + /** + * get id + * @return int + */ + public function getId() { + return $this->id; + } + + /** + * set id + * @param int $id + * @return $this + */ + public function setId($id) { + $this->id = $id; + return $this; + } + + /** + * get username + * @return string + */ + public function getUsername() { + return $this->username; + } + + /** + * set username + * @param string $username + * @return $this + */ + public function setUsername($username) { + $this->username = $username; + return $this; + } + + /** + * get first_name + * @return string + */ + public function getFirstName() { + return $this->first_name; + } + + /** + * set first_name + * @param string $first_name + * @return $this + */ + public function setFirstName($first_name) { + $this->first_name = $first_name; + return $this; + } + + /** + * get last_name + * @return string + */ + public function getLastName() { + return $this->last_name; + } + + /** + * set last_name + * @param string $last_name + * @return $this + */ + public function setLastName($last_name) { + $this->last_name = $last_name; + return $this; + } + + /** + * get email + * @return string + */ + public function getEmail() { + return $this->email; + } + + /** + * set email + * @param string $email + * @return $this + */ + public function setEmail($email) { + $this->email = $email; + return $this; + } + + /** + * get password + * @return string + */ + public function getPassword() { + return $this->password; + } + + /** + * set password + * @param string $password + * @return $this + */ + public function setPassword($password) { + $this->password = $password; + return $this; + } + + /** + * get phone + * @return string + */ + public function getPhone() { + return $this->phone; + } + + /** + * set phone + * @param string $phone + * @return $this + */ + public function setPhone($phone) { + $this->phone = $phone; + return $this; + } + + /** + * get user_status + * @return int + */ + public function getUserStatus() { + return $this->user_status; + } + + /** + * set user_status + * @param int $user_status + * @return $this + */ + public function setUserStatus($user_status) { + $this->user_status = $user_status; + return $this; + } + + public function offsetExists($offset) { + return isset($this->$offset); + } + + public function offsetGet($offset) { + return $this->$offset; + } + + public function offsetSet($offset, $value) { + $this->$offset = $value; + } + + public function offsetUnset($offset) { + unset($this->$offset); + } + + public function __toString() { + if (defined('JSON_PRETTY_PRINT')) { + return json_encode(get_object_vars($this), JSON_PRETTY_PRINT); + } else { + return json_encode(get_object_vars($this)); + } } - } } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php b/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php index 59b7601d1407..dd68d067c6aa 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php @@ -9,29 +9,29 @@ class ObjectSerializer { * @return string serialized form of $data */ public function sanitizeForSerialization($data) { - if (is_scalar($data) || null === $data) { - $sanitized = $data; - } else if ($data instanceof \DateTime) { - $sanitized = $data->format(\DateTime::ISO8601); - } else if (is_array($data)) { - foreach ($data as $property => $value) { - $data[$property] = $this->sanitizeForSerialization($value); + if (is_scalar($data) || null === $data) { + $sanitized = $data; + } else if ($data instanceof \DateTime) { + $sanitized = $data->format(\DateTime::ISO8601); + } else if (is_array($data)) { + foreach ($data as $property => $value) { + $data[$property] = $this->sanitizeForSerialization($value); + } + $sanitized = $data; + } else if (is_object($data)) { + $values = array(); + foreach (array_keys($data::$swaggerTypes) as $property) { + $getter = $data::$getters[$property]; + if ($data->$getter() !== null) { + $values[$data::$attributeMap[$property]] = $this->sanitizeForSerialization($data->$getter()); + } + } + $sanitized = $values; + } else { + $sanitized = (string)$data; } - $sanitized = $data; - } else if (is_object($data)) { - $values = array(); - foreach (array_keys($data::$swaggerTypes) as $property) { - $getter = $data::$getters[$property]; - if ($data->$getter() !== null) { - $values[$data::$attributeMap[$property]] = $this->sanitizeForSerialization($data->$getter()); - } - } - $sanitized = $values; - } else { - $sanitized = (string)$data; - } - return $sanitized; + return $sanitized; } /** @@ -41,7 +41,7 @@ class ObjectSerializer { * @return string the serialized object */ public function toPathValue($value) { - return rawurlencode($this->toString($value)); + return rawurlencode($this->toString($value)); } /** @@ -53,11 +53,11 @@ class ObjectSerializer { * @return string the serialized object */ public function toQueryValue($object) { - if (is_array($object)) { - return implode(',', $object); - } else { - return $this->toString($object); - } + if (is_array($object)) { + return implode(',', $object); + } else { + return $this->toString($object); + } } /** @@ -68,7 +68,7 @@ class ObjectSerializer { * @return string the header string */ public function toHeaderValue($value) { - return $this->toString($value); + return $this->toString($value); } /** @@ -79,11 +79,11 @@ class ObjectSerializer { * @return string the form string */ public function toFormValue($value) { - if ($value instanceof SplFileObject) { - return $value->getRealPath(); - } else { - return $this->toString($value); - } + if ($value instanceof SplFileObject) { + return $value->getRealPath(); + } else { + return $this->toString($value); + } } /** @@ -94,11 +94,11 @@ class ObjectSerializer { * @return string the header string */ public function toString($value) { - if ($value instanceof \DateTime) { // datetime in ISO8601 format - return $value->format(\DateTime::ISO8601); - } else { - return $value; - } + if ($value instanceof \DateTime) { // datetime in ISO8601 format + return $value->format(\DateTime::ISO8601); + } else { + return $value; + } } /** @@ -109,65 +109,63 @@ class ObjectSerializer { * @return object an instance of $class */ public function deserialize($data, $class, $httpHeader=null) { - if (null === $data) { - $deserialized = null; - } elseif (substr($class, 0, 4) == 'map[') { # for associative array e.g. map[string,int] - $inner = substr($class, 4, -1); - $deserialized = array(); - if(strrpos($inner, ",") !== false) { - $subClass_array = explode(',', $inner, 2); - $subClass = $subClass_array[1]; - foreach ($data as $key => $value) { - $deserialized[$key] = $this->deserialize($value, $subClass); - } + if (null === $data) { + $deserialized = null; + } elseif (substr($class, 0, 4) == 'map[') { # for associative array e.g. map[string,int] + $inner = substr($class, 4, -1); + $deserialized = array(); + if(strrpos($inner, ",") !== false) { + $subClass_array = explode(',', $inner, 2); + $subClass = $subClass_array[1]; + foreach ($data as $key => $value) { + $deserialized[$key] = $this->deserialize($value, $subClass); + } + } + } elseif (strcasecmp(substr($class, -2),'[]') == 0) { + $subClass = substr($class, 0, -2); + $values = array(); + foreach ($data as $key => $value) { + $values[] = $this->deserialize($value, $subClass); + } + $deserialized = $values; + } elseif ($class == 'DateTime') { + $deserialized = new \DateTime($data); + } elseif (in_array($class, array('string', 'int', 'float', 'double', 'bool', 'object'))) { + settype($data, $class); + $deserialized = $data; + } elseif ($class === '\SplFileObject') { + # determine temp folder path + $tmpFolderPath = Configuration::getDefaultConfiguration()->getTempFolderPath(); + print_r($tmpFolderPath); + + # determine file name + if (preg_match('/Content-Disposition: inline; filename=(.*)$/i', $httpHeader, $match)) { + $filename = $tmpFolderPath.$match[1]; + } else { + print_r($tmpFolderPath); + $filename = tempnam($tmpFolderPath, ''); + } + $deserialized = new \SplFileObject($filename, "w"); + $byte_written = $deserialized->fwrite($data); + error_log("[INFO] Written $byte_written byte to $filename. Please move the file to a proper folder or delete the temp file afterwards", 3, Configuration::getDefaultConfiguration()->getDebugFile()); + + } else { + $instance = new $class(); + foreach ($instance::$swaggerTypes as $property => $type) { + $propertySetter = $instance::$setters[$property]; + + if (!isset($propertySetter) || !isset($data->{$instance::$attributeMap[$property]})) { + continue; + } + + $propertyValue = $data->{$instance::$attributeMap[$property]}; + if (isset($propertyValue)) { + $instance->$propertySetter($this->deserialize($propertyValue, $type)); + } + } + $deserialized = $instance; } - } elseif (strcasecmp(substr($class, -2),'[]') == 0) { - $subClass = substr($class, 0, -2); - $values = array(); - foreach ($data as $key => $value) { - $values[] = $this->deserialize($value, $subClass); - } - $deserialized = $values; - } elseif ($class == 'DateTime') { - $deserialized = new \DateTime($data); - } elseif (in_array($class, array('string', 'int', 'float', 'double', 'bool', 'object'))) { - settype($data, $class); - $deserialized = $data; - } elseif ($class === '\SplFileObject') { - # determine temp folder path - if (!isset(Configuration::$tempFolderPath) || '' === Configuration::$tempFolderPath) { - $tmpFolderPath = sys_get_temp_dir(); - } else { - $tmpFolderPath = Configuration::tempFolderPath; - } - - # determine file name - if (preg_match('/Content-Disposition: inline; filename=(.*)/i', $httpHeader, $match)) { - $filename = $tmpFolderPath.$match[1]; - } else { - $filename = tempnam($tmpFolderPath, ''); - } - $deserialized = new \SplFileObject($filename, "w"); - $byte_written = $deserialized->fwrite($data); - error_log("[INFO] Written $byte_written byte to $filename. Please move the file to a proper folder or delete the temp file afterwards", 3, Configuration::getDefaultConfiguration()->getDebugFile()); - - } else { - $instance = new $class(); - foreach ($instance::$swaggerTypes as $property => $type) { - $propertySetter = $instance::$setters[$property]; - - if (!isset($propertySetter) || !isset($data->{$instance::$attributeMap[$property]})) { - continue; - } - - $propertyValue = $data->{$instance::$attributeMap[$property]}; - if (isset($propertyValue)) { - $instance->$propertySetter($this->deserialize($propertyValue, $type)); - } - } - $deserialized = $instance; - } - - return $deserialized; + + return $deserialized; } } diff --git a/samples/client/petstore/php/test.php b/samples/client/petstore/php/test.php index 55aae557a234..bec9f4e6e79b 100644 --- a/samples/client/petstore/php/test.php +++ b/samples/client/petstore/php/test.php @@ -12,12 +12,15 @@ require_once(__DIR__ . '/SwaggerClient-php/autoload.php'); // to enable logging //SwaggerClient\Configuration::$debug = true; //SwaggerClient\Configuration::$debug_file = '/var/tmp/php_debug.log'; +Swagger\Client\Configuration::getDefaultConfiguration()->setTempFolderPath('/var/tmp/php/'); $petId = 10005; // ID of pet that needs to be fetched try { // get pet by id //$pet_api = new SwaggerClient\PetAPI($api_client); $pet_api = new Swagger\Client\Api\PetAPI(); + $pet_api->getApiClient()->getConfig()->setTempFolderPath('/var/tmp/php/'); + print_r($pet_api->getApiClient()->getConfig()->getTempFolderPath()); // test default header //$pet_api->getApiClient()->addDefaultHeader("TEST_API_KEY", "09182sdkanafndsl903"); // return Pet (model) From 2258a4632d4f032f1e1a0d6af2f6f6aa7230370a Mon Sep 17 00:00:00 2001 From: wing328 Date: Sat, 27 Jun 2015 22:54:37 +0800 Subject: [PATCH 4/9] fix test.php, fix default configuration --- .../resources/php/ObjectSerializer.mustache | 15 +++------ .../main/resources/php/configuration.mustache | 32 +++++++++++++++++-- .../SwaggerClient-php/lib/Configuration.php | 17 +++++----- .../lib/ObjectSerializer.php | 13 +++----- samples/client/petstore/php/test.php | 24 +++++++------- 5 files changed, 60 insertions(+), 41 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache b/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache index 4463236063a9..930313865c76 100644 --- a/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache +++ b/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache @@ -134,22 +134,15 @@ class ObjectSerializer { settype($data, $class); $deserialized = $data; } elseif ($class === '\SplFileObject') { - # determine temp folder path - if (!isset(Configuration::getDefaultConfig->$tempFolderPath) || '' === Configuration::$tempFolderPath) { - $tmpFolderPath = sys_get_temp_dir(); - } else { - $tmpFolderPath = Configuration::tempFolderPath; - } - # determine file name - if (preg_match('/Content-Disposition: inline; filename=(.*)/i', $httpHeader, $match)) { - $filename = $tmpFolderPath.$match[1]; + if (preg_match('/Content-Disposition: inline; filename=[\'"]?([^\'"\s]+)[\'"]?$/i', $httpHeader, $match)) { + $filename = Configuration::getDefaultConfiguration()->getTempFolderPath().$match[1]; } else { - $filename = tempnam($tmpFolderPath, ''); + $filename = tempnam(Configuration::getDefaultConfiguration()->getTempFolderPath(), ''); } $deserialized = new \SplFileObject($filename, "w"); $byte_written = $deserialized->fwrite($data); - error_log("[INFO] Written $byte_written byte to $filename. Please move the file to a proper folder or delete the temp file afterwards", 3, Configuration::getDefaultConfiguration()->getDebugFile()); + error_log("[INFO] Written $byte_written byte to $filename. Please move the file to a proper folder or delete the temp file after processing.\n" , 3, Configuration::getDefaultConfiguration()->getDebugFile()); } else { $instance = new $class(); diff --git a/modules/swagger-codegen/src/main/resources/php/configuration.mustache b/modules/swagger-codegen/src/main/resources/php/configuration.mustache index 94e0165b4a83..710edab55b63 100644 --- a/modules/swagger-codegen/src/main/resources/php/configuration.mustache +++ b/modules/swagger-codegen/src/main/resources/php/configuration.mustache @@ -50,6 +50,16 @@ class Configuration { /** @var string Debug file location (log to STDOUT by default) */ protected $debugFile = 'php://output'; + + /** @var string Debug file location (log to STDOUT by default) */ + protected $tempFolderPath; + + /** + * @param string $tempFolderPath + */ + public function __construct() { + $this->tempFolderPath = sys_get_temp_dir(); + } /** * @param string $key @@ -248,13 +258,30 @@ class Configuration { public function getDebugFile() { return $this->debugFile; } - + + /** + * @param string $tempFolderPath + * @return Configuration + */ + public function setTempFolderPath($tempFolderPath) { + $this->tempFolderPath = $tempFolderPath; + return $this; + } + + /** + * @return string + */ + public function getTempFolderPath() { + return $this->tempFolderPath; + } + + /** * @return Configuration */ public static function getDefaultConfiguration() { if (self::$defaultConfiguration == null) { - return new Configuration(); + self::$defaultConfiguration = new Configuration(); } return self::$defaultConfiguration; @@ -276,6 +303,7 @@ class Configuration { $report .= " PHP Version: ".phpversion()."\n"; $report .= " Swagger Spec Version: {{version}}\n"; $report .= " SDK Package Version: {{version}}\n"; + $report .= " Temp Folder Path: ".self::getDefaultConfiguration()->getTempFolderPath()."\n"; return $report; } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php b/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php index 5f40dcfe3bdd..664293f1a13c 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php @@ -50,18 +50,17 @@ class Configuration { /** @var string Debug file location (log to STDOUT by default) */ protected $debugFile = 'php://output'; - + /** @var string Debug file location (log to STDOUT by default) */ protected $tempFolderPath; /** * @param string $tempFolderPath - */ + */ public function __construct() { $this->tempFolderPath = sys_get_temp_dir(); } - - + /** * @param string $key * @param string $value @@ -259,16 +258,16 @@ class Configuration { public function getDebugFile() { return $this->debugFile; } - + /** - * @param string $debugFile + * @param string $tempFolderPath * @return Configuration */ public function setTempFolderPath($tempFolderPath) { $this->tempFolderPath = $tempFolderPath; return $this; } - + /** * @return string */ @@ -276,12 +275,13 @@ class Configuration { return $this->tempFolderPath; } + /** * @return Configuration */ public static function getDefaultConfiguration() { if (self::$defaultConfiguration == null) { - return new Configuration(); + self::$defaultConfiguration = new Configuration(); } return self::$defaultConfiguration; @@ -303,6 +303,7 @@ class Configuration { $report .= " PHP Version: ".phpversion()."\n"; $report .= " Swagger Spec Version: 1.0.0\n"; $report .= " SDK Package Version: 1.0.0\n"; + $report .= " Temp Folder Path: ".self::getDefaultConfiguration()->getTempFolderPath()."\n"; return $report; } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php b/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php index dd68d067c6aa..3f78ea55bb93 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php @@ -134,20 +134,15 @@ class ObjectSerializer { settype($data, $class); $deserialized = $data; } elseif ($class === '\SplFileObject') { - # determine temp folder path - $tmpFolderPath = Configuration::getDefaultConfiguration()->getTempFolderPath(); - print_r($tmpFolderPath); - # determine file name - if (preg_match('/Content-Disposition: inline; filename=(.*)$/i', $httpHeader, $match)) { - $filename = $tmpFolderPath.$match[1]; + if (preg_match('/Content-Disposition: inline; filename=[\'"]?([^\'"\s]+)[\'"]?$/i', $httpHeader, $match)) { + $filename = Configuration::getDefaultConfiguration()->getTempFolderPath().$match[1]; } else { - print_r($tmpFolderPath); - $filename = tempnam($tmpFolderPath, ''); + $filename = tempnam(Configuration::getDefaultConfiguration()->getTempFolderPath(), ''); } $deserialized = new \SplFileObject($filename, "w"); $byte_written = $deserialized->fwrite($data); - error_log("[INFO] Written $byte_written byte to $filename. Please move the file to a proper folder or delete the temp file afterwards", 3, Configuration::getDefaultConfiguration()->getDebugFile()); + error_log("[INFO] Written $byte_written byte to $filename. Please move the file to a proper folder or delete the temp file after processing.\n" , 3, Configuration::getDefaultConfiguration()->getDebugFile()); } else { $instance = new $class(); diff --git a/samples/client/petstore/php/test.php b/samples/client/petstore/php/test.php index bec9f4e6e79b..79cc4ca4ad75 100644 --- a/samples/client/petstore/php/test.php +++ b/samples/client/petstore/php/test.php @@ -5,22 +5,24 @@ require_once(__DIR__ . '/SwaggerClient-php/autoload.php'); //ini_set('display_errors', 1); //error_reporting(~0); -// initialize the API client -//$api_client = new SwaggerClient\ApiClient('http://petstore.swagger.io/v2'); -//$api_client->addDefaultHeader("test1", "value1"); - // to enable logging -//SwaggerClient\Configuration::$debug = true; -//SwaggerClient\Configuration::$debug_file = '/var/tmp/php_debug.log'; +//Swagger\Client\Configuration::$debug = true; +//Swagger\Client\Configuration::$debug_file = '/var/tmp/php_debug.log'; + +// to debug report +print Swagger\Client\Configuration::toDebugReport(); + +// to change temp folder path Swagger\Client\Configuration::getDefaultConfiguration()->setTempFolderPath('/var/tmp/php/'); $petId = 10005; // ID of pet that needs to be fetched try { // get pet by id - //$pet_api = new SwaggerClient\PetAPI($api_client); + //$api_client = new Swagger\Client\ApiClient('http://petstore.swagger.io/v2'); + //$api_client->getConfig()->addDefaultHeader("test1", "value1"); + //$pet_api = new Swagger\Client\PetAPI($api_client); $pet_api = new Swagger\Client\Api\PetAPI(); $pet_api->getApiClient()->getConfig()->setTempFolderPath('/var/tmp/php/'); - print_r($pet_api->getApiClient()->getConfig()->getTempFolderPath()); // test default header //$pet_api->getApiClient()->addDefaultHeader("TEST_API_KEY", "09182sdkanafndsl903"); // return Pet (model) @@ -49,10 +51,10 @@ try { // add a new pet (model) $add_response = $pet_api->addPet($new_pet); - // test upload file (exception) - //$upload_response = $pet_api->uploadFile($petId, "test meta", NULL); + // test upload file (should return exception) + $upload_response = $pet_api->uploadFile($petId, "test meta", NULL); -} catch (Swagger\Client\Exception $e) { +} catch (Swagger\Client\ApiException $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; echo 'HTTP response headers: ', $e->getResponseHeaders(), "\n"; echo 'HTTP response body: ', $e->getResponseBody(), "\n"; From 38149173ff15b6aece68e03e68043165d4d3de35 Mon Sep 17 00:00:00 2001 From: wing328 Date: Sat, 27 Jun 2015 23:26:59 +0800 Subject: [PATCH 5/9] revert petstore json, fixed test case --- .../swagger-codegen/src/test/resources/2_0/petstore.json | 2 +- .../petstore/php/SwaggerClient-php/lib/Api/PetApi.php | 8 ++++---- .../petstore/php/SwaggerClient-php/tests/PetApiTest.php | 6 ++++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/modules/swagger-codegen/src/test/resources/2_0/petstore.json b/modules/swagger-codegen/src/test/resources/2_0/petstore.json index df781a90c494..66762d74b2bc 100644 --- a/modules/swagger-codegen/src/test/resources/2_0/petstore.json +++ b/modules/swagger-codegen/src/test/resources/2_0/petstore.json @@ -235,7 +235,7 @@ "200": { "description": "successful operation", "schema": { - "type": "file" + "$ref": "#/definitions/Pet" } }, "400": { 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 54926f3c9f74..6971e0904652 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php @@ -329,7 +329,7 @@ class PetApi { * Find pet by ID * * @param int $pet_id ID of pet that needs to be fetched (required) - * @return \SplFileObject + * @return \Swagger\Client\Model\Pet * @throws \Swagger\Client\ApiException on non-2xx response */ public function getPetById($pet_id) { @@ -387,11 +387,11 @@ class PetApi { try { list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, $queryParams, $httpBody, - $headerParams, '\SplFileObject'); + $headerParams, '\Swagger\Client\Model\Pet'); } catch (ApiException $e) { switch ($e->getCode()) { case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\SplFileObject', $httpHeader); + $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Pet', $httpHeader); $e->setResponseObject($data); break; } @@ -403,7 +403,7 @@ class PetApi { return null; } - return $this->apiClient->getSerializer()->deserialize($response,'\SplFileObject'); + return $this->apiClient->getSerializer()->deserialize($response,'\Swagger\Client\Model\Pet'); } diff --git a/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php b/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php index 76c88d20c4e9..fe818069dac5 100644 --- a/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php @@ -70,9 +70,11 @@ class PetApiTest extends \PHPUnit_Framework_TestCase $this->assertFalse(isset($defaultHeader['test2'])); $pet_api2 = new Swagger\Client\Api\PetAPI(); - $apiClient3 = new Swagger\Client\ApiClient(); + $config3 = new Swagger\Client\Configuration(); + $apiClient3 = new Swagger\Client\ApiClient($config3); $apiClient3->getConfig()->setUserAgent('api client 3'); - $apiClient4 = new Swagger\Client\ApiClient(); + $config4 = new Swagger\Client\Configuration(); + $apiClient4 = new Swagger\Client\ApiClient($config4); $apiClient4->getConfig()->setUserAgent('api client 4'); $pet_api3 = new Swagger\Client\Api\PetAPI($apiClient3); From 71a22141bfc4491c8812047283db2912709f677c Mon Sep 17 00:00:00 2001 From: wing328 Date: Thu, 2 Jul 2015 16:17:36 +0800 Subject: [PATCH 6/9] add enum support for model property --- .../src/main/resources/php/api.mustache | 4 +- .../src/main/resources/php/model.mustache | 4 ++ .../php/SwaggerClient-php/lib/Api/PetApi.php | 24 ++++-------- .../SwaggerClient-php/lib/Api/StoreApi.php | 12 ++---- .../php/SwaggerClient-php/lib/Api/UserApi.php | 22 ++++------- .../SwaggerClient-php/lib/Model/Category.php | 2 + .../php/SwaggerClient-php/lib/Model/Order.php | 9 +++++ .../php/SwaggerClient-php/lib/Model/Pet.php | 9 +++++ .../php/SwaggerClient-php/lib/Model/Tag.php | 2 + .../php/SwaggerClient-php/lib/Model/User.php | 8 ++++ .../SwaggerClient-php/tests/OrderApiTest.php | 38 +++++++++++++++++++ 11 files changed, 93 insertions(+), 41 deletions(-) create mode 100644 samples/client/petstore/php/SwaggerClient-php/tests/OrderApiTest.php diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index 5a97244bfe88..6255a59d8e02 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -76,9 +76,7 @@ class {{classname}} { // verify the required parameter '{{paramName}}' is set if (${{paramName}} === null) { throw new \InvalidArgumentException('Missing the required parameter ${{paramName}} when calling {{nickname}}'); ->>>>>>> temporary folder setting - } - {{/required}}{{/allParams}} + }{{/required}}{{/allParams}} // parse inputs $resourcePath = "{{path}}"; diff --git a/modules/swagger-codegen/src/main/resources/php/model.mustache b/modules/swagger-codegen/src/main/resources/php/model.mustache index 9b8307f6ec47..df4ddc0b4f06 100644 --- a/modules/swagger-codegen/src/main/resources/php/model.mustache +++ b/modules/swagger-codegen/src/main/resources/php/model.mustache @@ -78,6 +78,10 @@ class {{classname}} implements ArrayAccess { * @return $this */ public function {{setter}}(${{name}}) { + {{#isEnum}}$allowed_values = array({{#allowableValues}}{{#values}}"{{{this}}}"{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}); + if (!in_array(${{{name}}}, $allowed_values)) { + throw new \InvalidArgumentException("Invalid value for '{{name}}', must be one of {{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}"); + }{{/isEnum}} $this->{{name}} = ${{name}}; return $this; } 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 6971e0904652..3620252ea513 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php @@ -72,7 +72,7 @@ class PetApi { */ public function updatePet($body) { - + // parse inputs $resourcePath = "/pet"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -133,7 +133,7 @@ class PetApi { */ public function addPet($body) { - + // parse inputs $resourcePath = "/pet"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -194,7 +194,7 @@ class PetApi { */ public function findPetsByStatus($status) { - + // parse inputs $resourcePath = "/pet/findByStatus"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -264,7 +264,7 @@ class PetApi { */ public function findPetsByTags($tags) { - + // parse inputs $resourcePath = "/pet/findByTags"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -333,13 +333,11 @@ class PetApi { * @throws \Swagger\Client\ApiException on non-2xx response */ public function getPetById($pet_id) { - // verify the required parameter 'pet_id' is set if ($pet_id === null) { throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling getPetById'); } - - + // parse inputs $resourcePath = "/pet/{petId}"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -419,13 +417,11 @@ class PetApi { * @throws \Swagger\Client\ApiException on non-2xx response */ public function updatePetWithForm($pet_id, $name, $status) { - // verify the required parameter 'pet_id' is set if ($pet_id === null) { throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling updatePetWithForm'); } - - + // parse inputs $resourcePath = "/pet/{petId}"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -493,13 +489,11 @@ class PetApi { * @throws \Swagger\Client\ApiException on non-2xx response */ public function deletePet($api_key, $pet_id) { - // verify the required parameter 'pet_id' is set if ($pet_id === null) { throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling deletePet'); } - - + // parse inputs $resourcePath = "/pet/{petId}"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -565,13 +559,11 @@ class PetApi { * @throws \Swagger\Client\ApiException on non-2xx response */ public function uploadFile($pet_id, $additional_metadata, $file) { - // verify the required parameter 'pet_id' is set if ($pet_id === null) { throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling uploadFile'); } - - + // parse inputs $resourcePath = "/pet/{petId}/uploadImage"; $resourcePath = str_replace("{format}", "json", $resourcePath); 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 a132b3e3ef5d..9947628fdf68 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php @@ -71,7 +71,7 @@ class StoreApi { */ public function getInventory() { - + // parse inputs $resourcePath = "/store/inventory"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -142,7 +142,7 @@ class StoreApi { */ public function placeOrder($body) { - + // parse inputs $resourcePath = "/store/order"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -209,13 +209,11 @@ class StoreApi { * @throws \Swagger\Client\ApiException on non-2xx response */ public function getOrderById($order_id) { - // verify the required parameter 'order_id' is set if ($order_id === null) { throw new \InvalidArgumentException('Missing the required parameter $order_id when calling getOrderById'); } - - + // parse inputs $resourcePath = "/store/order/{orderId}"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -283,13 +281,11 @@ class StoreApi { * @throws \Swagger\Client\ApiException on non-2xx response */ public function deleteOrder($order_id) { - // verify the required parameter 'order_id' is set if ($order_id === null) { throw new \InvalidArgumentException('Missing the required parameter $order_id when calling deleteOrder'); } - - + // parse inputs $resourcePath = "/store/order/{orderId}"; $resourcePath = str_replace("{format}", "json", $resourcePath); 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 62204e182e79..d0b98f348e31 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php @@ -72,7 +72,7 @@ class UserApi { */ public function createUser($body) { - + // parse inputs $resourcePath = "/user"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -130,7 +130,7 @@ class UserApi { */ public function createUsersWithArrayInput($body) { - + // parse inputs $resourcePath = "/user/createWithArray"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -188,7 +188,7 @@ class UserApi { */ public function createUsersWithListInput($body) { - + // parse inputs $resourcePath = "/user/createWithList"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -247,7 +247,7 @@ class UserApi { */ public function loginUser($username, $password) { - + // parse inputs $resourcePath = "/user/login"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -316,7 +316,7 @@ class UserApi { */ public function logoutUser() { - + // parse inputs $resourcePath = "/user/logout"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -369,13 +369,11 @@ class UserApi { * @throws \Swagger\Client\ApiException on non-2xx response */ public function getUserByName($username) { - // verify the required parameter 'username' is set if ($username === null) { throw new \InvalidArgumentException('Missing the required parameter $username when calling getUserByName'); } - - + // parse inputs $resourcePath = "/user/{username}"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -444,13 +442,11 @@ class UserApi { * @throws \Swagger\Client\ApiException on non-2xx response */ public function updateUser($username, $body) { - // verify the required parameter 'username' is set if ($username === null) { throw new \InvalidArgumentException('Missing the required parameter $username when calling updateUser'); } - - + // parse inputs $resourcePath = "/user/{username}"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -512,13 +508,11 @@ class UserApi { * @throws \Swagger\Client\ApiException on non-2xx response */ public function deleteUser($username) { - // verify the required parameter 'username' is set if ($username === null) { throw new \InvalidArgumentException('Missing the required parameter $username when calling deleteUser'); } - - + // parse inputs $resourcePath = "/user/{username}"; $resourcePath = str_replace("{format}", "json", $resourcePath); diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php index eb6603043df1..02b3d3cde0f6 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php @@ -79,6 +79,7 @@ class Category implements ArrayAccess { * @return $this */ public function setId($id) { + $this->id = $id; return $this; } @@ -97,6 +98,7 @@ class Category implements ArrayAccess { * @return $this */ public function setName($name) { + $this->name = $name; return $this; } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php index bcea02d96862..9b20b159ab9f 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php @@ -111,6 +111,7 @@ class Order implements ArrayAccess { * @return $this */ public function setId($id) { + $this->id = $id; return $this; } @@ -129,6 +130,7 @@ class Order implements ArrayAccess { * @return $this */ public function setPetId($pet_id) { + $this->pet_id = $pet_id; return $this; } @@ -147,6 +149,7 @@ class Order implements ArrayAccess { * @return $this */ public function setQuantity($quantity) { + $this->quantity = $quantity; return $this; } @@ -165,6 +168,7 @@ class Order implements ArrayAccess { * @return $this */ public function setShipDate($ship_date) { + $this->ship_date = $ship_date; return $this; } @@ -183,6 +187,10 @@ class Order implements ArrayAccess { * @return $this */ public function setStatus($status) { + $allowed_values = array("placed", "approved", "delivered"); + if (!in_array($status, $allowed_values)) { + throw new \InvalidArgumentException("Invalid value for 'status', must be one of 'placed', 'approved', 'delivered'"); + } $this->status = $status; return $this; } @@ -201,6 +209,7 @@ class Order implements ArrayAccess { * @return $this */ public function setComplete($complete) { + $this->complete = $complete; return $this; } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php index 2e6947144c97..03c5b173532f 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php @@ -111,6 +111,7 @@ class Pet implements ArrayAccess { * @return $this */ public function setId($id) { + $this->id = $id; return $this; } @@ -129,6 +130,7 @@ class Pet implements ArrayAccess { * @return $this */ public function setCategory($category) { + $this->category = $category; return $this; } @@ -147,6 +149,7 @@ class Pet implements ArrayAccess { * @return $this */ public function setName($name) { + $this->name = $name; return $this; } @@ -165,6 +168,7 @@ class Pet implements ArrayAccess { * @return $this */ public function setPhotoUrls($photo_urls) { + $this->photo_urls = $photo_urls; return $this; } @@ -183,6 +187,7 @@ class Pet implements ArrayAccess { * @return $this */ public function setTags($tags) { + $this->tags = $tags; return $this; } @@ -201,6 +206,10 @@ class Pet implements ArrayAccess { * @return $this */ public function setStatus($status) { + $allowed_values = array("available", "pending", "sold"); + if (!in_array($status, $allowed_values)) { + throw new \InvalidArgumentException("Invalid value for 'status', must be one of 'available', 'pending', 'sold'"); + } $this->status = $status; return $this; } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php index bdd133810c57..279618ac3bea 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php @@ -79,6 +79,7 @@ class Tag implements ArrayAccess { * @return $this */ public function setId($id) { + $this->id = $id; return $this; } @@ -97,6 +98,7 @@ class Tag implements ArrayAccess { * @return $this */ public function setName($name) { + $this->name = $name; return $this; } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php index 160d93e8f58d..7dd45220cf93 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php @@ -127,6 +127,7 @@ class User implements ArrayAccess { * @return $this */ public function setId($id) { + $this->id = $id; return $this; } @@ -145,6 +146,7 @@ class User implements ArrayAccess { * @return $this */ public function setUsername($username) { + $this->username = $username; return $this; } @@ -163,6 +165,7 @@ class User implements ArrayAccess { * @return $this */ public function setFirstName($first_name) { + $this->first_name = $first_name; return $this; } @@ -181,6 +184,7 @@ class User implements ArrayAccess { * @return $this */ public function setLastName($last_name) { + $this->last_name = $last_name; return $this; } @@ -199,6 +203,7 @@ class User implements ArrayAccess { * @return $this */ public function setEmail($email) { + $this->email = $email; return $this; } @@ -217,6 +222,7 @@ class User implements ArrayAccess { * @return $this */ public function setPassword($password) { + $this->password = $password; return $this; } @@ -235,6 +241,7 @@ class User implements ArrayAccess { * @return $this */ public function setPhone($phone) { + $this->phone = $phone; return $this; } @@ -253,6 +260,7 @@ class User implements ArrayAccess { * @return $this */ public function setUserStatus($user_status) { + $this->user_status = $user_status; return $this; } diff --git a/samples/client/petstore/php/SwaggerClient-php/tests/OrderApiTest.php b/samples/client/petstore/php/SwaggerClient-php/tests/OrderApiTest.php new file mode 100644 index 000000000000..7672667a2358 --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/tests/OrderApiTest.php @@ -0,0 +1,38 @@ +setStatus("placed"); + $this->assertSame("placed", $order->getStatus()); + } + + /** + * @expectedException InvalidArgumentException + */ + public function testOrderException() + { + // initialize the API client + $order = new Swagger\Client\Model\Order(); + $order->setStatus("invalid_value"); + } + +} + +?> + From 44705b566d9d1b210532c8b2f8f646c177728b06 Mon Sep 17 00:00:00 2001 From: wing328 Date: Mon, 6 Jul 2015 15:21:24 +0800 Subject: [PATCH 7/9] add default version for package --- .../java/io/swagger/codegen/languages/PhpClientCodegen.java | 2 +- .../src/main/resources/php/configuration.mustache | 2 +- samples/client/petstore/php/SwaggerClient-php/composer.json | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java index c6e6d65596c3..4034b966cb6b 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java @@ -20,7 +20,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig { protected String groupId = "swagger"; protected String artifactId = "swagger-client"; protected String packagePath = "SwaggerClient-php"; - protected String artifactVersion = null; + protected String artifactVersion = "1.0.0"; protected String srcBasePath = "lib"; public PhpClientCodegen() { diff --git a/modules/swagger-codegen/src/main/resources/php/configuration.mustache b/modules/swagger-codegen/src/main/resources/php/configuration.mustache index 710edab55b63..a1d8c78c40eb 100644 --- a/modules/swagger-codegen/src/main/resources/php/configuration.mustache +++ b/modules/swagger-codegen/src/main/resources/php/configuration.mustache @@ -302,7 +302,7 @@ class Configuration { $report .= " OS: ".php_uname()."\n"; $report .= " PHP Version: ".phpversion()."\n"; $report .= " Swagger Spec Version: {{version}}\n"; - $report .= " SDK Package Version: {{version}}\n"; + $report .= " SDK Package Version: {{artifactVersion}}\n"; $report .= " Temp Folder Path: ".self::getDefaultConfiguration()->getTempFolderPath()."\n"; return $report; diff --git a/samples/client/petstore/php/SwaggerClient-php/composer.json b/samples/client/petstore/php/SwaggerClient-php/composer.json index 5a76d804876b..3b432d83b92b 100644 --- a/samples/client/petstore/php/SwaggerClient-php/composer.json +++ b/samples/client/petstore/php/SwaggerClient-php/composer.json @@ -1,5 +1,6 @@ { "name": "swagger/swagger-client", + "version": "1.0.0", "description": "", "keywords": [ "swagger", From f154e407d2e8cd06f2b798c53788301dddea5bc0 Mon Sep 17 00:00:00 2001 From: wing328 Date: Mon, 13 Jul 2015 00:53:32 +0800 Subject: [PATCH 8/9] update coding style based on CodeSniffer --- .../src/main/resources/php/ApiClient.mustache | 106 +++- .../main/resources/php/ApiException.mustache | 78 ++- .../resources/php/ObjectSerializer.mustache | 97 +++- .../src/main/resources/php/api.mustache | 88 ++- .../main/resources/php/configuration.mustache | 333 ++++++++--- .../src/main/resources/php/model.mustache | 122 +++- .../php/SwaggerClient-php/lib/Api/PetApi.php | 266 +++++---- .../SwaggerClient-php/lib/Api/StoreApi.php | 168 ++++-- .../php/SwaggerClient-php/lib/Api/UserApi.php | 244 +++++--- .../php/SwaggerClient-php/lib/ApiClient.php | 106 +++- .../SwaggerClient-php/lib/ApiException.php | 78 ++- .../SwaggerClient-php/lib/Configuration.php | 333 ++++++++--- .../SwaggerClient-php/lib/Model/Category.php | 135 ++++- .../php/SwaggerClient-php/lib/Model/Order.php | 203 +++++-- .../php/SwaggerClient-php/lib/Model/Pet.php | 203 +++++-- .../php/SwaggerClient-php/lib/Model/Tag.php | 135 ++++- .../php/SwaggerClient-php/lib/Model/User.php | 237 +++++--- .../lib/ObjectSerializer.php | 97 +++- .../php/SwaggerClient-php/lib/PetApi.php | 543 ------------------ .../php/SwaggerClient-php/lib/StoreApi.php | 294 ---------- .../php/SwaggerClient-php/lib/UserApi.php | 518 ----------------- 21 files changed, 2203 insertions(+), 2181 deletions(-) delete mode 100644 samples/client/petstore/php/SwaggerClient-php/lib/PetApi.php delete mode 100644 samples/client/petstore/php/SwaggerClient-php/lib/StoreApi.php delete mode 100644 samples/client/petstore/php/SwaggerClient-php/lib/UserApi.php diff --git a/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache index 158c9c662c00..3c6819ab73be 100644 --- a/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache @@ -1,4 +1,15 @@ config; } /** - * get the serializer + * Get the serializer * @return ObjectSerializer */ - public function getSerializer() { + public function getSerializer() + { return $this->serializer; } /** * Get API key (with prefix if set) - * @param string $apiKey name of apikey + * @param string $apiKeyIdentifier name of apikey * @return string API key with the prefix */ - public function getApiKeyWithPrefix($apiKeyIdentifier) { + public function getApiKeyWithPrefix($apiKeyIdentifier) + { $prefix = $this->config->getApiKeyPrefix($apiKeyIdentifier); $apiKey = $this->config->getApiKey($apiKeyIdentifier); @@ -82,20 +119,26 @@ class ApiClient { } /** + * Make the HTTP call (Sync) * @param string $resourcePath path to method endpoint - * @param string $method method to call - * @param array $queryParams parameters to be place in query URL - * @param array $postData parameters to be placed in POST body - * @param array $headerParams parameters to be place in request header + * @param string $method method to call + * @param array $queryParams parameters to be place in query URL + * @param array $postData parameters to be placed in POST body + * @param array $headerParams parameters to be place in request header + * @param string $responseType expected response type of the endpoint * @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(); - # construct the http header - $headerParams = array_merge((array)$this->config->getDefaultHeaders(), (array)$headerParams); + // construct the http header + $headerParams = array_merge( + (array)$this->config->getDefaultHeaders(), + (array)$headerParams + ); foreach ($headerParams as $key => $val) { $headers[] = "$key: $val"; @@ -104,8 +147,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 + } else if ((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)); } @@ -184,21 +226,25 @@ class ApiClient { $data = $http_body; } } else { - throw new ApiException("[".$response_info['http_code']."] Error connecting to the API ($url)", - $response_info['http_code'], $http_header, $http_body); + throw new ApiException( + "[".$response_info['http_code']."] Error connecting to the API ($url)", + $response_info['http_code'], $http_header, $http_body + ); } return array($data, $http_header); } - /* - * return the header 'Accept' based on an array of Accept provided + /** + * Return the header 'Accept' based on an array of Accept provided * * @param string[] $accept Array of header + * * @return string Accept (e.g. application/json) */ - public static function selectHeaderAccept($accept) { + public static function selectHeaderAccept($accept) + { if (count($accept) === 0 or (count($accept) === 1 and $accept[0] === '')) { - return NULL; + return null; } elseif (preg_grep("/application\/json/i", $accept)) { return 'application/json'; } else { @@ -206,13 +252,15 @@ class ApiClient { } } - /* - * return the content type based on an array of content-type provided + /** + * Return the content type based on an array of content-type provided + * + * @param string[] $content_type Array fo content-type * - * @param string[] content_type_array Array fo content-type * @return string Content-Type (e.g. application/json) */ - public static function selectHeaderContentType($content_type) { + public static function selectHeaderContentType($content_type) + { if (count($content_type) === 0 or (count($content_type) === 1 and $content_type[0] === '')) { return 'application/json'; } elseif (preg_grep("/application\/json/i", $content_type)) { diff --git a/modules/swagger-codegen/src/main/resources/php/ApiException.mustache b/modules/swagger-codegen/src/main/resources/php/ApiException.mustache index c57310ccece4..79d1b4fe0a15 100644 --- a/modules/swagger-codegen/src/main/resources/php/ApiException.mustache +++ b/modules/swagger-codegen/src/main/resources/php/ApiException.mustache @@ -1,4 +1,14 @@ responseHeaders = $responseHeaders; $this->responseBody = $responseBody; } /** - * Get the HTTP response header + * Gets the HTTP response header * * @return string HTTP response header */ - public function getResponseHeaders() { + public function getResponseHeaders() + { return $this->responseHeaders; } /** - * Get the HTTP response body + * Gets the HTTP response body * * @return string HTTP response body */ - public function getResponseBody() { + public function getResponseBody() + { return $this->responseBody; } /** - * sets the deseralized response object (during deserialization) - * @param mixed $obj + * Sets the deseralized response object (during deserialization) + * @param mixed $obj Deserialized response object + * @return void */ - public function setResponseObject($obj) { + public function setResponseObject($obj) + { $this->responseObject = $obj; } - - public function getResponseObject() { + + /** + * Gets the deseralized response object (during deserialization) + * + * @return mixed the deserialized response object + */ + public function getResponseObject() + { return $this->responseObject; } } diff --git a/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache b/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache index 930313865c76..1d63440b66fd 100644 --- a/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache +++ b/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache @@ -1,14 +1,59 @@ toString($value)); } @@ -49,10 +97,13 @@ class ObjectSerializer { * the query, by imploding comma-separated if it's an object. * If it's a string, pass through unchanged. It will be url-encoded * later. + * * @param object $object an object to be serialized to a string + * * @return string the serialized object */ - public function toQueryValue($object) { + public function toQueryValue($object) + { if (is_array($object)) { return implode(',', $object); } else { @@ -64,10 +115,13 @@ class ObjectSerializer { * Take value and turn it into a string suitable for inclusion in * the header. If it's a string, pass through unchanged * If it's a datetime object, format it in ISO8601 + * * @param string $value a string which will be part of the header + * * @return string the header string */ - public function toHeaderValue($value) { + public function toHeaderValue($value) + { return $this->toString($value); } @@ -75,10 +129,13 @@ class ObjectSerializer { * Take value and turn it into a string suitable for inclusion in * the http body (form parameter). If it's a string, pass through unchanged * If it's a datetime object, format it in ISO8601 + * * @param string $value the value of the form parameter + * * @return string the form string */ - public function toFormValue($value) { + public function toFormValue($value) + { if ($value instanceof SplFileObject) { return $value->getRealPath(); } else { @@ -90,10 +147,13 @@ class ObjectSerializer { * Take value and turn it into a string suitable for inclusion in * the parameter. If it's a string, pass through unchanged * If it's a datetime object, format it in ISO8601 + * * @param string $value the value of the parameter + * * @return string the header string */ - public function toString($value) { + public function toString($value) + { if ($value instanceof \DateTime) { // datetime in ISO8601 format return $value->format(\DateTime::ISO8601); } else { @@ -104,37 +164,40 @@ class ObjectSerializer { /** * Deserialize a JSON string into an object * - * @param mixed $data object or primitive to be deserialized - * @param string $class class name is passed as a string + * @param mixed $data object or primitive to be deserialized + * @param string $class class name is passed as a string + * @param string $httpHeader HTTP headers + * * @return object an instance of $class */ - public function deserialize($data, $class, $httpHeader=null) { + public function deserialize($data, $class, $httpHeader=null) + { if (null === $data) { $deserialized = null; - } elseif (substr($class, 0, 4) == 'map[') { # for associative array e.g. map[string,int] + } elseif (substr($class, 0, 4) === 'map[') { // for associative array e.g. map[string,int] $inner = substr($class, 4, -1); $deserialized = array(); - if(strrpos($inner, ",") !== false) { + if (strrpos($inner, ",") !== false) { $subClass_array = explode(',', $inner, 2); $subClass = $subClass_array[1]; foreach ($data as $key => $value) { $deserialized[$key] = $this->deserialize($value, $subClass); } } - } elseif (strcasecmp(substr($class, -2),'[]') == 0) { + } elseif (strcasecmp(substr($class, -2), '[]') == 0) { $subClass = substr($class, 0, -2); $values = array(); foreach ($data as $key => $value) { $values[] = $this->deserialize($value, $subClass); } $deserialized = $values; - } elseif ($class == 'DateTime') { + } elseif ($class === 'DateTime') { $deserialized = new \DateTime($data); } elseif (in_array($class, array('string', 'int', 'float', 'double', 'bool', 'object'))) { settype($data, $class); $deserialized = $data; } elseif ($class === '\SplFileObject') { - # determine file name + // determine file name if (preg_match('/Content-Disposition: inline; filename=[\'"]?([^\'"\s]+)[\'"]?$/i', $httpHeader, $match)) { $filename = Configuration::getDefaultConfiguration()->getTempFolderPath().$match[1]; } else { @@ -142,7 +205,7 @@ class ObjectSerializer { } $deserialized = new \SplFileObject($filename, "w"); $byte_written = $deserialized->fwrite($data); - error_log("[INFO] Written $byte_written byte to $filename. Please move the file to a proper folder or delete the temp file after processing.\n" , 3, Configuration::getDefaultConfiguration()->getDebugFile()); + error_log("[INFO] Written $byte_written byte to $filename. Please move the file to a proper folder or delete the temp file after processing.\n", 3, Configuration::getDefaultConfiguration()->getDebugFile()); } else { $instance = new $class(); @@ -150,7 +213,7 @@ class ObjectSerializer { $propertySetter = $instance::$setters[$property]; if (!isset($propertySetter) || !isset($data->{$instance::$attributeMap[$property]})) { - continue; + continue; } $propertyValue = $data->{$instance::$attributeMap[$property]}; diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index 6255a59d8e02..bb40ae7a98d6 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -1,4 +1,14 @@ getConfig()->setHost('{{basePath}}'); @@ -46,17 +71,21 @@ class {{classname}} { } /** + * Get API client * @return \{{invokerPackage}}\ApiClient get the API client */ - public function getApiClient() { + public function getApiClient() + { return $this->apiClient; } /** + * Set the API client * @param \{{invokerPackage}}\ApiClient $apiClient set the API client * @return {{classname}} */ - public function setApiClient(ApiClient $apiClient) { + public function setApiClient(ApiClient $apiClient) + { $this->apiClient = $apiClient; return $this; } @@ -71,7 +100,8 @@ class {{classname}} { {{/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 {{nickname}}({{#allParams}}${{paramName}}{{^required}}=null{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) + { {{#allParams}}{{#required}} // verify the required parameter '{{paramName}}' is set if (${{paramName}} === null) { @@ -93,18 +123,20 @@ class {{classname}} { $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array({{#consumes}}'{{mediaType}}'{{#hasMore}},{{/hasMore}}{{/consumes}})); {{#queryParams}}// query params - if(${{paramName}} !== null) { + if (${{paramName}} !== null) { $queryParams['{{baseName}}'] = $this->apiClient->getSerializer()->toQueryValue(${{paramName}}); }{{/queryParams}} {{#headerParams}}// header params - if(${{paramName}} !== null) { + if (${{paramName}} !== null) { $headerParams['{{baseName}}'] = $this->apiClient->getSerializer()->toHeaderValue(${{paramName}}); }{{/headerParams}} {{#pathParams}}// path params - if(${{paramName}} !== null) { - $resourcePath = str_replace("{" . "{{baseName}}" . "}", - $this->apiClient->getSerializer()->toPathValue(${{paramName}}), - $resourcePath); + if (${{paramName}} !== null) { + $resourcePath = str_replace( + "{" . "{{baseName}}" . "}", + $this->apiClient->getSerializer()->toPathValue(${{paramName}}), + $resourcePath + ); }{{/pathParams}} {{#formParams}}// form params if (${{paramName}} !== null) { @@ -120,8 +152,7 @@ class {{classname}} { if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; + $httpBody = $formParams; // for HTTP post (form) } {{#authMethods}}{{#isApiKey}} $apiKey = $this->apiClient->getApiKeyWithPrefix('{{keyParamName}}'); @@ -132,16 +163,19 @@ class {{classname}} { {{#isOAuth}}//TODO support oauth{{/isOAuth}} {{/authMethods}} // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams{{#returnType}}, '{{returnType}}'{{/returnType}}); + try + { + list($response, $httpHeader) = $this->apiClient->callApi( + $resourcePath, $method, + $queryParams, $httpBody, + $headerParams{{#returnType}}, '{{returnType}}'{{/returnType}} + ); } catch (ApiException $e) { switch ($e->getCode()) { {{#responses}}{{#dataType}} - case {{code}}: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '{{dataType}}', $httpHeader); - $e->setResponseObject($data); - break;{{/dataType}}{{/responses}} + case {{code}}: + $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '{{dataType}}', $httpHeader); + $e->setResponseObject($data); + break;{{/dataType}}{{/responses}} } throw $e; @@ -151,7 +185,7 @@ class {{classname}} { return null; } - return $this->apiClient->getSerializer()->deserialize($response,'{{returnType}}'); + return $this->apiClient->getSerializer()->deserialize($response, '{{returnType}}'); {{/returnType}} } {{/operation}} diff --git a/modules/swagger-codegen/src/main/resources/php/configuration.mustache b/modules/swagger-codegen/src/main/resources/php/configuration.mustache index a1d8c78c40eb..73d4000d950f 100644 --- a/modules/swagger-codegen/src/main/resources/php/configuration.mustache +++ b/modules/swagger-codegen/src/main/resources/php/configuration.mustache @@ -1,4 +1,15 @@ tempFolderPath = sys_get_temp_dir(); } /** - * @param string $key - * @param string $value + * Sets API key + * + * @param string $apiKeyIdentifier API key identifier (authentication scheme) + * @param string $key API key or token + * * @return Configuration */ - public function setApiKey($key, $value) { - $this->apiKeys[$key] = $value; - return $this; + public function setApiKey($apiKeyIdentifier, $key) + { + $this->apiKeys[$apiKeyIdentifier] = $key; + return $this; } /** - * @param $key + * Gets API key + * + * @param string $apiKeyIdentifier API key identifier (authentication scheme) + * + * @return string API key or token + */ + public function getApiKey($apiKeyIdentifier) + { + return isset($this->apiKeys[$apiKeyIdentifier]) ? $this->apiKeys[$apiKeyIdentifier] : null; + } + + /** + * Sets the prefix for API key (e.g. Bearer) + * + * @param string $apiKeyIdentifier API key identifier (authentication scheme) + * @param string $prefix API key prefix, e.g. Bearer + * + * @return Configuration + */ + public function setApiKeyPrefix($apiKeyIdentifier, $prefix) + { + $this->apiKeyPrefixes[$apiKeyIdentifier] = $prefix; + return $this; + } + + /** + * Gets API key prefix + * + * @param string $apiKeyIdentifier API key identifier (authentication scheme) + * * @return string */ - public function getApiKey($key) { - return isset($this->apiKeys[$key]) ? $this->apiKeys[$key] : null; + public function getApiKeyPrefix($apiKeyIdentifier) + { + return isset($this->apiKeyPrefixes[$apiKeyIdentifier]) ? $this->apiKeyPrefixes[$apiKeyIdentifier] : null; } /** - * @param string $key - * @param string $value + * Sets the username for HTTP basic authentication + * + * @param string $username Username for HTTP basic authentication + * * @return Configuration */ - public function setApiKeyPrefix($key, $value) { - $this->apiKeyPrefixes[$key] = $value; - return $this; - } - - /** - * @param $key - * @return string - */ - public function getApiKeyPrefix($key) { - return isset($this->apiKeyPrefixes[$key]) ? $this->apiKeyPrefixes[$key] : null; - } - - /** - * @param string $username - * @return Configuration - */ - public function setUsername($username) { + public function setUsername($username) + { $this->username = $username; return $this; } /** - * @return string + * Gets the username for HTTP basic authentication + * + * @return string Username for HTTP basic authentication */ - public function getUsername() { + public function getUsername() + { return $this->username; } /** - * @param string $password + * Sets the password for HTTP basic authentication + * + * @param string $password Password for HTTP basic authentication + * * @return Configuration */ - public function setPassword($password) { + public function setPassword($password) + { $this->password = $password; return $this; } /** - * @return string + * Gets the password for HTTP basic authentication + * + * @return string Password for HTTP basic authentication */ - public function getPassword() { + public function getPassword() + { return $this->password; } /** - * add default header + * Adds a default header * - * @param string $headerName header name (e.g. Token) + * @param string $headerName header name (e.g. Token) * @param string $headerValue header value (e.g. 1z8wp3) + * * @return ApiClient */ - public function addDefaultHeader($headerName, $headerValue) { + public function addDefaultHeader($headerName, $headerValue) + { if (!is_string($headerName)) { throw new \InvalidArgumentException('Header name must be a string.'); } @@ -146,46 +251,59 @@ class Configuration { } /** - * get the default header + * Gets the default header * - * @return array default header + * @return array An array of default header(s) */ - public function getDefaultHeaders() { + public function getDefaultHeaders() + { return $this->defaultHeaders; } /** - * delete a default header + * Deletes a default header + * * @param string $headerName the header to delete + * * @return Configuration */ - public function deleteDefaultHeader($headerName) { + public function deleteDefaultHeader($headerName) + { unset($this->defaultHeaders[$headerName]); } /** - * @param string $host + * Sets the host + * + * @param string $host Host + * * @return Configuration */ - public function setHost($host) { + public function setHost($host) + { $this->host = $host; return $this; } /** - * @return string + * Gets the host + * + * @return string Host */ - public function getHost() { + public function getHost() + { return $this->host; } /** - * set the user agent of the api client + * Sets the user agent of the api client * * @param string $userAgent the user agent of the api client + * * @return ApiClient */ - public function setUserAgent($userAgent) { + public function setUserAgent($userAgent) + { if (!is_string($userAgent)) { throw new \InvalidArgumentException('User-agent must be a string.'); } @@ -195,21 +313,24 @@ class Configuration { } /** - * get the user agent of the api client + * Gets the user agent of the api client * * @return string user agent */ - public function getUserAgent() { + public function getUserAgent() + { return $this->userAgent; } /** - * set the HTTP timeout value + * Sets the HTTP timeout value * * @param integer $seconds Number of seconds before timing out [set to 0 for no timeout] + * * @return ApiClient */ - public function setCurlTimeout($seconds) { + public function setCurlTimeout($seconds) + { if (!is_numeric($seconds) || $seconds < 0) { throw new \InvalidArgumentException('Timeout value must be numeric and a non-negative number.'); } @@ -219,85 +340,117 @@ class Configuration { } /** - * get the HTTP timeout value + * Gets the HTTP timeout value * * @return string HTTP timeout value */ - public function getCurlTimeout() { + public function getCurlTimeout() + { return $this->curlTimeout; } /** - * @param bool $debug + * Sets debug flag + * + * @param bool $debug Debug flag + * * @return Configuration */ - public function setDebug($debug) { + public function setDebug($debug) + { $this->debug = $debug; return $this; } /** + * Gets the debug flag + * * @return bool */ - public function getDebug() { + public function getDebug() + { return $this->debug; } /** - * @param string $debugFile + * Sets the debug file + * + * @param string $debugFile Debug file + * * @return Configuration */ - public function setDebugFile($debugFile) { + public function setDebugFile($debugFile) + { $this->debugFile = $debugFile; return $this; } /** + * Gets the debug file + * * @return string */ - public function getDebugFile() { + public function getDebugFile() + { return $this->debugFile; } /** - * @param string $tempFolderPath + * Sets the temp folder path + * + * @param string $tempFolderPath Temp folder path + * * @return Configuration */ - public function setTempFolderPath($tempFolderPath) { + public function setTempFolderPath($tempFolderPath) + { $this->tempFolderPath = $tempFolderPath; return $this; } /** - * @return string + * Gets the temp folder path + * + * @return string Temp folder path */ - public function getTempFolderPath() { + public function getTempFolderPath() + { return $this->tempFolderPath; } - /** + * Gets the default configuration instance + * * @return Configuration */ - public static function getDefaultConfiguration() { - if (self::$defaultConfiguration == null) { - self::$defaultConfiguration = new Configuration(); + public static function getDefaultConfiguration() + { + if (self::$_defaultConfiguration == null) { + self::$_defaultConfiguration = new Configuration(); } - return self::$defaultConfiguration; + return self::$_defaultConfiguration; } /** - * @param Configuration $config + * Sets the detault configuration instance + * + * @param Configuration $config An instance of the Configuration Object + * + * @return void */ - public static function setDefaultConfiguration(Configuration $config) { - self::$defaultConfiguration = $config; + public static function setDefaultConfiguration(Configuration $config) + { + self::$_defaultConfiguration = $config; } - /* - * return the report for debugging + /** + * Gets the essential information for debugging + * + * @return string The report for debugging */ - public static function toDebugReport() { + public static function toDebugReport() + { $report = "PHP SDK ({{invokerPackage}}) Debug Report:\n"; $report .= " OS: ".php_uname()."\n"; $report .= " PHP Version: ".phpversion()."\n"; diff --git a/modules/swagger-codegen/src/main/resources/php/model.mustache b/modules/swagger-codegen/src/main/resources/php/model.mustache index df4ddc0b4f06..861673982f22 100644 --- a/modules/swagger-codegen/src/main/resources/php/model.mustache +++ b/modules/swagger-codegen/src/main/resources/php/model.mustache @@ -1,4 +1,17 @@ '{{{datatype}}}'{{#hasMore}}, {{/hasMore}}{{/vars}} ); - /** @var string[] Array of attributes where the key is the local name, and the value is the original name */ + /** + * Array of attributes where the key is the local name, and the value is the original name + * @var string[] + */ static $attributeMap = array( {{#vars}}'{{name}}' => '{{baseName}}'{{#hasMore}}, {{/hasMore}}{{/vars}} ); - /** @var string[] Array of attributes to setter functions (for deserialization of responses) */ + /** + * Array of attributes to setter functions (for deserialization of responses) + * @var string[] + */ static $setters = array( {{#vars}}'{{name}}' => '{{setter}}'{{#hasMore}}, {{/hasMore}}{{/vars}} ); - /** @var string[] Array of attributes to getter functions (for serialization of requests) */ + /** + * Array of attributes to getter functions (for serialization of requests) + * @var string[] + */ static $getters = array( {{#vars}}'{{name}}' => '{{getter}}'{{#hasMore}}, {{/hasMore}}{{/vars}} ); {{#vars}} - /** @var {{datatype}} ${{name}} {{#description}}{{{description}}} {{/description}}*/ + /** + * ${{name}} {{#description}}{{{description}}}{{/description}} + * @var {{datatype}} + */ protected ${{name}}; {{/vars}} - public function __construct(array $data = null) { + + /** + * Constructor + * @param mixed[] $data Associated array of property value initalizing the model + */ + public function __construct(array $data = null) + { if ($data != null) { {{#vars}}$this->{{name}} = $data["{{name}}"];{{#hasMore}} {{/hasMore}}{{/vars}} @@ -65,19 +105,21 @@ class {{classname}} implements ArrayAccess { } {{#vars}} /** - * get {{name}} + * Gets {{name}} * @return {{datatype}} */ - public function {{getter}}() { + public function {{getter}}() + { return $this->{{name}}; } /** - * set {{name}} - * @param {{datatype}} ${{name}} + * Sets {{name}} + * @param {{datatype}} ${{name}} {{#description}}{{{description}}}{{/description}} * @return $this */ - public function {{setter}}(${{name}}) { + public function {{setter}}(${{name}}) + { {{#isEnum}}$allowed_values = array({{#allowableValues}}{{#values}}"{{{this}}}"{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}); if (!in_array(${{{name}}}, $allowed_values)) { throw new \InvalidArgumentException("Invalid value for '{{name}}', must be one of {{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}"); @@ -86,23 +128,53 @@ class {{classname}} implements ArrayAccess { return $this; } {{/vars}} - public function offsetExists($offset) { + /** + * Returns true if offset exists. False otherwise. + * @param integer $offset Offset + * @return boolean + */ + public function offsetExists($offset) + { return isset($this->$offset); } - public function offsetGet($offset) { + /** + * Gets offset. + * @param integer $offset Offset + * @return mixed + */ + public function offsetGet($offset) + { return $this->$offset; } - public function offsetSet($offset, $value) { + /** + * Sets value based on offset. + * @param integer $offset Offset + * @param mixed $value Value to be set + * @return void + */ + public function offsetSet($offset, $value) + { $this->$offset = $value; } - public function offsetUnset($offset) { + /** + * Unsets offset. + * @param integer $offset Offset + * @return void + */ + public function offsetUnset($offset) + { unset($this->$offset); } - public function __toString() { + /** + * Gets the string presentation of the object + * @return string + */ + public function __toString() + { if (defined('JSON_PRETTY_PRINT')) { return json_encode(get_object_vars($this), JSON_PRETTY_PRINT); } else { 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 3620252ea513..e9fef44a3ba1 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php @@ -1,4 +1,14 @@ getConfig()->setHost('http://petstore.swagger.io/v2'); @@ -45,17 +71,21 @@ class PetApi { } /** + * Get API client * @return \Swagger\Client\ApiClient get the API client */ - public function getApiClient() { + public function getApiClient() + { return $this->apiClient; } /** + * Set the API client * @param \Swagger\Client\ApiClient $apiClient set the API client * @return PetApi */ - public function setApiClient(ApiClient $apiClient) { + public function setApiClient(ApiClient $apiClient) + { $this->apiClient = $apiClient; return $this; } @@ -67,10 +97,12 @@ class PetApi { * Update an existing pet * * @param \Swagger\Client\Model\Pet $body Pet object that needs to be added to the store (required) + * * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function updatePet($body) { + public function updatePet($body) + { // parse inputs @@ -101,18 +133,20 @@ class PetApi { if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; + $httpBody = $formParams; // for HTTP post (form) } //TODO support oauth // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); + try + { + list($response, $httpHeader) = $this->apiClient->callApi( + $resourcePath, $method, + $queryParams, $httpBody, + $headerParams + ); } catch (ApiException $e) { switch ($e->getCode()) { } @@ -128,10 +162,12 @@ class PetApi { * Add a new pet to the store * * @param \Swagger\Client\Model\Pet $body Pet object that needs to be added to the store (required) + * * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function addPet($body) { + public function addPet($body) + { // parse inputs @@ -162,18 +198,20 @@ class PetApi { if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; + $httpBody = $formParams; // for HTTP post (form) } //TODO support oauth // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); + try + { + list($response, $httpHeader) = $this->apiClient->callApi( + $resourcePath, $method, + $queryParams, $httpBody, + $headerParams + ); } catch (ApiException $e) { switch ($e->getCode()) { } @@ -189,10 +227,12 @@ class PetApi { * Finds Pets by status * * @param string[] $status Status values that need to be considered for filter (required) + * * @return \Swagger\Client\Model\Pet[] * @throws \Swagger\Client\ApiException on non-2xx response */ - public function findPetsByStatus($status) { + public function findPetsByStatus($status) + { // parse inputs @@ -210,7 +250,7 @@ class PetApi { $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array()); // query params - if($status !== null) { + if ($status !== null) { $queryParams['status'] = $this->apiClient->getSerializer()->toQueryValue($status); } @@ -222,24 +262,26 @@ class PetApi { if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; + $httpBody = $formParams; // for HTTP post (form) } //TODO support oauth // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams, '\Swagger\Client\Model\Pet[]'); + try + { + list($response, $httpHeader) = $this->apiClient->callApi( + $resourcePath, $method, + $queryParams, $httpBody, + $headerParams, '\Swagger\Client\Model\Pet[]' + ); } catch (ApiException $e) { switch ($e->getCode()) { - case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Pet[]', $httpHeader); - $e->setResponseObject($data); - break; + case 200: + $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Pet[]', $httpHeader); + $e->setResponseObject($data); + break; } throw $e; @@ -249,7 +291,7 @@ class PetApi { return null; } - return $this->apiClient->getSerializer()->deserialize($response,'\Swagger\Client\Model\Pet[]'); + return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Pet[]'); } @@ -259,10 +301,12 @@ class PetApi { * Finds Pets by tags * * @param string[] $tags Tags to filter by (required) + * * @return \Swagger\Client\Model\Pet[] * @throws \Swagger\Client\ApiException on non-2xx response */ - public function findPetsByTags($tags) { + public function findPetsByTags($tags) + { // parse inputs @@ -280,7 +324,7 @@ class PetApi { $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array()); // query params - if($tags !== null) { + if ($tags !== null) { $queryParams['tags'] = $this->apiClient->getSerializer()->toQueryValue($tags); } @@ -292,24 +336,26 @@ class PetApi { if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; + $httpBody = $formParams; // for HTTP post (form) } //TODO support oauth // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams, '\Swagger\Client\Model\Pet[]'); + try + { + list($response, $httpHeader) = $this->apiClient->callApi( + $resourcePath, $method, + $queryParams, $httpBody, + $headerParams, '\Swagger\Client\Model\Pet[]' + ); } catch (ApiException $e) { switch ($e->getCode()) { - case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Pet[]', $httpHeader); - $e->setResponseObject($data); - break; + case 200: + $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Pet[]', $httpHeader); + $e->setResponseObject($data); + break; } throw $e; @@ -319,7 +365,7 @@ class PetApi { return null; } - return $this->apiClient->getSerializer()->deserialize($response,'\Swagger\Client\Model\Pet[]'); + return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Pet[]'); } @@ -329,10 +375,12 @@ class PetApi { * Find pet by ID * * @param int $pet_id ID of pet that needs to be fetched (required) + * * @return \Swagger\Client\Model\Pet * @throws \Swagger\Client\ApiException on non-2xx response */ - public function getPetById($pet_id) { + public function getPetById($pet_id) + { // verify the required parameter 'pet_id' is set if ($pet_id === null) { throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling getPetById'); @@ -355,10 +403,12 @@ class PetApi { // path params - if($pet_id !== null) { - $resourcePath = str_replace("{" . "petId" . "}", - $this->apiClient->getSerializer()->toPathValue($pet_id), - $resourcePath); + if ($pet_id !== null) { + $resourcePath = str_replace( + "{" . "petId" . "}", + $this->apiClient->getSerializer()->toPathValue($pet_id), + $resourcePath + ); } @@ -367,8 +417,7 @@ class PetApi { if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; + $httpBody = $formParams; // for HTTP post (form) } $apiKey = $this->apiClient->getApiKeyWithPrefix('api_key'); @@ -382,16 +431,19 @@ class PetApi { //TODO support oauth // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams, '\Swagger\Client\Model\Pet'); + try + { + list($response, $httpHeader) = $this->apiClient->callApi( + $resourcePath, $method, + $queryParams, $httpBody, + $headerParams, '\Swagger\Client\Model\Pet' + ); } catch (ApiException $e) { switch ($e->getCode()) { - case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Pet', $httpHeader); - $e->setResponseObject($data); - break; + case 200: + $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Pet', $httpHeader); + $e->setResponseObject($data); + break; } throw $e; @@ -401,7 +453,7 @@ class PetApi { return null; } - return $this->apiClient->getSerializer()->deserialize($response,'\Swagger\Client\Model\Pet'); + return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Pet'); } @@ -413,10 +465,12 @@ class PetApi { * @param string $pet_id ID of pet that needs to be updated (required) * @param string $name Updated name of the pet (required) * @param string $status Updated status of the pet (required) + * * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function updatePetWithForm($pet_id, $name, $status) { + public function updatePetWithForm($pet_id, $name, $status) + { // verify the required parameter 'pet_id' is set if ($pet_id === null) { throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling updatePetWithForm'); @@ -439,10 +493,12 @@ class PetApi { // path params - if($pet_id !== null) { - $resourcePath = str_replace("{" . "petId" . "}", - $this->apiClient->getSerializer()->toPathValue($pet_id), - $resourcePath); + if ($pet_id !== null) { + $resourcePath = str_replace( + "{" . "petId" . "}", + $this->apiClient->getSerializer()->toPathValue($pet_id), + $resourcePath + ); } // form params if ($name !== null) { @@ -457,18 +513,20 @@ class PetApi { if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; + $httpBody = $formParams; // for HTTP post (form) } //TODO support oauth // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); + try + { + list($response, $httpHeader) = $this->apiClient->callApi( + $resourcePath, $method, + $queryParams, $httpBody, + $headerParams + ); } catch (ApiException $e) { switch ($e->getCode()) { } @@ -485,10 +543,12 @@ class PetApi { * * @param string $api_key (required) * @param int $pet_id Pet id to delete (required) + * * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function deletePet($api_key, $pet_id) { + public function deletePet($api_key, $pet_id) + { // verify the required parameter 'pet_id' is set if ($pet_id === null) { throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling deletePet'); @@ -510,14 +570,16 @@ class PetApi { // header params - if($api_key !== null) { + if ($api_key !== null) { $headerParams['api_key'] = $this->apiClient->getSerializer()->toHeaderValue($api_key); } // path params - if($pet_id !== null) { - $resourcePath = str_replace("{" . "petId" . "}", - $this->apiClient->getSerializer()->toPathValue($pet_id), - $resourcePath); + if ($pet_id !== null) { + $resourcePath = str_replace( + "{" . "petId" . "}", + $this->apiClient->getSerializer()->toPathValue($pet_id), + $resourcePath + ); } @@ -526,18 +588,20 @@ class PetApi { if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; + $httpBody = $formParams; // for HTTP post (form) } //TODO support oauth // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); + try + { + list($response, $httpHeader) = $this->apiClient->callApi( + $resourcePath, $method, + $queryParams, $httpBody, + $headerParams + ); } catch (ApiException $e) { switch ($e->getCode()) { } @@ -555,10 +619,12 @@ class PetApi { * @param int $pet_id ID of pet to update (required) * @param string $additional_metadata Additional data to pass to server (required) * @param \SplFileObject $file file to upload (required) + * * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function uploadFile($pet_id, $additional_metadata, $file) { + public function uploadFile($pet_id, $additional_metadata, $file) + { // verify the required parameter 'pet_id' is set if ($pet_id === null) { throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling uploadFile'); @@ -581,10 +647,12 @@ class PetApi { // path params - if($pet_id !== null) { - $resourcePath = str_replace("{" . "petId" . "}", - $this->apiClient->getSerializer()->toPathValue($pet_id), - $resourcePath); + if ($pet_id !== null) { + $resourcePath = str_replace( + "{" . "petId" . "}", + $this->apiClient->getSerializer()->toPathValue($pet_id), + $resourcePath + ); } // form params if ($additional_metadata !== null) { @@ -599,18 +667,20 @@ class PetApi { if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; + $httpBody = $formParams; // for HTTP post (form) } //TODO support oauth // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); + try + { + list($response, $httpHeader) = $this->apiClient->callApi( + $resourcePath, $method, + $queryParams, $httpBody, + $headerParams + ); } catch (ApiException $e) { switch ($e->getCode()) { } 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 9947628fdf68..5ad1da9e887c 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php @@ -1,4 +1,14 @@ getConfig()->setHost('http://petstore.swagger.io/v2'); @@ -45,17 +71,21 @@ class StoreApi { } /** + * Get API client * @return \Swagger\Client\ApiClient get the API client */ - public function getApiClient() { + public function getApiClient() + { return $this->apiClient; } /** + * Set the API client * @param \Swagger\Client\ApiClient $apiClient set the API client * @return StoreApi */ - public function setApiClient(ApiClient $apiClient) { + public function setApiClient(ApiClient $apiClient) + { $this->apiClient = $apiClient; return $this; } @@ -66,10 +96,12 @@ class StoreApi { * * Returns pet inventories by status * + * * @return map[string,int] * @throws \Swagger\Client\ApiException on non-2xx response */ - public function getInventory() { + public function getInventory() + { // parse inputs @@ -96,8 +128,7 @@ class StoreApi { if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; + $httpBody = $formParams; // for HTTP post (form) } $apiKey = $this->apiClient->getApiKeyWithPrefix('api_key'); @@ -108,16 +139,19 @@ class StoreApi { // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams, 'map[string,int]'); + try + { + list($response, $httpHeader) = $this->apiClient->callApi( + $resourcePath, $method, + $queryParams, $httpBody, + $headerParams, 'map[string,int]' + ); } catch (ApiException $e) { switch ($e->getCode()) { - case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), 'map[string,int]', $httpHeader); - $e->setResponseObject($data); - break; + case 200: + $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), 'map[string,int]', $httpHeader); + $e->setResponseObject($data); + break; } throw $e; @@ -127,7 +161,7 @@ class StoreApi { return null; } - return $this->apiClient->getSerializer()->deserialize($response,'map[string,int]'); + return $this->apiClient->getSerializer()->deserialize($response, 'map[string,int]'); } @@ -137,10 +171,12 @@ class StoreApi { * Place an order for a pet * * @param \Swagger\Client\Model\Order $body order placed for purchasing the pet (required) + * * @return \Swagger\Client\Model\Order * @throws \Swagger\Client\ApiException on non-2xx response */ - public function placeOrder($body) { + public function placeOrder($body) + { // parse inputs @@ -171,21 +207,23 @@ class StoreApi { if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; + $httpBody = $formParams; // for HTTP post (form) } // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams, '\Swagger\Client\Model\Order'); + try + { + list($response, $httpHeader) = $this->apiClient->callApi( + $resourcePath, $method, + $queryParams, $httpBody, + $headerParams, '\Swagger\Client\Model\Order' + ); } catch (ApiException $e) { switch ($e->getCode()) { - case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Order', $httpHeader); - $e->setResponseObject($data); - break; + case 200: + $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Order', $httpHeader); + $e->setResponseObject($data); + break; } throw $e; @@ -195,7 +233,7 @@ class StoreApi { return null; } - return $this->apiClient->getSerializer()->deserialize($response,'\Swagger\Client\Model\Order'); + return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Order'); } @@ -205,10 +243,12 @@ class StoreApi { * Find purchase order by ID * * @param string $order_id ID of pet that needs to be fetched (required) + * * @return \Swagger\Client\Model\Order * @throws \Swagger\Client\ApiException on non-2xx response */ - public function getOrderById($order_id) { + public function getOrderById($order_id) + { // verify the required parameter 'order_id' is set if ($order_id === null) { throw new \InvalidArgumentException('Missing the required parameter $order_id when calling getOrderById'); @@ -231,10 +271,12 @@ class StoreApi { // path params - if($order_id !== null) { - $resourcePath = str_replace("{" . "orderId" . "}", - $this->apiClient->getSerializer()->toPathValue($order_id), - $resourcePath); + if ($order_id !== null) { + $resourcePath = str_replace( + "{" . "orderId" . "}", + $this->apiClient->getSerializer()->toPathValue($order_id), + $resourcePath + ); } @@ -243,21 +285,23 @@ class StoreApi { if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; + $httpBody = $formParams; // for HTTP post (form) } // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams, '\Swagger\Client\Model\Order'); + try + { + list($response, $httpHeader) = $this->apiClient->callApi( + $resourcePath, $method, + $queryParams, $httpBody, + $headerParams, '\Swagger\Client\Model\Order' + ); } catch (ApiException $e) { switch ($e->getCode()) { - case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Order', $httpHeader); - $e->setResponseObject($data); - break; + case 200: + $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\Order', $httpHeader); + $e->setResponseObject($data); + break; } throw $e; @@ -267,7 +311,7 @@ class StoreApi { return null; } - return $this->apiClient->getSerializer()->deserialize($response,'\Swagger\Client\Model\Order'); + return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Order'); } @@ -277,10 +321,12 @@ class StoreApi { * Delete purchase order by ID * * @param string $order_id ID of the order that needs to be deleted (required) + * * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function deleteOrder($order_id) { + public function deleteOrder($order_id) + { // verify the required parameter 'order_id' is set if ($order_id === null) { throw new \InvalidArgumentException('Missing the required parameter $order_id when calling deleteOrder'); @@ -303,10 +349,12 @@ class StoreApi { // path params - if($order_id !== null) { - $resourcePath = str_replace("{" . "orderId" . "}", - $this->apiClient->getSerializer()->toPathValue($order_id), - $resourcePath); + if ($order_id !== null) { + $resourcePath = str_replace( + "{" . "orderId" . "}", + $this->apiClient->getSerializer()->toPathValue($order_id), + $resourcePath + ); } @@ -315,15 +363,17 @@ class StoreApi { if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; + $httpBody = $formParams; // for HTTP post (form) } // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); + try + { + list($response, $httpHeader) = $this->apiClient->callApi( + $resourcePath, $method, + $queryParams, $httpBody, + $headerParams + ); } catch (ApiException $e) { switch ($e->getCode()) { } 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 d0b98f348e31..37f739c50eaf 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php @@ -1,4 +1,14 @@ getConfig()->setHost('http://petstore.swagger.io/v2'); @@ -45,17 +71,21 @@ class UserApi { } /** + * Get API client * @return \Swagger\Client\ApiClient get the API client */ - public function getApiClient() { + public function getApiClient() + { return $this->apiClient; } /** + * Set the API client * @param \Swagger\Client\ApiClient $apiClient set the API client * @return UserApi */ - public function setApiClient(ApiClient $apiClient) { + public function setApiClient(ApiClient $apiClient) + { $this->apiClient = $apiClient; return $this; } @@ -67,10 +97,12 @@ class UserApi { * Create user * * @param \Swagger\Client\Model\User $body Created user object (required) + * * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function createUser($body) { + public function createUser($body) + { // parse inputs @@ -101,15 +133,17 @@ class UserApi { if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; + $httpBody = $formParams; // for HTTP post (form) } // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); + try + { + list($response, $httpHeader) = $this->apiClient->callApi( + $resourcePath, $method, + $queryParams, $httpBody, + $headerParams + ); } catch (ApiException $e) { switch ($e->getCode()) { } @@ -125,10 +159,12 @@ class UserApi { * Creates list of users with given input array * * @param \Swagger\Client\Model\User[] $body List of user object (required) + * * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function createUsersWithArrayInput($body) { + public function createUsersWithArrayInput($body) + { // parse inputs @@ -159,15 +195,17 @@ class UserApi { if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; + $httpBody = $formParams; // for HTTP post (form) } // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); + try + { + list($response, $httpHeader) = $this->apiClient->callApi( + $resourcePath, $method, + $queryParams, $httpBody, + $headerParams + ); } catch (ApiException $e) { switch ($e->getCode()) { } @@ -183,10 +221,12 @@ class UserApi { * Creates list of users with given input array * * @param \Swagger\Client\Model\User[] $body List of user object (required) + * * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function createUsersWithListInput($body) { + public function createUsersWithListInput($body) + { // parse inputs @@ -217,15 +257,17 @@ class UserApi { if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; + $httpBody = $formParams; // for HTTP post (form) } // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); + try + { + list($response, $httpHeader) = $this->apiClient->callApi( + $resourcePath, $method, + $queryParams, $httpBody, + $headerParams + ); } catch (ApiException $e) { switch ($e->getCode()) { } @@ -242,10 +284,12 @@ class UserApi { * * @param string $username The user name for login (required) * @param string $password The password for login in clear text (required) + * * @return string * @throws \Swagger\Client\ApiException on non-2xx response */ - public function loginUser($username, $password) { + public function loginUser($username, $password) + { // parse inputs @@ -263,10 +307,10 @@ class UserApi { $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array()); // query params - if($username !== null) { + if ($username !== null) { $queryParams['username'] = $this->apiClient->getSerializer()->toQueryValue($username); }// query params - if($password !== null) { + if ($password !== null) { $queryParams['password'] = $this->apiClient->getSerializer()->toQueryValue($password); } @@ -278,21 +322,23 @@ class UserApi { if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; + $httpBody = $formParams; // for HTTP post (form) } // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams, 'string'); + try + { + list($response, $httpHeader) = $this->apiClient->callApi( + $resourcePath, $method, + $queryParams, $httpBody, + $headerParams, 'string' + ); } catch (ApiException $e) { switch ($e->getCode()) { - case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), 'string', $httpHeader); - $e->setResponseObject($data); - break; + case 200: + $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), 'string', $httpHeader); + $e->setResponseObject($data); + break; } throw $e; @@ -302,7 +348,7 @@ class UserApi { return null; } - return $this->apiClient->getSerializer()->deserialize($response,'string'); + return $this->apiClient->getSerializer()->deserialize($response, 'string'); } @@ -311,10 +357,12 @@ class UserApi { * * Logs out current logged in user session * + * * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function logoutUser() { + public function logoutUser() + { // parse inputs @@ -341,15 +389,17 @@ class UserApi { if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; + $httpBody = $formParams; // for HTTP post (form) } // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); + try + { + list($response, $httpHeader) = $this->apiClient->callApi( + $resourcePath, $method, + $queryParams, $httpBody, + $headerParams + ); } catch (ApiException $e) { switch ($e->getCode()) { } @@ -365,10 +415,12 @@ class UserApi { * Get user by user name * * @param string $username The name that needs to be fetched. Use user1 for testing. (required) + * * @return \Swagger\Client\Model\User * @throws \Swagger\Client\ApiException on non-2xx response */ - public function getUserByName($username) { + public function getUserByName($username) + { // verify the required parameter 'username' is set if ($username === null) { throw new \InvalidArgumentException('Missing the required parameter $username when calling getUserByName'); @@ -391,10 +443,12 @@ class UserApi { // path params - if($username !== null) { - $resourcePath = str_replace("{" . "username" . "}", - $this->apiClient->getSerializer()->toPathValue($username), - $resourcePath); + if ($username !== null) { + $resourcePath = str_replace( + "{" . "username" . "}", + $this->apiClient->getSerializer()->toPathValue($username), + $resourcePath + ); } @@ -403,21 +457,23 @@ class UserApi { if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; + $httpBody = $formParams; // for HTTP post (form) } // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams, '\Swagger\Client\Model\User'); + try + { + list($response, $httpHeader) = $this->apiClient->callApi( + $resourcePath, $method, + $queryParams, $httpBody, + $headerParams, '\Swagger\Client\Model\User' + ); } catch (ApiException $e) { switch ($e->getCode()) { - case 200: - $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\User', $httpHeader); - $e->setResponseObject($data); - break; + case 200: + $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '\Swagger\Client\Model\User', $httpHeader); + $e->setResponseObject($data); + break; } throw $e; @@ -427,7 +483,7 @@ class UserApi { return null; } - return $this->apiClient->getSerializer()->deserialize($response,'\Swagger\Client\Model\User'); + return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\User'); } @@ -438,10 +494,12 @@ class UserApi { * * @param string $username name that need to be deleted (required) * @param \Swagger\Client\Model\User $body Updated user object (required) + * * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function updateUser($username, $body) { + public function updateUser($username, $body) + { // verify the required parameter 'username' is set if ($username === null) { throw new \InvalidArgumentException('Missing the required parameter $username when calling updateUser'); @@ -464,10 +522,12 @@ class UserApi { // path params - if($username !== null) { - $resourcePath = str_replace("{" . "username" . "}", - $this->apiClient->getSerializer()->toPathValue($username), - $resourcePath); + if ($username !== null) { + $resourcePath = str_replace( + "{" . "username" . "}", + $this->apiClient->getSerializer()->toPathValue($username), + $resourcePath + ); } // body params @@ -480,15 +540,17 @@ class UserApi { if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; + $httpBody = $formParams; // for HTTP post (form) } // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); + try + { + list($response, $httpHeader) = $this->apiClient->callApi( + $resourcePath, $method, + $queryParams, $httpBody, + $headerParams + ); } catch (ApiException $e) { switch ($e->getCode()) { } @@ -504,10 +566,12 @@ class UserApi { * Delete user * * @param string $username The name that needs to be deleted (required) + * * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function deleteUser($username) { + public function deleteUser($username) + { // verify the required parameter 'username' is set if ($username === null) { throw new \InvalidArgumentException('Missing the required parameter $username when calling deleteUser'); @@ -530,10 +594,12 @@ class UserApi { // path params - if($username !== null) { - $resourcePath = str_replace("{" . "username" . "}", - $this->apiClient->getSerializer()->toPathValue($username), - $resourcePath); + if ($username !== null) { + $resourcePath = str_replace( + "{" . "username" . "}", + $this->apiClient->getSerializer()->toPathValue($username), + $resourcePath + ); } @@ -542,15 +608,17 @@ class UserApi { if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; + $httpBody = $formParams; // for HTTP post (form) } // make the API Call - try { - list($response, $httpHeader) = $this->apiClient->callApi($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); + try + { + list($response, $httpHeader) = $this->apiClient->callApi( + $resourcePath, $method, + $queryParams, $httpBody, + $headerParams + ); } catch (ApiException $e) { switch ($e->getCode()) { } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php b/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php index 1f466389cfdb..bf4f4e482bf6 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php @@ -1,4 +1,15 @@ config; } /** - * get the serializer + * Get the serializer * @return ObjectSerializer */ - public function getSerializer() { + public function getSerializer() + { return $this->serializer; } /** * Get API key (with prefix if set) - * @param string $apiKey name of apikey + * @param string $apiKeyIdentifier name of apikey * @return string API key with the prefix */ - public function getApiKeyWithPrefix($apiKeyIdentifier) { + public function getApiKeyWithPrefix($apiKeyIdentifier) + { $prefix = $this->config->getApiKeyPrefix($apiKeyIdentifier); $apiKey = $this->config->getApiKey($apiKeyIdentifier); @@ -82,20 +119,26 @@ class ApiClient { } /** + * Make the HTTP call (Sync) * @param string $resourcePath path to method endpoint - * @param string $method method to call - * @param array $queryParams parameters to be place in query URL - * @param array $postData parameters to be placed in POST body - * @param array $headerParams parameters to be place in request header + * @param string $method method to call + * @param array $queryParams parameters to be place in query URL + * @param array $postData parameters to be placed in POST body + * @param array $headerParams parameters to be place in request header + * @param string $responseType expected response type of the endpoint * @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(); - # construct the http header - $headerParams = array_merge((array)$this->config->getDefaultHeaders(), (array)$headerParams); + // construct the http header + $headerParams = array_merge( + (array)$this->config->getDefaultHeaders(), + (array)$headerParams + ); foreach ($headerParams as $key => $val) { $headers[] = "$key: $val"; @@ -104,8 +147,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 + } else if ((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)); } @@ -184,21 +226,25 @@ class ApiClient { $data = $http_body; } } else { - throw new ApiException("[".$response_info['http_code']."] Error connecting to the API ($url)", - $response_info['http_code'], $http_header, $http_body); + throw new ApiException( + "[".$response_info['http_code']."] Error connecting to the API ($url)", + $response_info['http_code'], $http_header, $http_body + ); } return array($data, $http_header); } - /* - * return the header 'Accept' based on an array of Accept provided + /** + * Return the header 'Accept' based on an array of Accept provided * * @param string[] $accept Array of header + * * @return string Accept (e.g. application/json) */ - public static function selectHeaderAccept($accept) { + public static function selectHeaderAccept($accept) + { if (count($accept) === 0 or (count($accept) === 1 and $accept[0] === '')) { - return NULL; + return null; } elseif (preg_grep("/application\/json/i", $accept)) { return 'application/json'; } else { @@ -206,13 +252,15 @@ class ApiClient { } } - /* - * return the content type based on an array of content-type provided + /** + * Return the content type based on an array of content-type provided + * + * @param string[] $content_type Array fo content-type * - * @param string[] content_type_array Array fo content-type * @return string Content-Type (e.g. application/json) */ - public static function selectHeaderContentType($content_type) { + public static function selectHeaderContentType($content_type) + { if (count($content_type) === 0 or (count($content_type) === 1 and $content_type[0] === '')) { return 'application/json'; } elseif (preg_grep("/application\/json/i", $content_type)) { diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/ApiException.php b/samples/client/petstore/php/SwaggerClient-php/lib/ApiException.php index b1342921a0a1..ce6c19e245f1 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/ApiException.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/ApiException.php @@ -1,4 +1,14 @@ responseHeaders = $responseHeaders; $this->responseBody = $responseBody; } /** - * Get the HTTP response header + * Gets the HTTP response header * * @return string HTTP response header */ - public function getResponseHeaders() { + public function getResponseHeaders() + { return $this->responseHeaders; } /** - * Get the HTTP response body + * Gets the HTTP response body * * @return string HTTP response body */ - public function getResponseBody() { + public function getResponseBody() + { return $this->responseBody; } /** - * sets the deseralized response object (during deserialization) - * @param mixed $obj + * Sets the deseralized response object (during deserialization) + * @param mixed $obj Deserialized response object + * @return void */ - public function setResponseObject($obj) { + public function setResponseObject($obj) + { $this->responseObject = $obj; } - - public function getResponseObject() { + + /** + * Gets the deseralized response object (during deserialization) + * + * @return mixed the deserialized response object + */ + public function getResponseObject() + { return $this->responseObject; } } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php b/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php index 664293f1a13c..002df7fc7133 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php @@ -1,4 +1,15 @@ tempFolderPath = sys_get_temp_dir(); } /** - * @param string $key - * @param string $value + * Sets API key + * + * @param string $apiKeyIdentifier API key identifier (authentication scheme) + * @param string $key API key or token + * * @return Configuration */ - public function setApiKey($key, $value) { - $this->apiKeys[$key] = $value; - return $this; + public function setApiKey($apiKeyIdentifier, $key) + { + $this->apiKeys[$apiKeyIdentifier] = $key; + return $this; } /** - * @param $key + * Gets API key + * + * @param string $apiKeyIdentifier API key identifier (authentication scheme) + * + * @return string API key or token + */ + public function getApiKey($apiKeyIdentifier) + { + return isset($this->apiKeys[$apiKeyIdentifier]) ? $this->apiKeys[$apiKeyIdentifier] : null; + } + + /** + * Sets the prefix for API key (e.g. Bearer) + * + * @param string $apiKeyIdentifier API key identifier (authentication scheme) + * @param string $prefix API key prefix, e.g. Bearer + * + * @return Configuration + */ + public function setApiKeyPrefix($apiKeyIdentifier, $prefix) + { + $this->apiKeyPrefixes[$apiKeyIdentifier] = $prefix; + return $this; + } + + /** + * Gets API key prefix + * + * @param string $apiKeyIdentifier API key identifier (authentication scheme) + * * @return string */ - public function getApiKey($key) { - return isset($this->apiKeys[$key]) ? $this->apiKeys[$key] : null; + public function getApiKeyPrefix($apiKeyIdentifier) + { + return isset($this->apiKeyPrefixes[$apiKeyIdentifier]) ? $this->apiKeyPrefixes[$apiKeyIdentifier] : null; } /** - * @param string $key - * @param string $value + * Sets the username for HTTP basic authentication + * + * @param string $username Username for HTTP basic authentication + * * @return Configuration */ - public function setApiKeyPrefix($key, $value) { - $this->apiKeyPrefixes[$key] = $value; - return $this; - } - - /** - * @param $key - * @return string - */ - public function getApiKeyPrefix($key) { - return isset($this->apiKeyPrefixes[$key]) ? $this->apiKeyPrefixes[$key] : null; - } - - /** - * @param string $username - * @return Configuration - */ - public function setUsername($username) { + public function setUsername($username) + { $this->username = $username; return $this; } /** - * @return string + * Gets the username for HTTP basic authentication + * + * @return string Username for HTTP basic authentication */ - public function getUsername() { + public function getUsername() + { return $this->username; } /** - * @param string $password + * Sets the password for HTTP basic authentication + * + * @param string $password Password for HTTP basic authentication + * * @return Configuration */ - public function setPassword($password) { + public function setPassword($password) + { $this->password = $password; return $this; } /** - * @return string + * Gets the password for HTTP basic authentication + * + * @return string Password for HTTP basic authentication */ - public function getPassword() { + public function getPassword() + { return $this->password; } /** - * add default header + * Adds a default header * - * @param string $headerName header name (e.g. Token) + * @param string $headerName header name (e.g. Token) * @param string $headerValue header value (e.g. 1z8wp3) + * * @return ApiClient */ - public function addDefaultHeader($headerName, $headerValue) { + public function addDefaultHeader($headerName, $headerValue) + { if (!is_string($headerName)) { throw new \InvalidArgumentException('Header name must be a string.'); } @@ -146,46 +251,59 @@ class Configuration { } /** - * get the default header + * Gets the default header * - * @return array default header + * @return array An array of default header(s) */ - public function getDefaultHeaders() { + public function getDefaultHeaders() + { return $this->defaultHeaders; } /** - * delete a default header + * Deletes a default header + * * @param string $headerName the header to delete + * * @return Configuration */ - public function deleteDefaultHeader($headerName) { + public function deleteDefaultHeader($headerName) + { unset($this->defaultHeaders[$headerName]); } /** - * @param string $host + * Sets the host + * + * @param string $host Host + * * @return Configuration */ - public function setHost($host) { + public function setHost($host) + { $this->host = $host; return $this; } /** - * @return string + * Gets the host + * + * @return string Host */ - public function getHost() { + public function getHost() + { return $this->host; } /** - * set the user agent of the api client + * Sets the user agent of the api client * * @param string $userAgent the user agent of the api client + * * @return ApiClient */ - public function setUserAgent($userAgent) { + public function setUserAgent($userAgent) + { if (!is_string($userAgent)) { throw new \InvalidArgumentException('User-agent must be a string.'); } @@ -195,21 +313,24 @@ class Configuration { } /** - * get the user agent of the api client + * Gets the user agent of the api client * * @return string user agent */ - public function getUserAgent() { + public function getUserAgent() + { return $this->userAgent; } /** - * set the HTTP timeout value + * Sets the HTTP timeout value * * @param integer $seconds Number of seconds before timing out [set to 0 for no timeout] + * * @return ApiClient */ - public function setCurlTimeout($seconds) { + public function setCurlTimeout($seconds) + { if (!is_numeric($seconds) || $seconds < 0) { throw new \InvalidArgumentException('Timeout value must be numeric and a non-negative number.'); } @@ -219,85 +340,117 @@ class Configuration { } /** - * get the HTTP timeout value + * Gets the HTTP timeout value * * @return string HTTP timeout value */ - public function getCurlTimeout() { + public function getCurlTimeout() + { return $this->curlTimeout; } /** - * @param bool $debug + * Sets debug flag + * + * @param bool $debug Debug flag + * * @return Configuration */ - public function setDebug($debug) { + public function setDebug($debug) + { $this->debug = $debug; return $this; } /** + * Gets the debug flag + * * @return bool */ - public function getDebug() { + public function getDebug() + { return $this->debug; } /** - * @param string $debugFile + * Sets the debug file + * + * @param string $debugFile Debug file + * * @return Configuration */ - public function setDebugFile($debugFile) { + public function setDebugFile($debugFile) + { $this->debugFile = $debugFile; return $this; } /** + * Gets the debug file + * * @return string */ - public function getDebugFile() { + public function getDebugFile() + { return $this->debugFile; } /** - * @param string $tempFolderPath + * Sets the temp folder path + * + * @param string $tempFolderPath Temp folder path + * * @return Configuration */ - public function setTempFolderPath($tempFolderPath) { + public function setTempFolderPath($tempFolderPath) + { $this->tempFolderPath = $tempFolderPath; return $this; } /** - * @return string + * Gets the temp folder path + * + * @return string Temp folder path */ - public function getTempFolderPath() { + public function getTempFolderPath() + { return $this->tempFolderPath; } - /** + * Gets the default configuration instance + * * @return Configuration */ - public static function getDefaultConfiguration() { - if (self::$defaultConfiguration == null) { - self::$defaultConfiguration = new Configuration(); + public static function getDefaultConfiguration() + { + if (self::$_defaultConfiguration == null) { + self::$_defaultConfiguration = new Configuration(); } - return self::$defaultConfiguration; + return self::$_defaultConfiguration; } /** - * @param Configuration $config + * Sets the detault configuration instance + * + * @param Configuration $config An instance of the Configuration Object + * + * @return void */ - public static function setDefaultConfiguration(Configuration $config) { - self::$defaultConfiguration = $config; + public static function setDefaultConfiguration(Configuration $config) + { + self::$_defaultConfiguration = $config; } - /* - * return the report for debugging + /** + * Gets the essential information for debugging + * + * @return string The report for debugging */ - public static function toDebugReport() { + public static function toDebugReport() + { $report = "PHP SDK (Swagger\Client) Debug Report:\n"; $report .= " OS: ".php_uname()."\n"; $report .= " PHP Version: ".phpversion()."\n"; diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php index 02b3d3cde0f6..444c3c1ed7e1 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php @@ -1,4 +1,15 @@ 'int', 'name' => 'string' ); - /** @var string[] Array of attributes where the key is the local name, and the value is the original name */ + /** + * Array of attributes where the key is the local name, and the value is the original name + * @var string[] + */ static $attributeMap = array( 'id' => 'id', 'name' => 'name' ); - /** @var string[] Array of attributes to setter functions (for deserialization of responses) */ + /** + * Array of attributes to setter functions (for deserialization of responses) + * @var string[] + */ static $setters = array( 'id' => 'setId', 'name' => 'setName' ); - /** @var string[] Array of attributes to getter functions (for serialization of requests) */ + /** + * Array of attributes to getter functions (for serialization of requests) + * @var string[] + */ static $getters = array( 'id' => 'getId', 'name' => 'getName' ); - /** @var int $id */ + /** + * $id + * @var int + */ protected $id; - /** @var string $name */ + /** + * $name + * @var string + */ protected $name; - public function __construct(array $data = null) { + + /** + * Constructor + * @param mixed[] $data Associated array of property value initalizing the model + */ + public function __construct(array $data = null) + { if ($data != null) { $this->id = $data["id"]; $this->name = $data["name"]; @@ -66,60 +109,94 @@ class Category implements ArrayAccess { } /** - * get id + * Gets id * @return int */ - public function getId() { + public function getId() + { return $this->id; } /** - * set id - * @param int $id + * Sets id + * @param int $id * @return $this */ - public function setId($id) { + public function setId($id) + { $this->id = $id; return $this; } /** - * get name + * Gets name * @return string */ - public function getName() { + public function getName() + { return $this->name; } /** - * set name - * @param string $name + * Sets name + * @param string $name * @return $this */ - public function setName($name) { + public function setName($name) + { $this->name = $name; return $this; } - public function offsetExists($offset) { + /** + * Returns true if offset exists. False otherwise. + * @param integer $offset Offset + * @return boolean + */ + public function offsetExists($offset) + { return isset($this->$offset); } - public function offsetGet($offset) { + /** + * Gets offset. + * @param integer $offset Offset + * @return mixed + */ + public function offsetGet($offset) + { return $this->$offset; } - public function offsetSet($offset, $value) { + /** + * Sets value based on offset. + * @param integer $offset Offset + * @param mixed $value Value to be set + * @return void + */ + public function offsetSet($offset, $value) + { $this->$offset = $value; } - public function offsetUnset($offset) { + /** + * Unsets offset. + * @param integer $offset Offset + * @return void + */ + public function offsetUnset($offset) + { unset($this->$offset); } - public function __toString() { + /** + * Gets the string presentation of the object + * @return string + */ + public function __toString() + { if (defined('JSON_PRETTY_PRINT')) { return json_encode(get_object_vars($this), JSON_PRETTY_PRINT); } else { diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php index 9b20b159ab9f..b803bd7325e7 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php @@ -1,4 +1,15 @@ 'int', 'pet_id' => 'int', @@ -37,7 +59,10 @@ class Order implements ArrayAccess { 'complete' => 'bool' ); - /** @var string[] Array of attributes where the key is the local name, and the value is the original name */ + /** + * Array of attributes where the key is the local name, and the value is the original name + * @var string[] + */ static $attributeMap = array( 'id' => 'id', 'pet_id' => 'petId', @@ -47,7 +72,10 @@ class Order implements ArrayAccess { 'complete' => 'complete' ); - /** @var string[] Array of attributes to setter functions (for deserialization of responses) */ + /** + * Array of attributes to setter functions (for deserialization of responses) + * @var string[] + */ static $setters = array( 'id' => 'setId', 'pet_id' => 'setPetId', @@ -57,7 +85,10 @@ class Order implements ArrayAccess { 'complete' => 'setComplete' ); - /** @var string[] Array of attributes to getter functions (for serialization of requests) */ + /** + * Array of attributes to getter functions (for serialization of requests) + * @var string[] + */ static $getters = array( 'id' => 'getId', 'pet_id' => 'getPetId', @@ -68,25 +99,49 @@ class Order implements ArrayAccess { ); - /** @var int $id */ + /** + * $id + * @var int + */ protected $id; - /** @var int $pet_id */ + /** + * $pet_id + * @var int + */ protected $pet_id; - /** @var int $quantity */ + /** + * $quantity + * @var int + */ protected $quantity; - /** @var \DateTime $ship_date */ + /** + * $ship_date + * @var \DateTime + */ protected $ship_date; - /** @var string $status Order Status */ + /** + * $status Order Status + * @var string + */ protected $status; - /** @var bool $complete */ + /** + * $complete + * @var bool + */ protected $complete; - public function __construct(array $data = null) { + + /** + * Constructor + * @param mixed[] $data Associated array of property value initalizing the model + */ + public function __construct(array $data = null) + { if ($data != null) { $this->id = $data["id"]; $this->pet_id = $data["pet_id"]; @@ -98,95 +153,105 @@ class Order implements ArrayAccess { } /** - * get id + * Gets id * @return int */ - public function getId() { + public function getId() + { return $this->id; } /** - * set id - * @param int $id + * Sets id + * @param int $id * @return $this */ - public function setId($id) { + public function setId($id) + { $this->id = $id; return $this; } /** - * get pet_id + * Gets pet_id * @return int */ - public function getPetId() { + public function getPetId() + { return $this->pet_id; } /** - * set pet_id - * @param int $pet_id + * Sets pet_id + * @param int $pet_id * @return $this */ - public function setPetId($pet_id) { + public function setPetId($pet_id) + { $this->pet_id = $pet_id; return $this; } /** - * get quantity + * Gets quantity * @return int */ - public function getQuantity() { + public function getQuantity() + { return $this->quantity; } /** - * set quantity - * @param int $quantity + * Sets quantity + * @param int $quantity * @return $this */ - public function setQuantity($quantity) { + public function setQuantity($quantity) + { $this->quantity = $quantity; return $this; } /** - * get ship_date + * Gets ship_date * @return \DateTime */ - public function getShipDate() { + public function getShipDate() + { return $this->ship_date; } /** - * set ship_date - * @param \DateTime $ship_date + * Sets ship_date + * @param \DateTime $ship_date * @return $this */ - public function setShipDate($ship_date) { + public function setShipDate($ship_date) + { $this->ship_date = $ship_date; return $this; } /** - * get status + * Gets status * @return string */ - public function getStatus() { + public function getStatus() + { return $this->status; } /** - * set status - * @param string $status + * Sets status + * @param string $status Order Status * @return $this */ - public function setStatus($status) { + public function setStatus($status) + { $allowed_values = array("placed", "approved", "delivered"); if (!in_array($status, $allowed_values)) { throw new \InvalidArgumentException("Invalid value for 'status', must be one of 'placed', 'approved', 'delivered'"); @@ -196,41 +261,73 @@ class Order implements ArrayAccess { } /** - * get complete + * Gets complete * @return bool */ - public function getComplete() { + public function getComplete() + { return $this->complete; } /** - * set complete - * @param bool $complete + * Sets complete + * @param bool $complete * @return $this */ - public function setComplete($complete) { + public function setComplete($complete) + { $this->complete = $complete; return $this; } - public function offsetExists($offset) { + /** + * Returns true if offset exists. False otherwise. + * @param integer $offset Offset + * @return boolean + */ + public function offsetExists($offset) + { return isset($this->$offset); } - public function offsetGet($offset) { + /** + * Gets offset. + * @param integer $offset Offset + * @return mixed + */ + public function offsetGet($offset) + { return $this->$offset; } - public function offsetSet($offset, $value) { + /** + * Sets value based on offset. + * @param integer $offset Offset + * @param mixed $value Value to be set + * @return void + */ + public function offsetSet($offset, $value) + { $this->$offset = $value; } - public function offsetUnset($offset) { + /** + * Unsets offset. + * @param integer $offset Offset + * @return void + */ + public function offsetUnset($offset) + { unset($this->$offset); } - public function __toString() { + /** + * Gets the string presentation of the object + * @return string + */ + public function __toString() + { if (defined('JSON_PRETTY_PRINT')) { return json_encode(get_object_vars($this), JSON_PRETTY_PRINT); } else { diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php index 03c5b173532f..6871ea9d9be5 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php @@ -1,4 +1,15 @@ 'int', 'category' => '\Swagger\Client\Model\Category', @@ -37,7 +59,10 @@ class Pet implements ArrayAccess { 'status' => 'string' ); - /** @var string[] Array of attributes where the key is the local name, and the value is the original name */ + /** + * Array of attributes where the key is the local name, and the value is the original name + * @var string[] + */ static $attributeMap = array( 'id' => 'id', 'category' => 'category', @@ -47,7 +72,10 @@ class Pet implements ArrayAccess { 'status' => 'status' ); - /** @var string[] Array of attributes to setter functions (for deserialization of responses) */ + /** + * Array of attributes to setter functions (for deserialization of responses) + * @var string[] + */ static $setters = array( 'id' => 'setId', 'category' => 'setCategory', @@ -57,7 +85,10 @@ class Pet implements ArrayAccess { 'status' => 'setStatus' ); - /** @var string[] Array of attributes to getter functions (for serialization of requests) */ + /** + * Array of attributes to getter functions (for serialization of requests) + * @var string[] + */ static $getters = array( 'id' => 'getId', 'category' => 'getCategory', @@ -68,25 +99,49 @@ class Pet implements ArrayAccess { ); - /** @var int $id */ + /** + * $id + * @var int + */ protected $id; - /** @var \Swagger\Client\Model\Category $category */ + /** + * $category + * @var \Swagger\Client\Model\Category + */ protected $category; - /** @var string $name */ + /** + * $name + * @var string + */ protected $name; - /** @var string[] $photo_urls */ + /** + * $photo_urls + * @var string[] + */ protected $photo_urls; - /** @var \Swagger\Client\Model\Tag[] $tags */ + /** + * $tags + * @var \Swagger\Client\Model\Tag[] + */ protected $tags; - /** @var string $status pet status in the store */ + /** + * $status pet status in the store + * @var string + */ protected $status; - public function __construct(array $data = null) { + + /** + * Constructor + * @param mixed[] $data Associated array of property value initalizing the model + */ + public function __construct(array $data = null) + { if ($data != null) { $this->id = $data["id"]; $this->category = $data["category"]; @@ -98,114 +153,126 @@ class Pet implements ArrayAccess { } /** - * get id + * Gets id * @return int */ - public function getId() { + public function getId() + { return $this->id; } /** - * set id - * @param int $id + * Sets id + * @param int $id * @return $this */ - public function setId($id) { + public function setId($id) + { $this->id = $id; return $this; } /** - * get category + * Gets category * @return \Swagger\Client\Model\Category */ - public function getCategory() { + public function getCategory() + { return $this->category; } /** - * set category - * @param \Swagger\Client\Model\Category $category + * Sets category + * @param \Swagger\Client\Model\Category $category * @return $this */ - public function setCategory($category) { + public function setCategory($category) + { $this->category = $category; return $this; } /** - * get name + * Gets name * @return string */ - public function getName() { + public function getName() + { return $this->name; } /** - * set name - * @param string $name + * Sets name + * @param string $name * @return $this */ - public function setName($name) { + public function setName($name) + { $this->name = $name; return $this; } /** - * get photo_urls + * Gets photo_urls * @return string[] */ - public function getPhotoUrls() { + public function getPhotoUrls() + { return $this->photo_urls; } /** - * set photo_urls - * @param string[] $photo_urls + * Sets photo_urls + * @param string[] $photo_urls * @return $this */ - public function setPhotoUrls($photo_urls) { + public function setPhotoUrls($photo_urls) + { $this->photo_urls = $photo_urls; return $this; } /** - * get tags + * Gets tags * @return \Swagger\Client\Model\Tag[] */ - public function getTags() { + public function getTags() + { return $this->tags; } /** - * set tags - * @param \Swagger\Client\Model\Tag[] $tags + * Sets tags + * @param \Swagger\Client\Model\Tag[] $tags * @return $this */ - public function setTags($tags) { + public function setTags($tags) + { $this->tags = $tags; return $this; } /** - * get status + * Gets status * @return string */ - public function getStatus() { + public function getStatus() + { return $this->status; } /** - * set status - * @param string $status + * Sets status + * @param string $status pet status in the store * @return $this */ - public function setStatus($status) { + public function setStatus($status) + { $allowed_values = array("available", "pending", "sold"); if (!in_array($status, $allowed_values)) { throw new \InvalidArgumentException("Invalid value for 'status', must be one of 'available', 'pending', 'sold'"); @@ -214,23 +281,53 @@ class Pet implements ArrayAccess { return $this; } - public function offsetExists($offset) { + /** + * Returns true if offset exists. False otherwise. + * @param integer $offset Offset + * @return boolean + */ + public function offsetExists($offset) + { return isset($this->$offset); } - public function offsetGet($offset) { + /** + * Gets offset. + * @param integer $offset Offset + * @return mixed + */ + public function offsetGet($offset) + { return $this->$offset; } - public function offsetSet($offset, $value) { + /** + * Sets value based on offset. + * @param integer $offset Offset + * @param mixed $value Value to be set + * @return void + */ + public function offsetSet($offset, $value) + { $this->$offset = $value; } - public function offsetUnset($offset) { + /** + * Unsets offset. + * @param integer $offset Offset + * @return void + */ + public function offsetUnset($offset) + { unset($this->$offset); } - public function __toString() { + /** + * Gets the string presentation of the object + * @return string + */ + public function __toString() + { if (defined('JSON_PRETTY_PRINT')) { return json_encode(get_object_vars($this), JSON_PRETTY_PRINT); } else { diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php index 279618ac3bea..bcecb32fa7e2 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php @@ -1,4 +1,15 @@ 'int', 'name' => 'string' ); - /** @var string[] Array of attributes where the key is the local name, and the value is the original name */ + /** + * Array of attributes where the key is the local name, and the value is the original name + * @var string[] + */ static $attributeMap = array( 'id' => 'id', 'name' => 'name' ); - /** @var string[] Array of attributes to setter functions (for deserialization of responses) */ + /** + * Array of attributes to setter functions (for deserialization of responses) + * @var string[] + */ static $setters = array( 'id' => 'setId', 'name' => 'setName' ); - /** @var string[] Array of attributes to getter functions (for serialization of requests) */ + /** + * Array of attributes to getter functions (for serialization of requests) + * @var string[] + */ static $getters = array( 'id' => 'getId', 'name' => 'getName' ); - /** @var int $id */ + /** + * $id + * @var int + */ protected $id; - /** @var string $name */ + /** + * $name + * @var string + */ protected $name; - public function __construct(array $data = null) { + + /** + * Constructor + * @param mixed[] $data Associated array of property value initalizing the model + */ + public function __construct(array $data = null) + { if ($data != null) { $this->id = $data["id"]; $this->name = $data["name"]; @@ -66,60 +109,94 @@ class Tag implements ArrayAccess { } /** - * get id + * Gets id * @return int */ - public function getId() { + public function getId() + { return $this->id; } /** - * set id - * @param int $id + * Sets id + * @param int $id * @return $this */ - public function setId($id) { + public function setId($id) + { $this->id = $id; return $this; } /** - * get name + * Gets name * @return string */ - public function getName() { + public function getName() + { return $this->name; } /** - * set name - * @param string $name + * Sets name + * @param string $name * @return $this */ - public function setName($name) { + public function setName($name) + { $this->name = $name; return $this; } - public function offsetExists($offset) { + /** + * Returns true if offset exists. False otherwise. + * @param integer $offset Offset + * @return boolean + */ + public function offsetExists($offset) + { return isset($this->$offset); } - public function offsetGet($offset) { + /** + * Gets offset. + * @param integer $offset Offset + * @return mixed + */ + public function offsetGet($offset) + { return $this->$offset; } - public function offsetSet($offset, $value) { + /** + * Sets value based on offset. + * @param integer $offset Offset + * @param mixed $value Value to be set + * @return void + */ + public function offsetSet($offset, $value) + { $this->$offset = $value; } - public function offsetUnset($offset) { + /** + * Unsets offset. + * @param integer $offset Offset + * @return void + */ + public function offsetUnset($offset) + { unset($this->$offset); } - public function __toString() { + /** + * Gets the string presentation of the object + * @return string + */ + public function __toString() + { if (defined('JSON_PRETTY_PRINT')) { return json_encode(get_object_vars($this), JSON_PRETTY_PRINT); } else { diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php index 7dd45220cf93..1650635d8cec 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php @@ -1,4 +1,15 @@ 'int', 'username' => 'string', @@ -39,7 +61,10 @@ class User implements ArrayAccess { 'user_status' => 'int' ); - /** @var string[] Array of attributes where the key is the local name, and the value is the original name */ + /** + * Array of attributes where the key is the local name, and the value is the original name + * @var string[] + */ static $attributeMap = array( 'id' => 'id', 'username' => 'username', @@ -51,7 +76,10 @@ class User implements ArrayAccess { 'user_status' => 'userStatus' ); - /** @var string[] Array of attributes to setter functions (for deserialization of responses) */ + /** + * Array of attributes to setter functions (for deserialization of responses) + * @var string[] + */ static $setters = array( 'id' => 'setId', 'username' => 'setUsername', @@ -63,7 +91,10 @@ class User implements ArrayAccess { 'user_status' => 'setUserStatus' ); - /** @var string[] Array of attributes to getter functions (for serialization of requests) */ + /** + * Array of attributes to getter functions (for serialization of requests) + * @var string[] + */ static $getters = array( 'id' => 'getId', 'username' => 'getUsername', @@ -76,31 +107,61 @@ class User implements ArrayAccess { ); - /** @var int $id */ + /** + * $id + * @var int + */ protected $id; - /** @var string $username */ + /** + * $username + * @var string + */ protected $username; - /** @var string $first_name */ + /** + * $first_name + * @var string + */ protected $first_name; - /** @var string $last_name */ + /** + * $last_name + * @var string + */ protected $last_name; - /** @var string $email */ + /** + * $email + * @var string + */ protected $email; - /** @var string $password */ + /** + * $password + * @var string + */ protected $password; - /** @var string $phone */ + /** + * $phone + * @var string + */ protected $phone; - /** @var int $user_status User Status */ + /** + * $user_status User Status + * @var int + */ protected $user_status; - public function __construct(array $data = null) { + + /** + * Constructor + * @param mixed[] $data Associated array of property value initalizing the model + */ + public function __construct(array $data = null) + { if ($data != null) { $this->id = $data["id"]; $this->username = $data["username"]; @@ -114,174 +175,220 @@ class User implements ArrayAccess { } /** - * get id + * Gets id * @return int */ - public function getId() { + public function getId() + { return $this->id; } /** - * set id - * @param int $id + * Sets id + * @param int $id * @return $this */ - public function setId($id) { + public function setId($id) + { $this->id = $id; return $this; } /** - * get username + * Gets username * @return string */ - public function getUsername() { + public function getUsername() + { return $this->username; } /** - * set username - * @param string $username + * Sets username + * @param string $username * @return $this */ - public function setUsername($username) { + public function setUsername($username) + { $this->username = $username; return $this; } /** - * get first_name + * Gets first_name * @return string */ - public function getFirstName() { + public function getFirstName() + { return $this->first_name; } /** - * set first_name - * @param string $first_name + * Sets first_name + * @param string $first_name * @return $this */ - public function setFirstName($first_name) { + public function setFirstName($first_name) + { $this->first_name = $first_name; return $this; } /** - * get last_name + * Gets last_name * @return string */ - public function getLastName() { + public function getLastName() + { return $this->last_name; } /** - * set last_name - * @param string $last_name + * Sets last_name + * @param string $last_name * @return $this */ - public function setLastName($last_name) { + public function setLastName($last_name) + { $this->last_name = $last_name; return $this; } /** - * get email + * Gets email * @return string */ - public function getEmail() { + public function getEmail() + { return $this->email; } /** - * set email - * @param string $email + * Sets email + * @param string $email * @return $this */ - public function setEmail($email) { + public function setEmail($email) + { $this->email = $email; return $this; } /** - * get password + * Gets password * @return string */ - public function getPassword() { + public function getPassword() + { return $this->password; } /** - * set password - * @param string $password + * Sets password + * @param string $password * @return $this */ - public function setPassword($password) { + public function setPassword($password) + { $this->password = $password; return $this; } /** - * get phone + * Gets phone * @return string */ - public function getPhone() { + public function getPhone() + { return $this->phone; } /** - * set phone - * @param string $phone + * Sets phone + * @param string $phone * @return $this */ - public function setPhone($phone) { + public function setPhone($phone) + { $this->phone = $phone; return $this; } /** - * get user_status + * Gets user_status * @return int */ - public function getUserStatus() { + public function getUserStatus() + { return $this->user_status; } /** - * set user_status - * @param int $user_status + * Sets user_status + * @param int $user_status User Status * @return $this */ - public function setUserStatus($user_status) { + public function setUserStatus($user_status) + { $this->user_status = $user_status; return $this; } - public function offsetExists($offset) { + /** + * Returns true if offset exists. False otherwise. + * @param integer $offset Offset + * @return boolean + */ + public function offsetExists($offset) + { return isset($this->$offset); } - public function offsetGet($offset) { + /** + * Gets offset. + * @param integer $offset Offset + * @return mixed + */ + public function offsetGet($offset) + { return $this->$offset; } - public function offsetSet($offset, $value) { + /** + * Sets value based on offset. + * @param integer $offset Offset + * @param mixed $value Value to be set + * @return void + */ + public function offsetSet($offset, $value) + { $this->$offset = $value; } - public function offsetUnset($offset) { + /** + * Unsets offset. + * @param integer $offset Offset + * @return void + */ + public function offsetUnset($offset) + { unset($this->$offset); } - public function __toString() { + /** + * Gets the string presentation of the object + * @return string + */ + public function __toString() + { if (defined('JSON_PRETTY_PRINT')) { return json_encode(get_object_vars($this), JSON_PRETTY_PRINT); } else { diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php b/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php index 3f78ea55bb93..535c623118ac 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php @@ -1,14 +1,59 @@ toString($value)); } @@ -49,10 +97,13 @@ class ObjectSerializer { * the query, by imploding comma-separated if it's an object. * If it's a string, pass through unchanged. It will be url-encoded * later. + * * @param object $object an object to be serialized to a string + * * @return string the serialized object */ - public function toQueryValue($object) { + public function toQueryValue($object) + { if (is_array($object)) { return implode(',', $object); } else { @@ -64,10 +115,13 @@ class ObjectSerializer { * Take value and turn it into a string suitable for inclusion in * the header. If it's a string, pass through unchanged * If it's a datetime object, format it in ISO8601 + * * @param string $value a string which will be part of the header + * * @return string the header string */ - public function toHeaderValue($value) { + public function toHeaderValue($value) + { return $this->toString($value); } @@ -75,10 +129,13 @@ class ObjectSerializer { * Take value and turn it into a string suitable for inclusion in * the http body (form parameter). If it's a string, pass through unchanged * If it's a datetime object, format it in ISO8601 + * * @param string $value the value of the form parameter + * * @return string the form string */ - public function toFormValue($value) { + public function toFormValue($value) + { if ($value instanceof SplFileObject) { return $value->getRealPath(); } else { @@ -90,10 +147,13 @@ class ObjectSerializer { * Take value and turn it into a string suitable for inclusion in * the parameter. If it's a string, pass through unchanged * If it's a datetime object, format it in ISO8601 + * * @param string $value the value of the parameter + * * @return string the header string */ - public function toString($value) { + public function toString($value) + { if ($value instanceof \DateTime) { // datetime in ISO8601 format return $value->format(\DateTime::ISO8601); } else { @@ -104,37 +164,40 @@ class ObjectSerializer { /** * Deserialize a JSON string into an object * - * @param mixed $data object or primitive to be deserialized - * @param string $class class name is passed as a string + * @param mixed $data object or primitive to be deserialized + * @param string $class class name is passed as a string + * @param string $httpHeader HTTP headers + * * @return object an instance of $class */ - public function deserialize($data, $class, $httpHeader=null) { + public function deserialize($data, $class, $httpHeader=null) + { if (null === $data) { $deserialized = null; - } elseif (substr($class, 0, 4) == 'map[') { # for associative array e.g. map[string,int] + } elseif (substr($class, 0, 4) === 'map[') { // for associative array e.g. map[string,int] $inner = substr($class, 4, -1); $deserialized = array(); - if(strrpos($inner, ",") !== false) { + if (strrpos($inner, ",") !== false) { $subClass_array = explode(',', $inner, 2); $subClass = $subClass_array[1]; foreach ($data as $key => $value) { $deserialized[$key] = $this->deserialize($value, $subClass); } } - } elseif (strcasecmp(substr($class, -2),'[]') == 0) { + } elseif (strcasecmp(substr($class, -2), '[]') == 0) { $subClass = substr($class, 0, -2); $values = array(); foreach ($data as $key => $value) { $values[] = $this->deserialize($value, $subClass); } $deserialized = $values; - } elseif ($class == 'DateTime') { + } elseif ($class === 'DateTime') { $deserialized = new \DateTime($data); } elseif (in_array($class, array('string', 'int', 'float', 'double', 'bool', 'object'))) { settype($data, $class); $deserialized = $data; } elseif ($class === '\SplFileObject') { - # determine file name + // determine file name if (preg_match('/Content-Disposition: inline; filename=[\'"]?([^\'"\s]+)[\'"]?$/i', $httpHeader, $match)) { $filename = Configuration::getDefaultConfiguration()->getTempFolderPath().$match[1]; } else { @@ -142,7 +205,7 @@ class ObjectSerializer { } $deserialized = new \SplFileObject($filename, "w"); $byte_written = $deserialized->fwrite($data); - error_log("[INFO] Written $byte_written byte to $filename. Please move the file to a proper folder or delete the temp file after processing.\n" , 3, Configuration::getDefaultConfiguration()->getDebugFile()); + error_log("[INFO] Written $byte_written byte to $filename. Please move the file to a proper folder or delete the temp file after processing.\n", 3, Configuration::getDefaultConfiguration()->getDebugFile()); } else { $instance = new $class(); @@ -150,7 +213,7 @@ class ObjectSerializer { $propertySetter = $instance::$setters[$property]; if (!isset($propertySetter) || !isset($data->{$instance::$attributeMap[$property]})) { - continue; + continue; } $propertyValue = $data->{$instance::$attributeMap[$property]}; diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/PetApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/PetApi.php deleted file mode 100644 index 4d1cba21c3e8..000000000000 --- a/samples/client/petstore/php/SwaggerClient-php/lib/PetApi.php +++ /dev/null @@ -1,543 +0,0 @@ -apiClient = Configuration::$apiClient; - } - else - $this->apiClient = Configuration::$apiClient; // use the default one - } else { - $this->apiClient = $apiClient; // use the one provided by the user - } - } - - private $apiClient; // instance of the ApiClient - - /** - * get the API client - */ - public function getApiClient() { - return $this->apiClient; - } - - /** - * set the API client - */ - public function setApiClient($apiClient) { - $this->apiClient = $apiClient; - } - - - /** - * updatePet - * - * Update an existing pet - * - * @param Pet $body Pet object that needs to be added to the store (required) - * @return void - */ - public function updatePet($body) { - - - // parse inputs - $resourcePath = "/pet"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "PUT"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array('application/json','application/xml')); - - - - - - // body params - $_tempBody = null; - if (isset($body)) { - $_tempBody = $body; - } - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - // authentication setting, if any - $authSettings = array('petstore_auth'); - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams, $authSettings); - - - } - - /** - * addPet - * - * Add a new pet to the store - * - * @param Pet $body Pet object that needs to be added to the store (required) - * @return void - */ - public function addPet($body) { - - - // parse inputs - $resourcePath = "/pet"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array('application/json','application/xml')); - - - - - - // body params - $_tempBody = null; - if (isset($body)) { - $_tempBody = $body; - } - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - // authentication setting, if any - $authSettings = array('petstore_auth'); - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams, $authSettings); - - - } - - /** - * findPetsByStatus - * - * Finds Pets by status - * - * @param array[string] $status Status values that need to be considered for filter (required) - * @return array[Pet] - */ - public function findPetsByStatus($status) { - - - // parse inputs - $resourcePath = "/pet/findByStatus"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array()); - - // query params - if($status !== null) { - $queryParams['status'] = $this->apiClient->toQueryValue($status); - } - - - - - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - // authentication setting, if any - $authSettings = array('petstore_auth'); - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams, $authSettings); - - if(! $response) { - return null; - } - - $responseObject = $this->apiClient->deserialize($response,'array[Pet]'); - return $responseObject; - } - - /** - * findPetsByTags - * - * Finds Pets by tags - * - * @param array[string] $tags Tags to filter by (required) - * @return array[Pet] - */ - public function findPetsByTags($tags) { - - - // parse inputs - $resourcePath = "/pet/findByTags"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array()); - - // query params - if($tags !== null) { - $queryParams['tags'] = $this->apiClient->toQueryValue($tags); - } - - - - - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - // authentication setting, if any - $authSettings = array('petstore_auth'); - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams, $authSettings); - - if(! $response) { - return null; - } - - $responseObject = $this->apiClient->deserialize($response,'array[Pet]'); - return $responseObject; - } - - /** - * getPetById - * - * Find pet by ID - * - * @param int $pet_id ID of pet that needs to be fetched (required) - * @return Pet - */ - public function getPetById($pet_id) { - - // verify the required parameter 'pet_id' is set - if ($pet_id === null) { - throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling getPetById'); - } - - - // parse inputs - $resourcePath = "/pet/{petId}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array()); - - - - // path params - if($pet_id !== null) { - $resourcePath = str_replace("{" . "petId" . "}", - $this->apiClient->toPathValue($pet_id), $resourcePath); - } - - - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - // authentication setting, if any - $authSettings = array('api_key', 'petstore_auth'); - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams, $authSettings); - - if(! $response) { - return null; - } - - $responseObject = $this->apiClient->deserialize($response,'Pet'); - return $responseObject; - } - - /** - * updatePetWithForm - * - * 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 (required) - * @param string $status Updated status of the pet (required) - * @return void - */ - public function updatePetWithForm($pet_id, $name, $status) { - - // verify the required parameter 'pet_id' is set - if ($pet_id === null) { - throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling updatePetWithForm'); - } - - - // parse inputs - $resourcePath = "/pet/{petId}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array('application/x-www-form-urlencoded')); - - - - // path params - if($pet_id !== null) { - $resourcePath = str_replace("{" . "petId" . "}", - $this->apiClient->toPathValue($pet_id), $resourcePath); - } - // form params - if ($name !== null) { - $formParams['name'] = $this->apiClient->toFormValue($name); - }// form params - if ($status !== null) { - $formParams['status'] = $this->apiClient->toFormValue($status); - } - - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - // authentication setting, if any - $authSettings = array('petstore_auth'); - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams, $authSettings); - - - } - - /** - * deletePet - * - * Deletes a pet - * - * @param string $api_key (required) - * @param int $pet_id Pet id to delete (required) - * @return void - */ - public function deletePet($api_key, $pet_id) { - - // verify the required parameter 'pet_id' is set - if ($pet_id === null) { - throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling deletePet'); - } - - - // parse inputs - $resourcePath = "/pet/{petId}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "DELETE"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array()); - - - // header params - if($api_key !== null) { - $headerParams['api_key'] = $this->apiClient->toHeaderValue($api_key); - } - // path params - if($pet_id !== null) { - $resourcePath = str_replace("{" . "petId" . "}", - $this->apiClient->toPathValue($pet_id), $resourcePath); - } - - - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - // authentication setting, if any - $authSettings = array('petstore_auth'); - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams, $authSettings); - - - } - - /** - * uploadFile - * - * uploads an image - * - * @param int $pet_id ID of pet to update (required) - * @param string $additional_metadata Additional data to pass to server (required) - * @param string $file file to upload (required) - * @return void - */ - public function uploadFile($pet_id, $additional_metadata, $file) { - - // verify the required parameter 'pet_id' is set - if ($pet_id === null) { - throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling uploadFile'); - } - - - // parse inputs - $resourcePath = "/pet/{petId}/uploadImage"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array('multipart/form-data')); - - - - // path params - if($pet_id !== null) { - $resourcePath = str_replace("{" . "petId" . "}", - $this->apiClient->toPathValue($pet_id), $resourcePath); - } - // form params - if ($additional_metadata !== null) { - $formParams['additionalMetadata'] = $this->apiClient->toFormValue($additional_metadata); - }// form params - if ($file !== null) { - $formParams['file'] = '@'.$this->apiClient->toFormValue($file); - } - - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - // authentication setting, if any - $authSettings = array('petstore_auth'); - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams, $authSettings); - - - } - - -} diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/StoreApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/StoreApi.php deleted file mode 100644 index 87937a60283f..000000000000 --- a/samples/client/petstore/php/SwaggerClient-php/lib/StoreApi.php +++ /dev/null @@ -1,294 +0,0 @@ -apiClient = Configuration::$apiClient; - } - else - $this->apiClient = Configuration::$apiClient; // use the default one - } else { - $this->apiClient = $apiClient; // use the one provided by the user - } - } - - private $apiClient; // instance of the ApiClient - - /** - * get the API client - */ - public function getApiClient() { - return $this->apiClient; - } - - /** - * set the API client - */ - public function setApiClient($apiClient) { - $this->apiClient = $apiClient; - } - - - /** - * getInventory - * - * Returns pet inventories by status - * - * @return map[string,int] - */ - public function getInventory() { - - - // parse inputs - $resourcePath = "/store/inventory"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array()); - - - - - - - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - // authentication setting, if any - $authSettings = array('api_key'); - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams, $authSettings); - - if(! $response) { - return null; - } - - $responseObject = $this->apiClient->deserialize($response,'map[string,int]'); - return $responseObject; - } - - /** - * placeOrder - * - * Place an order for a pet - * - * @param Order $body order placed for purchasing the pet (required) - * @return Order - */ - public function placeOrder($body) { - - - // parse inputs - $resourcePath = "/store/order"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array()); - - - - - - // body params - $_tempBody = null; - if (isset($body)) { - $_tempBody = $body; - } - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - // authentication setting, if any - $authSettings = array(); - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams, $authSettings); - - if(! $response) { - return null; - } - - $responseObject = $this->apiClient->deserialize($response,'Order'); - return $responseObject; - } - - /** - * getOrderById - * - * Find purchase order by ID - * - * @param string $order_id ID of pet that needs to be fetched (required) - * @return Order - */ - public function getOrderById($order_id) { - - // verify the required parameter 'order_id' is set - if ($order_id === null) { - throw new \InvalidArgumentException('Missing the required parameter $order_id when calling getOrderById'); - } - - - // parse inputs - $resourcePath = "/store/order/{orderId}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array()); - - - - // path params - if($order_id !== null) { - $resourcePath = str_replace("{" . "orderId" . "}", - $this->apiClient->toPathValue($order_id), $resourcePath); - } - - - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - // authentication setting, if any - $authSettings = array(); - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams, $authSettings); - - if(! $response) { - return null; - } - - $responseObject = $this->apiClient->deserialize($response,'Order'); - return $responseObject; - } - - /** - * deleteOrder - * - * Delete purchase order by ID - * - * @param string $order_id ID of the order that needs to be deleted (required) - * @return void - */ - public function deleteOrder($order_id) { - - // verify the required parameter 'order_id' is set - if ($order_id === null) { - throw new \InvalidArgumentException('Missing the required parameter $order_id when calling deleteOrder'); - } - - - // parse inputs - $resourcePath = "/store/order/{orderId}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "DELETE"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array()); - - - - // path params - if($order_id !== null) { - $resourcePath = str_replace("{" . "orderId" . "}", - $this->apiClient->toPathValue($order_id), $resourcePath); - } - - - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - // authentication setting, if any - $authSettings = array(); - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams, $authSettings); - - - } - - -} diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/UserApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/UserApi.php deleted file mode 100644 index 2e16022f25a5..000000000000 --- a/samples/client/petstore/php/SwaggerClient-php/lib/UserApi.php +++ /dev/null @@ -1,518 +0,0 @@ -apiClient = Configuration::$apiClient; - } - else - $this->apiClient = Configuration::$apiClient; // use the default one - } else { - $this->apiClient = $apiClient; // use the one provided by the user - } - } - - private $apiClient; // instance of the ApiClient - - /** - * get the API client - */ - public function getApiClient() { - return $this->apiClient; - } - - /** - * set the API client - */ - public function setApiClient($apiClient) { - $this->apiClient = $apiClient; - } - - - /** - * createUser - * - * Create user - * - * @param User $body Created user object (required) - * @return void - */ - public function createUser($body) { - - - // parse inputs - $resourcePath = "/user"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array()); - - - - - - // body params - $_tempBody = null; - if (isset($body)) { - $_tempBody = $body; - } - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - // authentication setting, if any - $authSettings = array(); - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams, $authSettings); - - - } - - /** - * createUsersWithArrayInput - * - * Creates list of users with given input array - * - * @param array[User] $body List of user object (required) - * @return void - */ - public function createUsersWithArrayInput($body) { - - - // parse inputs - $resourcePath = "/user/createWithArray"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array()); - - - - - - // body params - $_tempBody = null; - if (isset($body)) { - $_tempBody = $body; - } - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - // authentication setting, if any - $authSettings = array(); - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams, $authSettings); - - - } - - /** - * createUsersWithListInput - * - * Creates list of users with given input array - * - * @param array[User] $body List of user object (required) - * @return void - */ - public function createUsersWithListInput($body) { - - - // parse inputs - $resourcePath = "/user/createWithList"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array()); - - - - - - // body params - $_tempBody = null; - if (isset($body)) { - $_tempBody = $body; - } - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - // authentication setting, if any - $authSettings = array(); - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams, $authSettings); - - - } - - /** - * loginUser - * - * Logs user into the system - * - * @param string $username The user name for login (required) - * @param string $password The password for login in clear text (required) - * @return string - */ - public function loginUser($username, $password) { - - - // parse inputs - $resourcePath = "/user/login"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array()); - - // query params - if($username !== null) { - $queryParams['username'] = $this->apiClient->toQueryValue($username); - }// query params - if($password !== null) { - $queryParams['password'] = $this->apiClient->toQueryValue($password); - } - - - - - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - // authentication setting, if any - $authSettings = array(); - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams, $authSettings); - - if(! $response) { - return null; - } - - $responseObject = $this->apiClient->deserialize($response,'string'); - return $responseObject; - } - - /** - * logoutUser - * - * Logs out current logged in user session - * - * @return void - */ - public function logoutUser() { - - - // parse inputs - $resourcePath = "/user/logout"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array()); - - - - - - - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - // authentication setting, if any - $authSettings = array(); - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams, $authSettings); - - - } - - /** - * getUserByName - * - * Get user by user name - * - * @param string $username The name that needs to be fetched. Use user1 for testing. (required) - * @return User - */ - public function getUserByName($username) { - - // verify the required parameter 'username' is set - if ($username === null) { - throw new \InvalidArgumentException('Missing the required parameter $username when calling getUserByName'); - } - - - // parse inputs - $resourcePath = "/user/{username}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array()); - - - - // path params - if($username !== null) { - $resourcePath = str_replace("{" . "username" . "}", - $this->apiClient->toPathValue($username), $resourcePath); - } - - - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - // authentication setting, if any - $authSettings = array(); - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams, $authSettings); - - if(! $response) { - return null; - } - - $responseObject = $this->apiClient->deserialize($response,'User'); - return $responseObject; - } - - /** - * updateUser - * - * Updated user - * - * @param string $username name that need to be deleted (required) - * @param User $body Updated user object (required) - * @return void - */ - public function updateUser($username, $body) { - - // verify the required parameter 'username' is set - if ($username === null) { - throw new \InvalidArgumentException('Missing the required parameter $username when calling updateUser'); - } - - - // parse inputs - $resourcePath = "/user/{username}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "PUT"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array()); - - - - // path params - if($username !== null) { - $resourcePath = str_replace("{" . "username" . "}", - $this->apiClient->toPathValue($username), $resourcePath); - } - - // body params - $_tempBody = null; - if (isset($body)) { - $_tempBody = $body; - } - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - // authentication setting, if any - $authSettings = array(); - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams, $authSettings); - - - } - - /** - * deleteUser - * - * Delete user - * - * @param string $username The name that needs to be deleted (required) - * @return void - */ - public function deleteUser($username) { - - // verify the required parameter 'username' is set - if ($username === null) { - throw new \InvalidArgumentException('Missing the required parameter $username when calling deleteUser'); - } - - - // parse inputs - $resourcePath = "/user/{username}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "DELETE"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); - if (!is_null($_header_accept)) { - $headerParams['Accept'] = $_header_accept; - } - $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array()); - - - - // path params - if($username !== null) { - $resourcePath = str_replace("{" . "username" . "}", - $this->apiClient->toPathValue($username), $resourcePath); - } - - - - // for model (json/xml) - if (isset($_tempBody)) { - $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { - // for HTTP post (form) - $httpBody = $formParams; - } - - // authentication setting, if any - $authSettings = array(); - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams, $authSettings); - - - } - - -} From 879c1b921cd80594bc13563d4c5249c3c729e133 Mon Sep 17 00:00:00 2001 From: wing328 Date: Mon, 13 Jul 2015 15:31:20 +0800 Subject: [PATCH 9/9] update php petstore sample --- .../php/SwaggerClient-php/lib/Api/PetApi.php | 60 +++++++++---------- .../SwaggerClient-php/lib/Api/StoreApi.php | 18 +++--- .../php/SwaggerClient-php/lib/Api/UserApi.php | 49 +++++++-------- 3 files changed, 58 insertions(+), 69 deletions(-) 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 e9fef44a3ba1..8c0ce100d507 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php @@ -96,15 +96,14 @@ class PetApi * * Update an existing pet * - * @param \Swagger\Client\Model\Pet $body Pet object that needs to be added to the store (required) - * + * @param \Swagger\Client\Model\Pet $body Pet object that needs to be added to the store (optional) * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function updatePet($body) + public function updatePet($body=null) { - + // parse inputs $resourcePath = "/pet"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -161,15 +160,14 @@ class PetApi * * Add a new pet to the store * - * @param \Swagger\Client\Model\Pet $body Pet object that needs to be added to the store (required) - * + * @param \Swagger\Client\Model\Pet $body Pet object that needs to be added to the store (optional) * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function addPet($body) + public function addPet($body=null) { - + // parse inputs $resourcePath = "/pet"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -226,15 +224,14 @@ class PetApi * * Finds Pets by status * - * @param string[] $status Status values that need to be considered for filter (required) - * + * @param string[] $status Status values that need to be considered for filter (optional) * @return \Swagger\Client\Model\Pet[] * @throws \Swagger\Client\ApiException on non-2xx response */ - public function findPetsByStatus($status) + public function findPetsByStatus($status=null) { - + // parse inputs $resourcePath = "/pet/findByStatus"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -300,15 +297,14 @@ class PetApi * * Finds Pets by tags * - * @param string[] $tags Tags to filter by (required) - * + * @param string[] $tags Tags to filter by (optional) * @return \Swagger\Client\Model\Pet[] * @throws \Swagger\Client\ApiException on non-2xx response */ - public function findPetsByTags($tags) + public function findPetsByTags($tags=null) { - + // parse inputs $resourcePath = "/pet/findByTags"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -375,17 +371,17 @@ class PetApi * Find pet by ID * * @param int $pet_id ID of pet that needs to be fetched (required) - * * @return \Swagger\Client\Model\Pet * @throws \Swagger\Client\ApiException on non-2xx response */ public function getPetById($pet_id) { + // verify the required parameter 'pet_id' is set if ($pet_id === null) { throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling getPetById'); } - + // parse inputs $resourcePath = "/pet/{petId}"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -463,19 +459,19 @@ class PetApi * 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 (required) - * @param string $status Updated status of the pet (required) - * + * @param string $name Updated name of the pet (optional) + * @param string $status Updated status of the pet (optional) * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function updatePetWithForm($pet_id, $name, $status) + public function updatePetWithForm($pet_id, $name=null, $status=null) { + // verify the required parameter 'pet_id' is set if ($pet_id === null) { throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling updatePetWithForm'); } - + // parse inputs $resourcePath = "/pet/{petId}"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -541,19 +537,19 @@ class PetApi * * Deletes a pet * - * @param string $api_key (required) + * @param string $api_key (optional) * @param int $pet_id Pet id to delete (required) - * * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function deletePet($api_key, $pet_id) + public function deletePet($api_key=null, $pet_id) { + // verify the required parameter 'pet_id' is set if ($pet_id === null) { throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling deletePet'); } - + // parse inputs $resourcePath = "/pet/{petId}"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -617,19 +613,19 @@ class PetApi * uploads an image * * @param int $pet_id ID of pet to update (required) - * @param string $additional_metadata Additional data to pass to server (required) - * @param \SplFileObject $file file to upload (required) - * + * @param string $additional_metadata Additional data to pass to server (optional) + * @param \SplFileObject $file file to upload (optional) * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function uploadFile($pet_id, $additional_metadata, $file) + public function uploadFile($pet_id, $additional_metadata=null, $file=null) { + // verify the required parameter 'pet_id' is set if ($pet_id === null) { throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling uploadFile'); } - + // parse inputs $resourcePath = "/pet/{petId}/uploadImage"; $resourcePath = str_replace("{format}", "json", $resourcePath); 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 5ad1da9e887c..ede8a3c14dad 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php @@ -96,14 +96,13 @@ class StoreApi * * Returns pet inventories by status * - * * @return map[string,int] * @throws \Swagger\Client\ApiException on non-2xx response */ public function getInventory() { - + // parse inputs $resourcePath = "/store/inventory"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -170,15 +169,14 @@ class StoreApi * * Place an order for a pet * - * @param \Swagger\Client\Model\Order $body order placed for purchasing the pet (required) - * + * @param \Swagger\Client\Model\Order $body order placed for purchasing the pet (optional) * @return \Swagger\Client\Model\Order * @throws \Swagger\Client\ApiException on non-2xx response */ - public function placeOrder($body) + public function placeOrder($body=null) { - + // parse inputs $resourcePath = "/store/order"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -243,17 +241,17 @@ class StoreApi * Find purchase order by ID * * @param string $order_id ID of pet that needs to be fetched (required) - * * @return \Swagger\Client\Model\Order * @throws \Swagger\Client\ApiException on non-2xx response */ public function getOrderById($order_id) { + // verify the required parameter 'order_id' is set if ($order_id === null) { throw new \InvalidArgumentException('Missing the required parameter $order_id when calling getOrderById'); } - + // parse inputs $resourcePath = "/store/order/{orderId}"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -321,17 +319,17 @@ class StoreApi * Delete purchase order by ID * * @param string $order_id ID of the order that needs to be deleted (required) - * * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ public function deleteOrder($order_id) { + // verify the required parameter 'order_id' is set if ($order_id === null) { throw new \InvalidArgumentException('Missing the required parameter $order_id when calling deleteOrder'); } - + // parse inputs $resourcePath = "/store/order/{orderId}"; $resourcePath = str_replace("{format}", "json", $resourcePath); 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 37f739c50eaf..773181a52fc0 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php @@ -96,15 +96,14 @@ class UserApi * * Create user * - * @param \Swagger\Client\Model\User $body Created user object (required) - * + * @param \Swagger\Client\Model\User $body Created user object (optional) * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function createUser($body) + public function createUser($body=null) { - + // parse inputs $resourcePath = "/user"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -158,15 +157,14 @@ class UserApi * * Creates list of users with given input array * - * @param \Swagger\Client\Model\User[] $body List of user object (required) - * + * @param \Swagger\Client\Model\User[] $body List of user object (optional) * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function createUsersWithArrayInput($body) + public function createUsersWithArrayInput($body=null) { - + // parse inputs $resourcePath = "/user/createWithArray"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -220,15 +218,14 @@ class UserApi * * Creates list of users with given input array * - * @param \Swagger\Client\Model\User[] $body List of user object (required) - * + * @param \Swagger\Client\Model\User[] $body List of user object (optional) * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function createUsersWithListInput($body) + public function createUsersWithListInput($body=null) { - + // parse inputs $resourcePath = "/user/createWithList"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -282,16 +279,15 @@ class UserApi * * Logs user into the system * - * @param string $username The user name for login (required) - * @param string $password The password for login in clear text (required) - * + * @param string $username The user name for login (optional) + * @param string $password The password for login in clear text (optional) * @return string * @throws \Swagger\Client\ApiException on non-2xx response */ - public function loginUser($username, $password) + public function loginUser($username=null, $password=null) { - + // parse inputs $resourcePath = "/user/login"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -357,14 +353,13 @@ class UserApi * * Logs out current logged in user session * - * * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ public function logoutUser() { - + // parse inputs $resourcePath = "/user/logout"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -415,17 +410,17 @@ class UserApi * Get user by user name * * @param string $username The name that needs to be fetched. Use user1 for testing. (required) - * * @return \Swagger\Client\Model\User * @throws \Swagger\Client\ApiException on non-2xx response */ public function getUserByName($username) { + // verify the required parameter 'username' is set if ($username === null) { throw new \InvalidArgumentException('Missing the required parameter $username when calling getUserByName'); } - + // parse inputs $resourcePath = "/user/{username}"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -493,18 +488,18 @@ class UserApi * Updated user * * @param string $username name that need to be deleted (required) - * @param \Swagger\Client\Model\User $body Updated user object (required) - * + * @param \Swagger\Client\Model\User $body Updated user object (optional) * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function updateUser($username, $body) + public function updateUser($username, $body=null) { + // verify the required parameter 'username' is set if ($username === null) { throw new \InvalidArgumentException('Missing the required parameter $username when calling updateUser'); } - + // parse inputs $resourcePath = "/user/{username}"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -566,17 +561,17 @@ class UserApi * Delete user * * @param string $username The name that needs to be deleted (required) - * * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ public function deleteUser($username) { + // verify the required parameter 'username' is set if ($username === null) { throw new \InvalidArgumentException('Missing the required parameter $username when calling deleteUser'); } - + // parse inputs $resourcePath = "/user/{username}"; $resourcePath = str_replace("{format}", "json", $resourcePath);