From bb341832a578eb8a711adb764198325314a6d7af Mon Sep 17 00:00:00 2001 From: wing328 Date: Sun, 6 Dec 2015 19:00:52 +0800 Subject: [PATCH 1/6] add http info to php api methods --- .../src/main/resources/php/ApiClient.mustache | 4 +- .../src/main/resources/php/api.mustache | 30 ++- .../php/SwaggerClient-php/lib/Api/PetApi.php | 183 +++++++++++++++--- .../SwaggerClient-php/lib/Api/StoreApi.php | 97 ++++++++-- .../php/SwaggerClient-php/lib/Api/UserApi.php | 173 ++++++++++++++--- .../php/SwaggerClient-php/lib/ApiClient.php | 4 +- 6 files changed, 416 insertions(+), 75 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache index 11fe3827d48..35c065c81de 100644 --- a/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache @@ -231,7 +231,7 @@ class ApiClient } 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); + return array($http_body, $response_info['http_code'], $http_header); } $data = json_decode($http_body); @@ -249,7 +249,7 @@ class ApiClient $response_info['http_code'], $http_header, $data ); } - return array($data, $http_header); + return array($data, $response_info['http_code'], $http_header); } /** diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index 53a81030813..2ba06331d50 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -92,7 +92,7 @@ use \{{invokerPackage}}\ObjectSerializer; {{#operation}} /** - * {{{nickname}}} + * {{{operationId}}} * * {{{summary}}} * @@ -100,12 +100,28 @@ use \{{invokerPackage}}\ObjectSerializer; {{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} * @throws \{{invokerPackage}}\ApiException on non-2xx response */ - public function {{nickname}}({{#allParams}}${{paramName}}{{^required}}=null{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) + public function {{operationId}} ({{#allParams}}${{paramName}}{{^required}}=null{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) + { + list($response, $statusCode, $httpHeader) = $this->{{operationId}}WithHttpInfo ({{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); + return $response; + } + + + /** + * {{{operationId}}} + * + * {{{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 {{operationId}}WithHttpInfo ({{#allParams}}${{paramName}}{{^required}}=null{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { {{#allParams}}{{#required}} // verify the required parameter '{{paramName}}' is set if (${{paramName}} === null) { - throw new \InvalidArgumentException('Missing the required parameter ${{paramName}} when calling {{nickname}}'); + throw new \InvalidArgumentException('Missing the required parameter ${{paramName}} when calling {{operationId}}'); }{{/required}}{{/allParams}} // parse inputs @@ -182,17 +198,17 @@ use \{{invokerPackage}}\ObjectSerializer; // make the API Call try { - list($response, $httpHeader) = $this->apiClient->callApi( + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams{{#returnType}}, '{{returnType}}'{{/returnType}} ); {{#returnType}} if (!$response) { - return null; + return array(null, $statusCode, $httpHeader); } - return $this->apiClient->getSerializer()->deserialize($response, '{{returnType}}', $httpHeader); + return array($this->apiClient->getSerializer()->deserialize($response, '{{returnType}}', $httpHeader)); {{/returnType}} } catch (ApiException $e) { switch ($e->getCode()) { {{#responses}}{{#dataType}} @@ -205,7 +221,7 @@ use \{{invokerPackage}}\ObjectSerializer; throw $e; } {{#returnType}} - return null; + return array(null, $statusCode, $httpHeader); {{/returnType}} } {{/operation}} diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php index bc03a7974d3..0e971841f50 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php @@ -100,7 +100,23 @@ class PetApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function updatePet($body=null) + public function updatePet ($body=null) + { + list($response, $statusCode, $httpHeader) = $this->updatePetWithHttpInfo ($body); + return $response; + } + + + /** + * updatePet + * + * Update an existing pet + * + * @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 updatePetWithHttpInfo ($body=null) { @@ -143,7 +159,7 @@ class PetApi // make the API Call try { - list($response, $httpHeader) = $this->apiClient->callApi( + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams @@ -167,7 +183,23 @@ class PetApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function addPet($body=null) + public function addPet ($body=null) + { + list($response, $statusCode, $httpHeader) = $this->addPetWithHttpInfo ($body); + return $response; + } + + + /** + * addPet + * + * Add a new pet to the store + * + * @param \Swagger\Client\Model\Pet $body Pet object that needs to be added to the store (optional) + * @return void + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function addPetWithHttpInfo ($body=null) { @@ -210,7 +242,7 @@ class PetApi // make the API Call try { - list($response, $httpHeader) = $this->apiClient->callApi( + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams @@ -234,7 +266,23 @@ class PetApi * @return \Swagger\Client\Model\Pet[] * @throws \Swagger\Client\ApiException on non-2xx response */ - public function findPetsByStatus($status=null) + public function findPetsByStatus ($status=null) + { + list($response, $statusCode, $httpHeader) = $this->findPetsByStatusWithHttpInfo ($status); + return $response; + } + + + /** + * findPetsByStatus + * + * Finds Pets by status + * + * @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 findPetsByStatusWithHttpInfo ($status=null) { @@ -276,17 +324,17 @@ class PetApi // make the API Call try { - list($response, $httpHeader) = $this->apiClient->callApi( + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams, '\Swagger\Client\Model\Pet[]' ); if (!$response) { - return null; + return array(null, $statusCode, $httpHeader); } - return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Pet[]', $httpHeader); + return array($this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Pet[]', $httpHeader)); } catch (ApiException $e) { switch ($e->getCode()) { @@ -299,7 +347,7 @@ class PetApi throw $e; } - return null; + return array(null, $statusCode, $httpHeader); } @@ -312,7 +360,23 @@ class PetApi * @return \Swagger\Client\Model\Pet[] * @throws \Swagger\Client\ApiException on non-2xx response */ - public function findPetsByTags($tags=null) + public function findPetsByTags ($tags=null) + { + list($response, $statusCode, $httpHeader) = $this->findPetsByTagsWithHttpInfo ($tags); + return $response; + } + + + /** + * findPetsByTags + * + * Finds Pets by tags + * + * @param string[] $tags Tags to filter by (optional) + * @return \Swagger\Client\Model\Pet[] + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function findPetsByTagsWithHttpInfo ($tags=null) { @@ -354,17 +418,17 @@ class PetApi // make the API Call try { - list($response, $httpHeader) = $this->apiClient->callApi( + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams, '\Swagger\Client\Model\Pet[]' ); if (!$response) { - return null; + return array(null, $statusCode, $httpHeader); } - return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Pet[]', $httpHeader); + return array($this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Pet[]', $httpHeader)); } catch (ApiException $e) { switch ($e->getCode()) { @@ -377,7 +441,7 @@ class PetApi throw $e; } - return null; + return array(null, $statusCode, $httpHeader); } @@ -390,7 +454,23 @@ class PetApi * @return \Swagger\Client\Model\Pet * @throws \Swagger\Client\ApiException on non-2xx response */ - public function getPetById($pet_id) + public function getPetById ($pet_id) + { + list($response, $statusCode, $httpHeader) = $this->getPetByIdWithHttpInfo ($pet_id); + return $response; + } + + + /** + * 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 getPetByIdWithHttpInfo ($pet_id) { // verify the required parameter 'pet_id' is set @@ -442,17 +522,17 @@ class PetApi // make the API Call try { - list($response, $httpHeader) = $this->apiClient->callApi( + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams, '\Swagger\Client\Model\Pet' ); if (!$response) { - return null; + return array(null, $statusCode, $httpHeader); } - return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Pet', $httpHeader); + return array($this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Pet', $httpHeader)); } catch (ApiException $e) { switch ($e->getCode()) { @@ -465,7 +545,7 @@ class PetApi throw $e; } - return null; + return array(null, $statusCode, $httpHeader); } @@ -480,7 +560,25 @@ class PetApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function updatePetWithForm($pet_id, $name=null, $status=null) + public function updatePetWithForm ($pet_id, $name=null, $status=null) + { + list($response, $statusCode, $httpHeader) = $this->updatePetWithFormWithHttpInfo ($pet_id, $name, $status); + return $response; + } + + + /** + * 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 (optional) + * @param string $status Updated status of the pet (optional) + * @return void + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function updatePetWithFormWithHttpInfo ($pet_id, $name=null, $status=null) { // verify the required parameter 'pet_id' is set @@ -542,7 +640,7 @@ class PetApi // make the API Call try { - list($response, $httpHeader) = $this->apiClient->callApi( + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams @@ -567,7 +665,24 @@ class PetApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function deletePet($pet_id, $api_key=null) + public function deletePet ($pet_id, $api_key=null) + { + list($response, $statusCode, $httpHeader) = $this->deletePetWithHttpInfo ($pet_id, $api_key); + return $response; + } + + + /** + * deletePet + * + * Deletes a pet + * + * @param int $pet_id Pet id to delete (required) + * @param string $api_key (optional) + * @return void + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function deletePetWithHttpInfo ($pet_id, $api_key=null) { // verify the required parameter 'pet_id' is set @@ -620,7 +735,7 @@ class PetApi // make the API Call try { - list($response, $httpHeader) = $this->apiClient->callApi( + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams @@ -646,7 +761,25 @@ class PetApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function uploadFile($pet_id, $additional_metadata=null, $file=null) + public function uploadFile ($pet_id, $additional_metadata=null, $file=null) + { + list($response, $statusCode, $httpHeader) = $this->uploadFileWithHttpInfo ($pet_id, $additional_metadata, $file); + return $response; + } + + + /** + * uploadFile + * + * uploads an image + * + * @param int $pet_id ID of pet to update (required) + * @param string $additional_metadata Additional data to pass to server (optional) + * @param \SplFileObject $file file to upload (optional) + * @return void + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function uploadFileWithHttpInfo ($pet_id, $additional_metadata=null, $file=null) { // verify the required parameter 'pet_id' is set @@ -714,7 +847,7 @@ class PetApi // make the API Call try { - list($response, $httpHeader) = $this->apiClient->callApi( + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php index d709330b056..d32b2ac783e 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php @@ -99,7 +99,22 @@ class StoreApi * @return map[string,int] * @throws \Swagger\Client\ApiException on non-2xx response */ - public function getInventory() + public function getInventory () + { + list($response, $statusCode, $httpHeader) = $this->getInventoryWithHttpInfo (); + return $response; + } + + + /** + * getInventory + * + * Returns pet inventories by status + * + * @return map[string,int] + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function getInventoryWithHttpInfo () { @@ -140,17 +155,17 @@ class StoreApi // make the API Call try { - list($response, $httpHeader) = $this->apiClient->callApi( + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams, 'map[string,int]' ); if (!$response) { - return null; + return array(null, $statusCode, $httpHeader); } - return $this->apiClient->getSerializer()->deserialize($response, 'map[string,int]', $httpHeader); + return array($this->apiClient->getSerializer()->deserialize($response, 'map[string,int]', $httpHeader)); } catch (ApiException $e) { switch ($e->getCode()) { @@ -163,7 +178,7 @@ class StoreApi throw $e; } - return null; + return array(null, $statusCode, $httpHeader); } @@ -176,7 +191,23 @@ class StoreApi * @return \Swagger\Client\Model\Order * @throws \Swagger\Client\ApiException on non-2xx response */ - public function placeOrder($body=null) + public function placeOrder ($body=null) + { + list($response, $statusCode, $httpHeader) = $this->placeOrderWithHttpInfo ($body); + return $response; + } + + + /** + * placeOrder + * + * Place an order for a pet + * + * @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 placeOrderWithHttpInfo ($body=null) { @@ -214,17 +245,17 @@ class StoreApi // make the API Call try { - list($response, $httpHeader) = $this->apiClient->callApi( + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams, '\Swagger\Client\Model\Order' ); if (!$response) { - return null; + return array(null, $statusCode, $httpHeader); } - return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Order', $httpHeader); + return array($this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Order', $httpHeader)); } catch (ApiException $e) { switch ($e->getCode()) { @@ -237,7 +268,7 @@ class StoreApi throw $e; } - return null; + return array(null, $statusCode, $httpHeader); } @@ -250,7 +281,23 @@ class StoreApi * @return \Swagger\Client\Model\Order * @throws \Swagger\Client\ApiException on non-2xx response */ - public function getOrderById($order_id) + public function getOrderById ($order_id) + { + list($response, $statusCode, $httpHeader) = $this->getOrderByIdWithHttpInfo ($order_id); + return $response; + } + + + /** + * 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 getOrderByIdWithHttpInfo ($order_id) { // verify the required parameter 'order_id' is set @@ -295,17 +342,17 @@ class StoreApi // make the API Call try { - list($response, $httpHeader) = $this->apiClient->callApi( + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams, '\Swagger\Client\Model\Order' ); if (!$response) { - return null; + return array(null, $statusCode, $httpHeader); } - return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Order', $httpHeader); + return array($this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Order', $httpHeader)); } catch (ApiException $e) { switch ($e->getCode()) { @@ -318,7 +365,7 @@ class StoreApi throw $e; } - return null; + return array(null, $statusCode, $httpHeader); } @@ -331,7 +378,23 @@ class StoreApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function deleteOrder($order_id) + public function deleteOrder ($order_id) + { + list($response, $statusCode, $httpHeader) = $this->deleteOrderWithHttpInfo ($order_id); + return $response; + } + + + /** + * 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 deleteOrderWithHttpInfo ($order_id) { // verify the required parameter 'order_id' is set @@ -376,7 +439,7 @@ class StoreApi // make the API Call try { - list($response, $httpHeader) = $this->apiClient->callApi( + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php index 8ce6301a51e..890b876a106 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php @@ -100,7 +100,23 @@ class UserApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function createUser($body=null) + public function createUser ($body=null) + { + list($response, $statusCode, $httpHeader) = $this->createUserWithHttpInfo ($body); + return $response; + } + + + /** + * createUser + * + * Create user + * + * @param \Swagger\Client\Model\User $body Created user object (optional) + * @return void + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function createUserWithHttpInfo ($body=null) { @@ -138,7 +154,7 @@ class UserApi // make the API Call try { - list($response, $httpHeader) = $this->apiClient->callApi( + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams @@ -162,7 +178,23 @@ class UserApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function createUsersWithArrayInput($body=null) + public function createUsersWithArrayInput ($body=null) + { + list($response, $statusCode, $httpHeader) = $this->createUsersWithArrayInputWithHttpInfo ($body); + return $response; + } + + + /** + * createUsersWithArrayInput + * + * Creates list of users with given input array + * + * @param \Swagger\Client\Model\User[] $body List of user object (optional) + * @return void + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function createUsersWithArrayInputWithHttpInfo ($body=null) { @@ -200,7 +232,7 @@ class UserApi // make the API Call try { - list($response, $httpHeader) = $this->apiClient->callApi( + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams @@ -224,7 +256,23 @@ class UserApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function createUsersWithListInput($body=null) + public function createUsersWithListInput ($body=null) + { + list($response, $statusCode, $httpHeader) = $this->createUsersWithListInputWithHttpInfo ($body); + return $response; + } + + + /** + * createUsersWithListInput + * + * Creates list of users with given input array + * + * @param \Swagger\Client\Model\User[] $body List of user object (optional) + * @return void + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function createUsersWithListInputWithHttpInfo ($body=null) { @@ -262,7 +310,7 @@ class UserApi // make the API Call try { - list($response, $httpHeader) = $this->apiClient->callApi( + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams @@ -287,7 +335,24 @@ class UserApi * @return string * @throws \Swagger\Client\ApiException on non-2xx response */ - public function loginUser($username=null, $password=null) + public function loginUser ($username=null, $password=null) + { + list($response, $statusCode, $httpHeader) = $this->loginUserWithHttpInfo ($username, $password); + return $response; + } + + + /** + * loginUser + * + * Logs user into the system + * + * @param string $username The user name for login (optional) + * @param string $password The password for login in clear text (optional) + * @return string + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function loginUserWithHttpInfo ($username=null, $password=null) { @@ -327,17 +392,17 @@ class UserApi // make the API Call try { - list($response, $httpHeader) = $this->apiClient->callApi( + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams, 'string' ); if (!$response) { - return null; + return array(null, $statusCode, $httpHeader); } - return $this->apiClient->getSerializer()->deserialize($response, 'string', $httpHeader); + return array($this->apiClient->getSerializer()->deserialize($response, 'string', $httpHeader)); } catch (ApiException $e) { switch ($e->getCode()) { @@ -350,7 +415,7 @@ class UserApi throw $e; } - return null; + return array(null, $statusCode, $httpHeader); } @@ -362,7 +427,22 @@ class UserApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function logoutUser() + public function logoutUser () + { + list($response, $statusCode, $httpHeader) = $this->logoutUserWithHttpInfo (); + return $response; + } + + + /** + * logoutUser + * + * Logs out current logged in user session + * + * @return void + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function logoutUserWithHttpInfo () { @@ -396,7 +476,7 @@ class UserApi // make the API Call try { - list($response, $httpHeader) = $this->apiClient->callApi( + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams @@ -420,7 +500,23 @@ class UserApi * @return \Swagger\Client\Model\User * @throws \Swagger\Client\ApiException on non-2xx response */ - public function getUserByName($username) + public function getUserByName ($username) + { + list($response, $statusCode, $httpHeader) = $this->getUserByNameWithHttpInfo ($username); + return $response; + } + + + /** + * 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 getUserByNameWithHttpInfo ($username) { // verify the required parameter 'username' is set @@ -465,17 +561,17 @@ class UserApi // make the API Call try { - list($response, $httpHeader) = $this->apiClient->callApi( + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams, '\Swagger\Client\Model\User' ); if (!$response) { - return null; + return array(null, $statusCode, $httpHeader); } - return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\User', $httpHeader); + return array($this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\User', $httpHeader)); } catch (ApiException $e) { switch ($e->getCode()) { @@ -488,7 +584,7 @@ class UserApi throw $e; } - return null; + return array(null, $statusCode, $httpHeader); } @@ -502,7 +598,24 @@ class UserApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function updateUser($username, $body=null) + public function updateUser ($username, $body=null) + { + list($response, $statusCode, $httpHeader) = $this->updateUserWithHttpInfo ($username, $body); + return $response; + } + + + /** + * updateUser + * + * Updated user + * + * @param string $username name that need to be deleted (required) + * @param \Swagger\Client\Model\User $body Updated user object (optional) + * @return void + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function updateUserWithHttpInfo ($username, $body=null) { // verify the required parameter 'username' is set @@ -551,7 +664,7 @@ class UserApi // make the API Call try { - list($response, $httpHeader) = $this->apiClient->callApi( + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams @@ -575,7 +688,23 @@ class UserApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function deleteUser($username) + public function deleteUser ($username) + { + list($response, $statusCode, $httpHeader) = $this->deleteUserWithHttpInfo ($username); + return $response; + } + + + /** + * 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 deleteUserWithHttpInfo ($username) { // verify the required parameter 'username' is set @@ -620,7 +749,7 @@ class UserApi // make the API Call try { - list($response, $httpHeader) = $this->apiClient->callApi( + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, $headerParams diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php b/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php index a0bb07273e4..b5b63793e85 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php @@ -231,7 +231,7 @@ class ApiClient } 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); + return array($http_body, $response_info['http_code'], $http_header); } $data = json_decode($http_body); @@ -249,7 +249,7 @@ class ApiClient $response_info['http_code'], $http_header, $data ); } - return array($data, $http_header); + return array($data, $response_info['http_code'], $http_header); } /** From b282d4fbea9a1265aef7099104324ffb70e2b5b8 Mon Sep 17 00:00:00 2001 From: wing328 Date: Sun, 6 Dec 2015 23:58:25 +0800 Subject: [PATCH 2/6] add http_parse_headers, update test case --- .../src/main/resources/php/ApiClient.mustache | 50 ++++++++++++++++++- .../resources/php/ObjectSerializer.mustache | 2 +- .../src/main/resources/php/api.mustache | 7 ++- .../php/SwaggerClient-php/lib/Api/PetApi.php | 26 ++++------ .../SwaggerClient-php/lib/Api/StoreApi.php | 22 ++++---- .../php/SwaggerClient-php/lib/Api/UserApi.php | 20 +++----- .../php/SwaggerClient-php/lib/ApiClient.php | 50 ++++++++++++++++++- .../lib/ObjectSerializer.php | 2 +- .../SwaggerClient-php/tests/PetApiTest.php | 19 +++++++ 9 files changed, 146 insertions(+), 52 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache index 35c065c81de..86998fd16d0 100644 --- a/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache @@ -216,7 +216,7 @@ class ApiClient // Make the request $response = curl_exec($curl); $http_header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE); - $http_header = substr($response, 0, $http_header_size); + $http_header = $this->http_parse_headers(substr($response, 0, $http_header_size)); $http_body = substr($response, $http_header_size); $response_info = curl_getinfo($curl); @@ -287,4 +287,52 @@ class ApiClient return implode(',', $content_type); } } + + /** + * Return an array of HTTP response headers + * + * @param string $raw_headers A string of raw HTTP response headers + * + * @return string[] Array of HTTP response heaers + */ + protected function http_parse_headers($raw_headers) + { + // ref/credit: http://php.net/manual/en/function.http-parse-headers.php#112986 + $headers = array(); + $key = ''; // [+] + + foreach(explode("\n", $raw_headers) as $i => $h) + { + $h = explode(':', $h, 2); + + if (isset($h[1])) + { + if (!isset($headers[$h[0]])) + $headers[$h[0]] = trim($h[1]); + elseif (is_array($headers[$h[0]])) + { + // $tmp = array_merge($headers[$h[0]], array(trim($h[1]))); // [-] + // $headers[$h[0]] = $tmp; // [-] + $headers[$h[0]] = array_merge($headers[$h[0]], array(trim($h[1]))); // [+] + } + else + { + // $tmp = array_merge(array($headers[$h[0]]), array(trim($h[1]))); // [-] + // $headers[$h[0]] = $tmp; // [-] + $headers[$h[0]] = array_merge(array($headers[$h[0]]), array(trim($h[1]))); // [+] + } + + $key = $h[0]; // [+] + } + else // [+] + { // [+] + if (substr($h[0], 0, 1) == "\t") // [+] + $headers[$key] .= "\r\n\t".trim($h[0]); // [+] + elseif (!$key) // [+] + $headers[0] = trim($h[0]);trim($h[0]); // [+] + } // [+] + } + + return $headers; + } } diff --git a/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache b/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache index 45b56aa9b97..54fb66a9543 100644 --- a/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache +++ b/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache @@ -198,7 +198,7 @@ class ObjectSerializer $deserialized = $data; } elseif ($class === '\SplFileObject') { // determine file name - if (preg_match('/Content-Disposition: inline; filename=[\'"]?([^\'"\s]+)[\'"]?$/i', $httpHeader, $match)) { + if (array_key_exists('Content-Disposition', $httpHeaders) && preg_match('/inline; filename=[\'"]?([^\'"\s]+)[\'"]?$/i', $httpHeader['Content-Disposition'], $match)) { $filename = Configuration::getDefaultConfiguration()->getTempFolderPath().$match[1]; } else { $filename = tempnam(Configuration::getDefaultConfiguration()->getTempFolderPath(), ''); diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index 2ba06331d50..7cd4e659b98 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -208,7 +208,9 @@ use \{{invokerPackage}}\ObjectSerializer; return array(null, $statusCode, $httpHeader); } - return array($this->apiClient->getSerializer()->deserialize($response, '{{returnType}}', $httpHeader)); + return array($this->apiClient->getSerializer()->deserialize($response, '{{returnType}}', $httpHeader), $statusCode, $httpHeader); + {{/returnType}}{{#returnType}} + return array(null, $statusCode, $httpHeader); {{/returnType}} } catch (ApiException $e) { switch ($e->getCode()) { {{#responses}}{{#dataType}} @@ -220,9 +222,6 @@ use \{{invokerPackage}}\ObjectSerializer; throw $e; } - {{#returnType}} - return array(null, $statusCode, $httpHeader); - {{/returnType}} } {{/operation}} } 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 0e971841f50..44b35efe7ae 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php @@ -171,7 +171,6 @@ class PetApi throw $e; } - } /** @@ -254,7 +253,6 @@ class PetApi throw $e; } - } /** @@ -334,7 +332,9 @@ class PetApi return array(null, $statusCode, $httpHeader); } - return array($this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Pet[]', $httpHeader)); + return array($this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Pet[]', $httpHeader), $statusCode, $httpHeader); + + return array(null, $statusCode, $httpHeader); } catch (ApiException $e) { switch ($e->getCode()) { @@ -346,9 +346,6 @@ class PetApi throw $e; } - - return array(null, $statusCode, $httpHeader); - } /** @@ -428,7 +425,9 @@ class PetApi return array(null, $statusCode, $httpHeader); } - return array($this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Pet[]', $httpHeader)); + return array($this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Pet[]', $httpHeader), $statusCode, $httpHeader); + + return array(null, $statusCode, $httpHeader); } catch (ApiException $e) { switch ($e->getCode()) { @@ -440,9 +439,6 @@ class PetApi throw $e; } - - return array(null, $statusCode, $httpHeader); - } /** @@ -532,7 +528,9 @@ class PetApi return array(null, $statusCode, $httpHeader); } - return array($this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Pet', $httpHeader)); + return array($this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Pet', $httpHeader), $statusCode, $httpHeader); + + return array(null, $statusCode, $httpHeader); } catch (ApiException $e) { switch ($e->getCode()) { @@ -544,9 +542,6 @@ class PetApi throw $e; } - - return array(null, $statusCode, $httpHeader); - } /** @@ -652,7 +647,6 @@ class PetApi throw $e; } - } /** @@ -747,7 +741,6 @@ class PetApi throw $e; } - } /** @@ -859,7 +852,6 @@ class PetApi 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 d32b2ac783e..26b25027a1b 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php @@ -165,7 +165,9 @@ class StoreApi return array(null, $statusCode, $httpHeader); } - return array($this->apiClient->getSerializer()->deserialize($response, 'map[string,int]', $httpHeader)); + return array($this->apiClient->getSerializer()->deserialize($response, 'map[string,int]', $httpHeader), $statusCode, $httpHeader); + + return array(null, $statusCode, $httpHeader); } catch (ApiException $e) { switch ($e->getCode()) { @@ -177,9 +179,6 @@ class StoreApi throw $e; } - - return array(null, $statusCode, $httpHeader); - } /** @@ -255,7 +254,9 @@ class StoreApi return array(null, $statusCode, $httpHeader); } - return array($this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Order', $httpHeader)); + return array($this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Order', $httpHeader), $statusCode, $httpHeader); + + return array(null, $statusCode, $httpHeader); } catch (ApiException $e) { switch ($e->getCode()) { @@ -267,9 +268,6 @@ class StoreApi throw $e; } - - return array(null, $statusCode, $httpHeader); - } /** @@ -352,7 +350,9 @@ class StoreApi return array(null, $statusCode, $httpHeader); } - return array($this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Order', $httpHeader)); + return array($this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Order', $httpHeader), $statusCode, $httpHeader); + + return array(null, $statusCode, $httpHeader); } catch (ApiException $e) { switch ($e->getCode()) { @@ -364,9 +364,6 @@ class StoreApi throw $e; } - - return array(null, $statusCode, $httpHeader); - } /** @@ -451,7 +448,6 @@ class StoreApi 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 890b876a106..9e2f3aa9eab 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php @@ -166,7 +166,6 @@ class UserApi throw $e; } - } /** @@ -244,7 +243,6 @@ class UserApi throw $e; } - } /** @@ -322,7 +320,6 @@ class UserApi throw $e; } - } /** @@ -402,7 +399,9 @@ class UserApi return array(null, $statusCode, $httpHeader); } - return array($this->apiClient->getSerializer()->deserialize($response, 'string', $httpHeader)); + return array($this->apiClient->getSerializer()->deserialize($response, 'string', $httpHeader), $statusCode, $httpHeader); + + return array(null, $statusCode, $httpHeader); } catch (ApiException $e) { switch ($e->getCode()) { @@ -414,9 +413,6 @@ class UserApi throw $e; } - - return array(null, $statusCode, $httpHeader); - } /** @@ -488,7 +484,6 @@ class UserApi throw $e; } - } /** @@ -571,7 +566,9 @@ class UserApi return array(null, $statusCode, $httpHeader); } - return array($this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\User', $httpHeader)); + return array($this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\User', $httpHeader), $statusCode, $httpHeader); + + return array(null, $statusCode, $httpHeader); } catch (ApiException $e) { switch ($e->getCode()) { @@ -583,9 +580,6 @@ class UserApi throw $e; } - - return array(null, $statusCode, $httpHeader); - } /** @@ -676,7 +670,6 @@ class UserApi throw $e; } - } /** @@ -761,7 +754,6 @@ class UserApi 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 b5b63793e85..2f3aacd1ffd 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php @@ -216,7 +216,7 @@ class ApiClient // Make the request $response = curl_exec($curl); $http_header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE); - $http_header = substr($response, 0, $http_header_size); + $http_header = $this->http_parse_headers(substr($response, 0, $http_header_size)); $http_body = substr($response, $http_header_size); $response_info = curl_getinfo($curl); @@ -287,4 +287,52 @@ class ApiClient return implode(',', $content_type); } } + + /** + * Return an array of HTTP response headers + * + * @param string $raw_headers A string of raw HTTP response headers + * + * @return string[] Array of HTTP response heaers + */ + protected function http_parse_headers($raw_headers) + { + // ref/credit: http://php.net/manual/en/function.http-parse-headers.php#112986 + $headers = array(); + $key = ''; // [+] + + foreach(explode("\n", $raw_headers) as $i => $h) + { + $h = explode(':', $h, 2); + + if (isset($h[1])) + { + if (!isset($headers[$h[0]])) + $headers[$h[0]] = trim($h[1]); + elseif (is_array($headers[$h[0]])) + { + // $tmp = array_merge($headers[$h[0]], array(trim($h[1]))); // [-] + // $headers[$h[0]] = $tmp; // [-] + $headers[$h[0]] = array_merge($headers[$h[0]], array(trim($h[1]))); // [+] + } + else + { + // $tmp = array_merge(array($headers[$h[0]]), array(trim($h[1]))); // [-] + // $headers[$h[0]] = $tmp; // [-] + $headers[$h[0]] = array_merge(array($headers[$h[0]]), array(trim($h[1]))); // [+] + } + + $key = $h[0]; // [+] + } + else // [+] + { // [+] + if (substr($h[0], 0, 1) == "\t") // [+] + $headers[$key] .= "\r\n\t".trim($h[0]); // [+] + elseif (!$key) // [+] + $headers[0] = trim($h[0]);trim($h[0]); // [+] + } // [+] + } + + return $headers; + } } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php b/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php index 0d281b9d1fa..22d03030fb3 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php @@ -198,7 +198,7 @@ class ObjectSerializer $deserialized = $data; } elseif ($class === '\SplFileObject') { // determine file name - if (preg_match('/Content-Disposition: inline; filename=[\'"]?([^\'"\s]+)[\'"]?$/i', $httpHeader, $match)) { + if (array_key_exists('Content-Disposition', $httpHeaders) && preg_match('/inline; filename=[\'"]?([^\'"\s]+)[\'"]?$/i', $httpHeader['Content-Disposition'], $match)) { $filename = Configuration::getDefaultConfiguration()->getTempFolderPath().$match[1]; } else { $filename = tempnam(Configuration::getDefaultConfiguration()->getTempFolderPath(), ''); diff --git a/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php b/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php index 58d5cd661f4..c30c95eaa69 100644 --- a/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php @@ -105,6 +105,25 @@ class PetApiTest extends \PHPUnit_Framework_TestCase $this->assertSame($response->getTags()[0]->getName(), 'test php tag'); } + // test getPetById with a Pet object (id 10005) + public function testGetPetByIdWithHttpInfo() + { + // initialize the API client without host + $pet_id = 10005; // ID of pet that needs to be fetched + $pet_api = new Swagger\Client\Api\PetAPI(); + $pet_api->getApiClient()->getConfig()->setApiKey('api_key', '111222333444555'); + // return Pet (model) + list($response, $status_code, $response_headers) = $pet_api->getPetByIdWithHttpInfo($pet_id); + $this->assertSame($response->getId(), $pet_id); + $this->assertSame($response->getName(), 'PHP Unit Test'); + $this->assertSame($response->getCategory()->getId(), $pet_id); + $this->assertSame($response->getCategory()->getName(), 'test php category'); + $this->assertSame($response->getTags()[0]->getId(), $pet_id); + $this->assertSame($response->getTags()[0]->getName(), 'test php tag'); + $this->assertSame($status_code, 200); + $this->assertSame($response_headers['Content-Type'], 'application/json'); + } + // test getPetByStatus and verify by the "id" of the response public function testFindPetByStatus() { From 11466570f752fe15e8e0d09d0f7cdd6a95e960f1 Mon Sep 17 00:00:00 2001 From: wing328 Date: Mon, 7 Dec 2015 00:30:17 +0800 Subject: [PATCH 3/6] php add test case for withinfo method returnig void --- .../src/main/resources/php/api.mustache | 6 ++-- .../php/SwaggerClient-php/lib/Api/PetApi.php | 32 +++++++++++-------- .../SwaggerClient-php/lib/Api/StoreApi.php | 16 ++++------ .../php/SwaggerClient-php/lib/Api/UserApi.php | 32 ++++++++++++------- .../SwaggerClient-php/tests/PetApiTest.php | 21 +++++++++++- 5 files changed, 67 insertions(+), 40 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index 7cd4e659b98..0b28b2b4ca6 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -108,12 +108,12 @@ use \{{invokerPackage}}\ObjectSerializer; /** - * {{{operationId}}} + * {{{operationId}}}WithHttpInfo * * {{{summary}}} * {{#allParams}} * @param {{dataType}} ${{paramName}} {{description}} {{#required}}(required){{/required}}{{^required}}(optional){{/required}} - {{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} + {{/allParams}} * @return Array of {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}null{{/returnType}}, HTTP status code, HTTP response headers (array of strings) * @throws \{{invokerPackage}}\ApiException on non-2xx response */ public function {{operationId}}WithHttpInfo ({{#allParams}}${{paramName}}{{^required}}=null{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) @@ -209,7 +209,7 @@ use \{{invokerPackage}}\ObjectSerializer; } return array($this->apiClient->getSerializer()->deserialize($response, '{{returnType}}', $httpHeader), $statusCode, $httpHeader); - {{/returnType}}{{#returnType}} + {{/returnType}}{{^returnType}} return array(null, $statusCode, $httpHeader); {{/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 44b35efe7ae..792053877a4 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php @@ -113,7 +113,7 @@ class PetApi * Update an existing pet * * @param \Swagger\Client\Model\Pet $body Pet object that needs to be added to the store (optional) - * @return void + * @return Array of null, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ public function updatePetWithHttpInfo ($body=null) @@ -165,6 +165,8 @@ class PetApi $headerParams ); + return array(null, $statusCode, $httpHeader); + } catch (ApiException $e) { switch ($e->getCode()) { } @@ -195,7 +197,7 @@ 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 (optional) - * @return void + * @return Array of null, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ public function addPetWithHttpInfo ($body=null) @@ -247,6 +249,8 @@ class PetApi $headerParams ); + return array(null, $statusCode, $httpHeader); + } catch (ApiException $e) { switch ($e->getCode()) { } @@ -277,7 +281,7 @@ class PetApi * Finds Pets by status * * @param string[] $status Status values that need to be considered for filter (optional) - * @return \Swagger\Client\Model\Pet[] + * @return Array of \Swagger\Client\Model\Pet[], HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ public function findPetsByStatusWithHttpInfo ($status=null) @@ -334,8 +338,6 @@ class PetApi return array($this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Pet[]', $httpHeader), $statusCode, $httpHeader); - return array(null, $statusCode, $httpHeader); - } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -370,7 +372,7 @@ class PetApi * Finds Pets by tags * * @param string[] $tags Tags to filter by (optional) - * @return \Swagger\Client\Model\Pet[] + * @return Array of \Swagger\Client\Model\Pet[], HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ public function findPetsByTagsWithHttpInfo ($tags=null) @@ -427,8 +429,6 @@ class PetApi return array($this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Pet[]', $httpHeader), $statusCode, $httpHeader); - return array(null, $statusCode, $httpHeader); - } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -463,7 +463,7 @@ class PetApi * Find pet by ID * * @param int $pet_id ID of pet that needs to be fetched (required) - * @return \Swagger\Client\Model\Pet + * @return Array of \Swagger\Client\Model\Pet, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ public function getPetByIdWithHttpInfo ($pet_id) @@ -530,8 +530,6 @@ class PetApi return array($this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Pet', $httpHeader), $statusCode, $httpHeader); - return array(null, $statusCode, $httpHeader); - } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -570,7 +568,7 @@ class PetApi * @param string $pet_id ID of pet that needs to be updated (required) * @param string $name Updated name of the pet (optional) * @param string $status Updated status of the pet (optional) - * @return void + * @return Array of null, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ public function updatePetWithFormWithHttpInfo ($pet_id, $name=null, $status=null) @@ -641,6 +639,8 @@ class PetApi $headerParams ); + return array(null, $statusCode, $httpHeader); + } catch (ApiException $e) { switch ($e->getCode()) { } @@ -673,7 +673,7 @@ class PetApi * * @param int $pet_id Pet id to delete (required) * @param string $api_key (optional) - * @return void + * @return Array of null, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ public function deletePetWithHttpInfo ($pet_id, $api_key=null) @@ -735,6 +735,8 @@ class PetApi $headerParams ); + return array(null, $statusCode, $httpHeader); + } catch (ApiException $e) { switch ($e->getCode()) { } @@ -769,7 +771,7 @@ class PetApi * @param int $pet_id ID of pet to update (required) * @param string $additional_metadata Additional data to pass to server (optional) * @param \SplFileObject $file file to upload (optional) - * @return void + * @return Array of null, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ public function uploadFileWithHttpInfo ($pet_id, $additional_metadata=null, $file=null) @@ -846,6 +848,8 @@ class PetApi $headerParams ); + return array(null, $statusCode, $httpHeader); + } 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 26b25027a1b..3d8d14139c0 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php @@ -111,7 +111,7 @@ class StoreApi * * Returns pet inventories by status * - * @return map[string,int] + * @return Array of map[string,int], HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ public function getInventoryWithHttpInfo () @@ -167,8 +167,6 @@ class StoreApi return array($this->apiClient->getSerializer()->deserialize($response, 'map[string,int]', $httpHeader), $statusCode, $httpHeader); - return array(null, $statusCode, $httpHeader); - } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -203,7 +201,7 @@ class StoreApi * Place an order for a pet * * @param \Swagger\Client\Model\Order $body order placed for purchasing the pet (optional) - * @return \Swagger\Client\Model\Order + * @return Array of \Swagger\Client\Model\Order, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ public function placeOrderWithHttpInfo ($body=null) @@ -256,8 +254,6 @@ class StoreApi return array($this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Order', $httpHeader), $statusCode, $httpHeader); - return array(null, $statusCode, $httpHeader); - } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -292,7 +288,7 @@ 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 + * @return Array of \Swagger\Client\Model\Order, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ public function getOrderByIdWithHttpInfo ($order_id) @@ -352,8 +348,6 @@ class StoreApi return array($this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Order', $httpHeader), $statusCode, $httpHeader); - return array(null, $statusCode, $httpHeader); - } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -388,7 +382,7 @@ class StoreApi * Delete purchase order by ID * * @param string $order_id ID of the order that needs to be deleted (required) - * @return void + * @return Array of null, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ public function deleteOrderWithHttpInfo ($order_id) @@ -442,6 +436,8 @@ class StoreApi $headerParams ); + return array(null, $statusCode, $httpHeader); + } 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 9e2f3aa9eab..588f2b0a2e1 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php @@ -113,7 +113,7 @@ class UserApi * Create user * * @param \Swagger\Client\Model\User $body Created user object (optional) - * @return void + * @return Array of null, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ public function createUserWithHttpInfo ($body=null) @@ -160,6 +160,8 @@ class UserApi $headerParams ); + return array(null, $statusCode, $httpHeader); + } catch (ApiException $e) { switch ($e->getCode()) { } @@ -190,7 +192,7 @@ class UserApi * Creates list of users with given input array * * @param \Swagger\Client\Model\User[] $body List of user object (optional) - * @return void + * @return Array of null, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ public function createUsersWithArrayInputWithHttpInfo ($body=null) @@ -237,6 +239,8 @@ class UserApi $headerParams ); + return array(null, $statusCode, $httpHeader); + } catch (ApiException $e) { switch ($e->getCode()) { } @@ -267,7 +271,7 @@ class UserApi * Creates list of users with given input array * * @param \Swagger\Client\Model\User[] $body List of user object (optional) - * @return void + * @return Array of null, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ public function createUsersWithListInputWithHttpInfo ($body=null) @@ -314,6 +318,8 @@ class UserApi $headerParams ); + return array(null, $statusCode, $httpHeader); + } catch (ApiException $e) { switch ($e->getCode()) { } @@ -346,7 +352,7 @@ class UserApi * * @param string $username The user name for login (optional) * @param string $password The password for login in clear text (optional) - * @return string + * @return Array of string, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ public function loginUserWithHttpInfo ($username=null, $password=null) @@ -401,8 +407,6 @@ class UserApi return array($this->apiClient->getSerializer()->deserialize($response, 'string', $httpHeader), $statusCode, $httpHeader); - return array(null, $statusCode, $httpHeader); - } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -435,7 +439,7 @@ class UserApi * * Logs out current logged in user session * - * @return void + * @return Array of null, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ public function logoutUserWithHttpInfo () @@ -478,6 +482,8 @@ class UserApi $headerParams ); + return array(null, $statusCode, $httpHeader); + } catch (ApiException $e) { switch ($e->getCode()) { } @@ -508,7 +514,7 @@ 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 + * @return Array of \Swagger\Client\Model\User, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ public function getUserByNameWithHttpInfo ($username) @@ -568,8 +574,6 @@ class UserApi return array($this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\User', $httpHeader), $statusCode, $httpHeader); - return array(null, $statusCode, $httpHeader); - } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -606,7 +610,7 @@ class UserApi * * @param string $username name that need to be deleted (required) * @param \Swagger\Client\Model\User $body Updated user object (optional) - * @return void + * @return Array of null, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ public function updateUserWithHttpInfo ($username, $body=null) @@ -664,6 +668,8 @@ class UserApi $headerParams ); + return array(null, $statusCode, $httpHeader); + } catch (ApiException $e) { switch ($e->getCode()) { } @@ -694,7 +700,7 @@ class UserApi * Delete user * * @param string $username The name that needs to be deleted (required) - * @return void + * @return Array of null, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ public function deleteUserWithHttpInfo ($username) @@ -748,6 +754,8 @@ class UserApi $headerParams ); + return array(null, $statusCode, $httpHeader); + } catch (ApiException $e) { switch ($e->getCode()) { } diff --git a/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php b/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php index c30c95eaa69..c81b07b38fd 100644 --- a/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php @@ -168,7 +168,26 @@ class PetApiTest extends \PHPUnit_Framework_TestCase $this->assertSame($response->getName(), 'updatePet'); } - // test updatePet and verify by the "id" of the response + // test updatePetWithFormWithHttpInfo and verify by the "name" of the response + public function testUpdatePetWithFormWithHttpInfo() + { + // initialize the API client + $config = (new Swagger\Client\Configuration())->setHost('http://petstore.swagger.io/v2'); + $api_client = new Swagger\Client\ApiClient($config); + $pet_id = 10001; // ID of pet that needs to be fetched + $pet_api = new Swagger\Client\Api\PetAPI($api_client); + // update Pet (form) + list($update_response, $status_code, $http_headers) = $pet_api->updatePetWithFormWithHttpInfo($pet_id, 'update pet with form with http info'); + // return nothing (void) + $this->assertNull($update_response); + $this->assertSame($status_code, 200); + $this->assertSame($http_headers['Content-Type'], 'application/json'); + $response = $pet_api->getPetById($pet_id); + $this->assertSame($response->getId(), $pet_id); + $this->assertSame($response->getName(), 'update pet with form with http info'); + } + + // test updatePetWithForm and verify by the "name" and "status" of the response public function testUpdatePetWithForm() { // initialize the API client From 17b14fa281aa73677ef2dc632332f12b57fda651 Mon Sep 17 00:00:00 2001 From: wing328 Date: Mon, 7 Dec 2015 00:37:22 +0800 Subject: [PATCH 4/6] update php sample --- .../php/SwaggerClient-php/lib/Api/PetApi.php | 16 ++++++++-------- .../php/SwaggerClient-php/lib/Api/StoreApi.php | 8 ++++---- .../php/SwaggerClient-php/lib/Api/UserApi.php | 16 ++++++++-------- 3 files changed, 20 insertions(+), 20 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 792053877a4..c5ac2e17eb9 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php @@ -108,7 +108,7 @@ class PetApi /** - * updatePet + * updatePetWithHttpInfo * * Update an existing pet * @@ -192,7 +192,7 @@ class PetApi /** - * addPet + * addPetWithHttpInfo * * Add a new pet to the store * @@ -276,7 +276,7 @@ class PetApi /** - * findPetsByStatus + * findPetsByStatusWithHttpInfo * * Finds Pets by status * @@ -367,7 +367,7 @@ class PetApi /** - * findPetsByTags + * findPetsByTagsWithHttpInfo * * Finds Pets by tags * @@ -458,7 +458,7 @@ class PetApi /** - * getPetById + * getPetByIdWithHttpInfo * * Find pet by ID * @@ -561,7 +561,7 @@ class PetApi /** - * updatePetWithForm + * updatePetWithFormWithHttpInfo * * Updates a pet in the store with form data * @@ -667,7 +667,7 @@ class PetApi /** - * deletePet + * deletePetWithHttpInfo * * Deletes a pet * @@ -764,7 +764,7 @@ class PetApi /** - * uploadFile + * uploadFileWithHttpInfo * * uploads an image * 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 3d8d14139c0..3deab979d41 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php @@ -107,7 +107,7 @@ class StoreApi /** - * getInventory + * getInventoryWithHttpInfo * * Returns pet inventories by status * @@ -196,7 +196,7 @@ class StoreApi /** - * placeOrder + * placeOrderWithHttpInfo * * Place an order for a pet * @@ -283,7 +283,7 @@ class StoreApi /** - * getOrderById + * getOrderByIdWithHttpInfo * * Find purchase order by ID * @@ -377,7 +377,7 @@ class StoreApi /** - * deleteOrder + * deleteOrderWithHttpInfo * * Delete purchase order by ID * 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 588f2b0a2e1..98a26537f2a 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php @@ -108,7 +108,7 @@ class UserApi /** - * createUser + * createUserWithHttpInfo * * Create user * @@ -187,7 +187,7 @@ class UserApi /** - * createUsersWithArrayInput + * createUsersWithArrayInputWithHttpInfo * * Creates list of users with given input array * @@ -266,7 +266,7 @@ class UserApi /** - * createUsersWithListInput + * createUsersWithListInputWithHttpInfo * * Creates list of users with given input array * @@ -346,7 +346,7 @@ class UserApi /** - * loginUser + * loginUserWithHttpInfo * * Logs user into the system * @@ -435,7 +435,7 @@ class UserApi /** - * logoutUser + * logoutUserWithHttpInfo * * Logs out current logged in user session * @@ -509,7 +509,7 @@ class UserApi /** - * getUserByName + * getUserByNameWithHttpInfo * * Get user by user name * @@ -604,7 +604,7 @@ class UserApi /** - * updateUser + * updateUserWithHttpInfo * * Updated user * @@ -695,7 +695,7 @@ class UserApi /** - * deleteUser + * deleteUserWithHttpInfo * * Delete user * From 442f87c19a08b5c797ca60796d54fa3a2437fa18 Mon Sep 17 00:00:00 2001 From: wing328 Date: Mon, 7 Dec 2015 00:42:25 +0800 Subject: [PATCH 5/6] minor style change for php functions --- .../src/main/resources/php/api.mustache | 4 +-- .../php/SwaggerClient-php/lib/Api/PetApi.php | 32 +++++++++---------- .../SwaggerClient-php/lib/Api/StoreApi.php | 16 +++++----- .../php/SwaggerClient-php/lib/Api/UserApi.php | 32 +++++++++---------- 4 files changed, 42 insertions(+), 42 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index 0b28b2b4ca6..53a476b4061 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -100,7 +100,7 @@ use \{{invokerPackage}}\ObjectSerializer; {{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} * @throws \{{invokerPackage}}\ApiException on non-2xx response */ - public function {{operationId}} ({{#allParams}}${{paramName}}{{^required}}=null{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) + public function {{operationId}}({{#allParams}}${{paramName}}{{^required}}=null{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { list($response, $statusCode, $httpHeader) = $this->{{operationId}}WithHttpInfo ({{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); return $response; @@ -116,7 +116,7 @@ use \{{invokerPackage}}\ObjectSerializer; {{/allParams}} * @return Array of {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}null{{/returnType}}, HTTP status code, HTTP response headers (array of strings) * @throws \{{invokerPackage}}\ApiException on non-2xx response */ - public function {{operationId}}WithHttpInfo ({{#allParams}}${{paramName}}{{^required}}=null{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) + public function {{operationId}}WithHttpInfo({{#allParams}}${{paramName}}{{^required}}=null{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { {{#allParams}}{{#required}} // verify the required parameter '{{paramName}}' is set 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 c5ac2e17eb9..ed73dd64dc8 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php @@ -100,7 +100,7 @@ class PetApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function updatePet ($body=null) + public function updatePet($body=null) { list($response, $statusCode, $httpHeader) = $this->updatePetWithHttpInfo ($body); return $response; @@ -116,7 +116,7 @@ class PetApi * @return Array of null, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ - public function updatePetWithHttpInfo ($body=null) + public function updatePetWithHttpInfo($body=null) { @@ -184,7 +184,7 @@ class PetApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function addPet ($body=null) + public function addPet($body=null) { list($response, $statusCode, $httpHeader) = $this->addPetWithHttpInfo ($body); return $response; @@ -200,7 +200,7 @@ class PetApi * @return Array of null, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ - public function addPetWithHttpInfo ($body=null) + public function addPetWithHttpInfo($body=null) { @@ -268,7 +268,7 @@ class PetApi * @return \Swagger\Client\Model\Pet[] * @throws \Swagger\Client\ApiException on non-2xx response */ - public function findPetsByStatus ($status=null) + public function findPetsByStatus($status=null) { list($response, $statusCode, $httpHeader) = $this->findPetsByStatusWithHttpInfo ($status); return $response; @@ -284,7 +284,7 @@ class PetApi * @return Array of \Swagger\Client\Model\Pet[], HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ - public function findPetsByStatusWithHttpInfo ($status=null) + public function findPetsByStatusWithHttpInfo($status=null) { @@ -359,7 +359,7 @@ class PetApi * @return \Swagger\Client\Model\Pet[] * @throws \Swagger\Client\ApiException on non-2xx response */ - public function findPetsByTags ($tags=null) + public function findPetsByTags($tags=null) { list($response, $statusCode, $httpHeader) = $this->findPetsByTagsWithHttpInfo ($tags); return $response; @@ -375,7 +375,7 @@ class PetApi * @return Array of \Swagger\Client\Model\Pet[], HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ - public function findPetsByTagsWithHttpInfo ($tags=null) + public function findPetsByTagsWithHttpInfo($tags=null) { @@ -450,7 +450,7 @@ class PetApi * @return \Swagger\Client\Model\Pet * @throws \Swagger\Client\ApiException on non-2xx response */ - public function getPetById ($pet_id) + public function getPetById($pet_id) { list($response, $statusCode, $httpHeader) = $this->getPetByIdWithHttpInfo ($pet_id); return $response; @@ -466,7 +466,7 @@ class PetApi * @return Array of \Swagger\Client\Model\Pet, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ - public function getPetByIdWithHttpInfo ($pet_id) + public function getPetByIdWithHttpInfo($pet_id) { // verify the required parameter 'pet_id' is set @@ -553,7 +553,7 @@ class PetApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function updatePetWithForm ($pet_id, $name=null, $status=null) + public function updatePetWithForm($pet_id, $name=null, $status=null) { list($response, $statusCode, $httpHeader) = $this->updatePetWithFormWithHttpInfo ($pet_id, $name, $status); return $response; @@ -571,7 +571,7 @@ class PetApi * @return Array of null, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ - public function updatePetWithFormWithHttpInfo ($pet_id, $name=null, $status=null) + public function updatePetWithFormWithHttpInfo($pet_id, $name=null, $status=null) { // verify the required parameter 'pet_id' is set @@ -659,7 +659,7 @@ class PetApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function deletePet ($pet_id, $api_key=null) + public function deletePet($pet_id, $api_key=null) { list($response, $statusCode, $httpHeader) = $this->deletePetWithHttpInfo ($pet_id, $api_key); return $response; @@ -676,7 +676,7 @@ class PetApi * @return Array of null, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ - public function deletePetWithHttpInfo ($pet_id, $api_key=null) + public function deletePetWithHttpInfo($pet_id, $api_key=null) { // verify the required parameter 'pet_id' is set @@ -756,7 +756,7 @@ class PetApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function uploadFile ($pet_id, $additional_metadata=null, $file=null) + public function uploadFile($pet_id, $additional_metadata=null, $file=null) { list($response, $statusCode, $httpHeader) = $this->uploadFileWithHttpInfo ($pet_id, $additional_metadata, $file); return $response; @@ -774,7 +774,7 @@ class PetApi * @return Array of null, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ - public function uploadFileWithHttpInfo ($pet_id, $additional_metadata=null, $file=null) + public function uploadFileWithHttpInfo($pet_id, $additional_metadata=null, $file=null) { // verify the required parameter 'pet_id' is set 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 3deab979d41..34490783ffb 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php @@ -99,7 +99,7 @@ class StoreApi * @return map[string,int] * @throws \Swagger\Client\ApiException on non-2xx response */ - public function getInventory () + public function getInventory() { list($response, $statusCode, $httpHeader) = $this->getInventoryWithHttpInfo (); return $response; @@ -114,7 +114,7 @@ class StoreApi * @return Array of map[string,int], HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ - public function getInventoryWithHttpInfo () + public function getInventoryWithHttpInfo() { @@ -188,7 +188,7 @@ class StoreApi * @return \Swagger\Client\Model\Order * @throws \Swagger\Client\ApiException on non-2xx response */ - public function placeOrder ($body=null) + public function placeOrder($body=null) { list($response, $statusCode, $httpHeader) = $this->placeOrderWithHttpInfo ($body); return $response; @@ -204,7 +204,7 @@ class StoreApi * @return Array of \Swagger\Client\Model\Order, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ - public function placeOrderWithHttpInfo ($body=null) + public function placeOrderWithHttpInfo($body=null) { @@ -275,7 +275,7 @@ class StoreApi * @return \Swagger\Client\Model\Order * @throws \Swagger\Client\ApiException on non-2xx response */ - public function getOrderById ($order_id) + public function getOrderById($order_id) { list($response, $statusCode, $httpHeader) = $this->getOrderByIdWithHttpInfo ($order_id); return $response; @@ -291,7 +291,7 @@ class StoreApi * @return Array of \Swagger\Client\Model\Order, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ - public function getOrderByIdWithHttpInfo ($order_id) + public function getOrderByIdWithHttpInfo($order_id) { // verify the required parameter 'order_id' is set @@ -369,7 +369,7 @@ class StoreApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function deleteOrder ($order_id) + public function deleteOrder($order_id) { list($response, $statusCode, $httpHeader) = $this->deleteOrderWithHttpInfo ($order_id); return $response; @@ -385,7 +385,7 @@ class StoreApi * @return Array of null, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ - public function deleteOrderWithHttpInfo ($order_id) + public function deleteOrderWithHttpInfo($order_id) { // verify the required parameter 'order_id' is set 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 98a26537f2a..2a19c2f7798 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php @@ -100,7 +100,7 @@ class UserApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function createUser ($body=null) + public function createUser($body=null) { list($response, $statusCode, $httpHeader) = $this->createUserWithHttpInfo ($body); return $response; @@ -116,7 +116,7 @@ class UserApi * @return Array of null, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ - public function createUserWithHttpInfo ($body=null) + public function createUserWithHttpInfo($body=null) { @@ -179,7 +179,7 @@ class UserApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function createUsersWithArrayInput ($body=null) + public function createUsersWithArrayInput($body=null) { list($response, $statusCode, $httpHeader) = $this->createUsersWithArrayInputWithHttpInfo ($body); return $response; @@ -195,7 +195,7 @@ class UserApi * @return Array of null, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ - public function createUsersWithArrayInputWithHttpInfo ($body=null) + public function createUsersWithArrayInputWithHttpInfo($body=null) { @@ -258,7 +258,7 @@ class UserApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function createUsersWithListInput ($body=null) + public function createUsersWithListInput($body=null) { list($response, $statusCode, $httpHeader) = $this->createUsersWithListInputWithHttpInfo ($body); return $response; @@ -274,7 +274,7 @@ class UserApi * @return Array of null, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ - public function createUsersWithListInputWithHttpInfo ($body=null) + public function createUsersWithListInputWithHttpInfo($body=null) { @@ -338,7 +338,7 @@ class UserApi * @return string * @throws \Swagger\Client\ApiException on non-2xx response */ - public function loginUser ($username=null, $password=null) + public function loginUser($username=null, $password=null) { list($response, $statusCode, $httpHeader) = $this->loginUserWithHttpInfo ($username, $password); return $response; @@ -355,7 +355,7 @@ class UserApi * @return Array of string, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ - public function loginUserWithHttpInfo ($username=null, $password=null) + public function loginUserWithHttpInfo($username=null, $password=null) { @@ -427,7 +427,7 @@ class UserApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function logoutUser () + public function logoutUser() { list($response, $statusCode, $httpHeader) = $this->logoutUserWithHttpInfo (); return $response; @@ -442,7 +442,7 @@ class UserApi * @return Array of null, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ - public function logoutUserWithHttpInfo () + public function logoutUserWithHttpInfo() { @@ -501,7 +501,7 @@ class UserApi * @return \Swagger\Client\Model\User * @throws \Swagger\Client\ApiException on non-2xx response */ - public function getUserByName ($username) + public function getUserByName($username) { list($response, $statusCode, $httpHeader) = $this->getUserByNameWithHttpInfo ($username); return $response; @@ -517,7 +517,7 @@ class UserApi * @return Array of \Swagger\Client\Model\User, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ - public function getUserByNameWithHttpInfo ($username) + public function getUserByNameWithHttpInfo($username) { // verify the required parameter 'username' is set @@ -596,7 +596,7 @@ class UserApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function updateUser ($username, $body=null) + public function updateUser($username, $body=null) { list($response, $statusCode, $httpHeader) = $this->updateUserWithHttpInfo ($username, $body); return $response; @@ -613,7 +613,7 @@ class UserApi * @return Array of null, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ - public function updateUserWithHttpInfo ($username, $body=null) + public function updateUserWithHttpInfo($username, $body=null) { // verify the required parameter 'username' is set @@ -687,7 +687,7 @@ class UserApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function deleteUser ($username) + public function deleteUser($username) { list($response, $statusCode, $httpHeader) = $this->deleteUserWithHttpInfo ($username); return $response; @@ -703,7 +703,7 @@ class UserApi * @return Array of null, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ - public function deleteUserWithHttpInfo ($username) + public function deleteUserWithHttpInfo($username) { // verify the required parameter 'username' is set From 340e60002e023e9ade296b1015345cf6544d12da Mon Sep 17 00:00:00 2001 From: wing328 Date: Mon, 7 Dec 2015 00:52:30 +0800 Subject: [PATCH 6/6] more style change for php client --- .../src/main/resources/php/ApiClient.mustache | 20 +++--- .../resources/php/ObjectSerializer.mustache | 6 +- .../src/main/resources/php/api.mustache | 9 ++- .../php/SwaggerClient-php/lib/Api/PetApi.php | 68 ++++++++----------- .../SwaggerClient-php/lib/Api/StoreApi.php | 24 +++---- .../php/SwaggerClient-php/lib/Api/UserApi.php | 60 +++++++--------- .../php/SwaggerClient-php/lib/ApiClient.php | 20 +++--- .../lib/ObjectSerializer.php | 6 +- 8 files changed, 96 insertions(+), 117 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache index 86998fd16d0..be18e221972 100644 --- a/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache @@ -131,7 +131,7 @@ class ApiClient * @throws \{{invokerPackage}}\ApiException on a non 2xx response * @return mixed */ - public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams, $responseType=null) + public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams, $responseType = null) { $headers = array(); @@ -149,7 +149,7 @@ class ApiClient // form data if ($postData and in_array('Content-Type: application/x-www-form-urlencoded', $headers)) { $postData = http_build_query($postData); - } else if ((is_object($postData) or is_array($postData)) and !in_array('Content-Type: multipart/form-data', $headers)) { // json model + } elseif ((is_object($postData) or is_array($postData)) and !in_array('Content-Type: multipart/form-data', $headers)) { // json model $postData = json_encode($this->serializer->sanitizeForSerialization($postData)); } @@ -160,7 +160,7 @@ class ApiClient if ($this->config->getCurlTimeout() != 0) { curl_setopt($curl, CURLOPT_TIMEOUT, $this->config->getCurlTimeout()); } - // return the result on success, rather than just TRUE + // return the result on success, rather than just true curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); @@ -178,21 +178,21 @@ class ApiClient if ($method == self::$POST) { curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method == self::$HEAD) { + } elseif ($method == self::$HEAD) { curl_setopt($curl, CURLOPT_NOBODY, true); - } else if ($method == self::$OPTIONS) { + } elseif ($method == self::$OPTIONS) { curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "OPTIONS"); curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method == self::$PATCH) { + } elseif ($method == self::$PATCH) { curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH"); curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method == self::$PUT) { + } elseif ($method == self::$PUT) { curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method == self::$DELETE) { + } elseif ($method == self::$DELETE) { curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method != self::$GET) { + } elseif ($method != self::$GET) { throw new ApiException('Method ' . $method . ' is not recognized.'); } curl_setopt($curl, CURLOPT_URL, $url); @@ -228,7 +228,7 @@ class ApiClient // Handle the response if ($response_info['http_code'] == 0) { throw new ApiException("API call to $url timed out: ".serialize($response_info), 0, null, null); - } else if ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) { + } elseif ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) { // return raw body if response is a file if ($responseType == '\SplFileObject') { return array($http_body, $response_info['http_code'], $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 54fb66a9543..133c1b1f454 100644 --- a/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache +++ b/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache @@ -56,14 +56,14 @@ class ObjectSerializer { if (is_scalar($data) || null === $data) { $sanitized = $data; - } else if ($data instanceof \DateTime) { + } elseif ($data instanceof \DateTime) { $sanitized = $data->format(\DateTime::ISO8601); - } else if (is_array($data)) { + } elseif (is_array($data)) { foreach ($data as $property => $value) { $data[$property] = $this->sanitizeForSerialization($value); } $sanitized = $data; - } else if (is_object($data)) { + } elseif (is_object($data)) { $values = array(); foreach (array_keys($data::$swaggerTypes) as $property) { $getter = $data::$getters[$property]; diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index 53a476b4061..22ae27fc77d 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -100,7 +100,7 @@ use \{{invokerPackage}}\ObjectSerializer; {{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}} * @throws \{{invokerPackage}}\ApiException on non-2xx response */ - public function {{operationId}}({{#allParams}}${{paramName}}{{^required}}=null{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) + public function {{operationId}}({{#allParams}}${{paramName}}{{^required}} = null{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { list($response, $statusCode, $httpHeader) = $this->{{operationId}}WithHttpInfo ({{#allParams}}${{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); return $response; @@ -116,7 +116,7 @@ use \{{invokerPackage}}\ObjectSerializer; {{/allParams}} * @return Array of {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}null{{/returnType}}, HTTP status code, HTTP response headers (array of strings) * @throws \{{invokerPackage}}\ApiException on non-2xx response */ - public function {{operationId}}WithHttpInfo({{#allParams}}${{paramName}}{{^required}}=null{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) + public function {{operationId}}WithHttpInfo({{#allParams}}${{paramName}}{{^required}} = null{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { {{#allParams}}{{#required}} // verify the required parameter '{{paramName}}' is set @@ -178,7 +178,7 @@ use \{{invokerPackage}}\ObjectSerializer; // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } {{#authMethods}}{{#isApiKey}} @@ -196,8 +196,7 @@ use \{{invokerPackage}}\ObjectSerializer; }{{/isOAuth}} {{/authMethods}} // make the API Call - try - { + try { list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, 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 ed73dd64dc8..18aeba64072 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php @@ -100,7 +100,7 @@ class PetApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function updatePet($body=null) + public function updatePet($body = null) { list($response, $statusCode, $httpHeader) = $this->updatePetWithHttpInfo ($body); return $response; @@ -116,7 +116,7 @@ class PetApi * @return Array of null, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ - public function updatePetWithHttpInfo($body=null) + public function updatePetWithHttpInfo($body = null) { @@ -147,7 +147,7 @@ class PetApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } @@ -157,8 +157,7 @@ class PetApi } // make the API Call - try - { + try { list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, @@ -184,7 +183,7 @@ class PetApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function addPet($body=null) + public function addPet($body = null) { list($response, $statusCode, $httpHeader) = $this->addPetWithHttpInfo ($body); return $response; @@ -200,7 +199,7 @@ class PetApi * @return Array of null, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ - public function addPetWithHttpInfo($body=null) + public function addPetWithHttpInfo($body = null) { @@ -231,7 +230,7 @@ class PetApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } @@ -241,8 +240,7 @@ class PetApi } // make the API Call - try - { + try { list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, @@ -268,7 +266,7 @@ class PetApi * @return \Swagger\Client\Model\Pet[] * @throws \Swagger\Client\ApiException on non-2xx response */ - public function findPetsByStatus($status=null) + public function findPetsByStatus($status = null) { list($response, $statusCode, $httpHeader) = $this->findPetsByStatusWithHttpInfo ($status); return $response; @@ -284,7 +282,7 @@ class PetApi * @return Array of \Swagger\Client\Model\Pet[], HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ - public function findPetsByStatusWithHttpInfo($status=null) + public function findPetsByStatusWithHttpInfo($status = null) { @@ -314,7 +312,7 @@ class PetApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } @@ -324,8 +322,7 @@ class PetApi } // make the API Call - try - { + try { list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, @@ -359,7 +356,7 @@ class PetApi * @return \Swagger\Client\Model\Pet[] * @throws \Swagger\Client\ApiException on non-2xx response */ - public function findPetsByTags($tags=null) + public function findPetsByTags($tags = null) { list($response, $statusCode, $httpHeader) = $this->findPetsByTagsWithHttpInfo ($tags); return $response; @@ -375,7 +372,7 @@ class PetApi * @return Array of \Swagger\Client\Model\Pet[], HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ - public function findPetsByTagsWithHttpInfo($tags=null) + public function findPetsByTagsWithHttpInfo($tags = null) { @@ -405,7 +402,7 @@ class PetApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } @@ -415,8 +412,7 @@ class PetApi } // make the API Call - try - { + try { list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, @@ -504,7 +500,7 @@ class PetApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } @@ -516,8 +512,7 @@ class PetApi // make the API Call - try - { + try { list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, @@ -553,7 +548,7 @@ class PetApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function updatePetWithForm($pet_id, $name=null, $status=null) + public function updatePetWithForm($pet_id, $name = null, $status = null) { list($response, $statusCode, $httpHeader) = $this->updatePetWithFormWithHttpInfo ($pet_id, $name, $status); return $response; @@ -571,7 +566,7 @@ class PetApi * @return Array of null, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ - public function updatePetWithFormWithHttpInfo($pet_id, $name=null, $status=null) + public function updatePetWithFormWithHttpInfo($pet_id, $name = null, $status = null) { // verify the required parameter 'pet_id' is set @@ -621,7 +616,7 @@ class PetApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } @@ -631,8 +626,7 @@ class PetApi } // make the API Call - try - { + try { list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, @@ -659,7 +653,7 @@ class PetApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function deletePet($pet_id, $api_key=null) + public function deletePet($pet_id, $api_key = null) { list($response, $statusCode, $httpHeader) = $this->deletePetWithHttpInfo ($pet_id, $api_key); return $response; @@ -676,7 +670,7 @@ class PetApi * @return Array of null, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ - public function deletePetWithHttpInfo($pet_id, $api_key=null) + public function deletePetWithHttpInfo($pet_id, $api_key = null) { // verify the required parameter 'pet_id' is set @@ -717,7 +711,7 @@ class PetApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } @@ -727,8 +721,7 @@ class PetApi } // make the API Call - try - { + try { list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, @@ -756,7 +749,7 @@ class PetApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function uploadFile($pet_id, $additional_metadata=null, $file=null) + public function uploadFile($pet_id, $additional_metadata = null, $file = null) { list($response, $statusCode, $httpHeader) = $this->uploadFileWithHttpInfo ($pet_id, $additional_metadata, $file); return $response; @@ -774,7 +767,7 @@ class PetApi * @return Array of null, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ - public function uploadFileWithHttpInfo($pet_id, $additional_metadata=null, $file=null) + public function uploadFileWithHttpInfo($pet_id, $additional_metadata = null, $file = null) { // verify the required parameter 'pet_id' is set @@ -830,7 +823,7 @@ class PetApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } @@ -840,8 +833,7 @@ class PetApi } // make the API Call - try - { + try { list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, 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 34490783ffb..4539aeeeab4 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php @@ -141,7 +141,7 @@ class StoreApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } @@ -153,8 +153,7 @@ class StoreApi // make the API Call - try - { + try { list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, @@ -188,7 +187,7 @@ class StoreApi * @return \Swagger\Client\Model\Order * @throws \Swagger\Client\ApiException on non-2xx response */ - public function placeOrder($body=null) + public function placeOrder($body = null) { list($response, $statusCode, $httpHeader) = $this->placeOrderWithHttpInfo ($body); return $response; @@ -204,7 +203,7 @@ class StoreApi * @return Array of \Swagger\Client\Model\Order, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ - public function placeOrderWithHttpInfo($body=null) + public function placeOrderWithHttpInfo($body = null) { @@ -235,13 +234,12 @@ class StoreApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } // make the API Call - try - { + try { list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, @@ -329,13 +327,12 @@ class StoreApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } // make the API Call - try - { + try { list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, @@ -423,13 +420,12 @@ class StoreApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } // make the API Call - try - { + try { list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, 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 2a19c2f7798..f200ff51d2a 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php @@ -100,7 +100,7 @@ class UserApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function createUser($body=null) + public function createUser($body = null) { list($response, $statusCode, $httpHeader) = $this->createUserWithHttpInfo ($body); return $response; @@ -116,7 +116,7 @@ class UserApi * @return Array of null, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ - public function createUserWithHttpInfo($body=null) + public function createUserWithHttpInfo($body = null) { @@ -147,13 +147,12 @@ class UserApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } // make the API Call - try - { + try { list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, @@ -179,7 +178,7 @@ class UserApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function createUsersWithArrayInput($body=null) + public function createUsersWithArrayInput($body = null) { list($response, $statusCode, $httpHeader) = $this->createUsersWithArrayInputWithHttpInfo ($body); return $response; @@ -195,7 +194,7 @@ class UserApi * @return Array of null, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ - public function createUsersWithArrayInputWithHttpInfo($body=null) + public function createUsersWithArrayInputWithHttpInfo($body = null) { @@ -226,13 +225,12 @@ class UserApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } // make the API Call - try - { + try { list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, @@ -258,7 +256,7 @@ class UserApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function createUsersWithListInput($body=null) + public function createUsersWithListInput($body = null) { list($response, $statusCode, $httpHeader) = $this->createUsersWithListInputWithHttpInfo ($body); return $response; @@ -274,7 +272,7 @@ class UserApi * @return Array of null, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ - public function createUsersWithListInputWithHttpInfo($body=null) + public function createUsersWithListInputWithHttpInfo($body = null) { @@ -305,13 +303,12 @@ class UserApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } // make the API Call - try - { + try { list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, @@ -338,7 +335,7 @@ class UserApi * @return string * @throws \Swagger\Client\ApiException on non-2xx response */ - public function loginUser($username=null, $password=null) + public function loginUser($username = null, $password = null) { list($response, $statusCode, $httpHeader) = $this->loginUserWithHttpInfo ($username, $password); return $response; @@ -355,7 +352,7 @@ class UserApi * @return Array of string, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ - public function loginUserWithHttpInfo($username=null, $password=null) + public function loginUserWithHttpInfo($username = null, $password = null) { @@ -388,13 +385,12 @@ class UserApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } // make the API Call - try - { + try { list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, @@ -469,13 +465,12 @@ class UserApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } // make the API Call - try - { + try { list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, @@ -555,13 +550,12 @@ class UserApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } // make the API Call - try - { + try { list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, @@ -596,7 +590,7 @@ class UserApi * @return void * @throws \Swagger\Client\ApiException on non-2xx response */ - public function updateUser($username, $body=null) + public function updateUser($username, $body = null) { list($response, $statusCode, $httpHeader) = $this->updateUserWithHttpInfo ($username, $body); return $response; @@ -613,7 +607,7 @@ class UserApi * @return Array of null, HTTP status code, HTTP response headers (array of strings) * @throws \Swagger\Client\ApiException on non-2xx response */ - public function updateUserWithHttpInfo($username, $body=null) + public function updateUserWithHttpInfo($username, $body = null) { // verify the required parameter 'username' is set @@ -655,13 +649,12 @@ class UserApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } // make the API Call - try - { + try { list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, @@ -741,13 +734,12 @@ class UserApi // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present - } else if (count($formParams) > 0) { + } elseif (count($formParams) > 0) { $httpBody = $formParams; // for HTTP post (form) } // make the API Call - try - { + try { list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( $resourcePath, $method, $queryParams, $httpBody, diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php b/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php index 2f3aacd1ffd..8730a8c0601 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php @@ -131,7 +131,7 @@ class ApiClient * @throws \Swagger\Client\ApiException on a non 2xx response * @return mixed */ - public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams, $responseType=null) + public function callApi($resourcePath, $method, $queryParams, $postData, $headerParams, $responseType = null) { $headers = array(); @@ -149,7 +149,7 @@ class ApiClient // form data if ($postData and in_array('Content-Type: application/x-www-form-urlencoded', $headers)) { $postData = http_build_query($postData); - } else if ((is_object($postData) or is_array($postData)) and !in_array('Content-Type: multipart/form-data', $headers)) { // json model + } elseif ((is_object($postData) or is_array($postData)) and !in_array('Content-Type: multipart/form-data', $headers)) { // json model $postData = json_encode($this->serializer->sanitizeForSerialization($postData)); } @@ -160,7 +160,7 @@ class ApiClient if ($this->config->getCurlTimeout() != 0) { curl_setopt($curl, CURLOPT_TIMEOUT, $this->config->getCurlTimeout()); } - // return the result on success, rather than just TRUE + // return the result on success, rather than just true curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); @@ -178,21 +178,21 @@ class ApiClient if ($method == self::$POST) { curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method == self::$HEAD) { + } elseif ($method == self::$HEAD) { curl_setopt($curl, CURLOPT_NOBODY, true); - } else if ($method == self::$OPTIONS) { + } elseif ($method == self::$OPTIONS) { curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "OPTIONS"); curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method == self::$PATCH) { + } elseif ($method == self::$PATCH) { curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH"); curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method == self::$PUT) { + } elseif ($method == self::$PUT) { curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method == self::$DELETE) { + } elseif ($method == self::$DELETE) { curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method != self::$GET) { + } elseif ($method != self::$GET) { throw new ApiException('Method ' . $method . ' is not recognized.'); } curl_setopt($curl, CURLOPT_URL, $url); @@ -228,7 +228,7 @@ class ApiClient // Handle the response if ($response_info['http_code'] == 0) { throw new ApiException("API call to $url timed out: ".serialize($response_info), 0, null, null); - } else if ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) { + } elseif ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) { // return raw body if response is a file if ($responseType == '\SplFileObject') { return array($http_body, $response_info['http_code'], $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 22d03030fb3..cc023b61bd2 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php @@ -56,14 +56,14 @@ class ObjectSerializer { if (is_scalar($data) || null === $data) { $sanitized = $data; - } else if ($data instanceof \DateTime) { + } elseif ($data instanceof \DateTime) { $sanitized = $data->format(\DateTime::ISO8601); - } else if (is_array($data)) { + } elseif (is_array($data)) { foreach ($data as $property => $value) { $data[$property] = $this->sanitizeForSerialization($value); } $sanitized = $data; - } else if (is_object($data)) { + } elseif (is_object($data)) { $values = array(); foreach (array_keys($data::$swaggerTypes) as $property) { $getter = $data::$getters[$property];