From 3bd4502bbf1cf3a4feb9e378ae0d4b4f421e4a28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arne=20J=C3=B8rgensen?= Date: Thu, 8 Oct 2015 11:25:43 +0200 Subject: [PATCH] Deserialize httpHeader. See #1354. Regenerated php-petstore sample. --- .../src/main/resources/php/api.mustache | 13 +++-- .../php/SwaggerClient-php/lib/Api/PetApi.php | 50 ++++++++++++------- .../SwaggerClient-php/lib/Api/StoreApi.php | 40 +++++++++------ .../php/SwaggerClient-php/lib/Api/UserApi.php | 32 ++++++++---- .../lib/ObjectSerializer.php | 2 +- 5 files changed, 88 insertions(+), 49 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index bb40ae7a98..4f0184310b 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -170,6 +170,13 @@ use \{{invokerPackage}}\ObjectSerializer; $queryParams, $httpBody, $headerParams{{#returnType}}, '{{returnType}}'{{/returnType}} ); + {{#returnType}} + if (!$response) { + return null; + } + + return $this->apiClient->getSerializer()->deserialize($response, '{{returnType}}', $httpHeader); + {{/returnType}} } catch (ApiException $e) { switch ($e->getCode()) { {{#responses}}{{#dataType}} case {{code}}: @@ -181,11 +188,7 @@ use \{{invokerPackage}}\ObjectSerializer; throw $e; } {{#returnType}} - if (!$response) { - return null; - } - - return $this->apiClient->getSerializer()->deserialize($response, '{{returnType}}'); + return null; {{/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 8e75c360ae..45b2bbfe36 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php @@ -146,6 +146,7 @@ class PetApi $queryParams, $httpBody, $headerParams ); + } catch (ApiException $e) { switch ($e->getCode()) { } @@ -210,6 +211,7 @@ class PetApi $queryParams, $httpBody, $headerParams ); + } catch (ApiException $e) { switch ($e->getCode()) { } @@ -273,6 +275,13 @@ class PetApi $queryParams, $httpBody, $headerParams, '\Swagger\Client\Model\Pet[]' ); + + if (!$response) { + return null; + } + + return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Pet[]', $httpHeader); + } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -284,11 +293,7 @@ class PetApi throw $e; } - if (!$response) { - return null; - } - - return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Pet[]'); + return null; } @@ -346,6 +351,13 @@ class PetApi $queryParams, $httpBody, $headerParams, '\Swagger\Client\Model\Pet[]' ); + + if (!$response) { + return null; + } + + return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Pet[]', $httpHeader); + } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -357,11 +369,7 @@ class PetApi throw $e; } - if (!$response) { - return null; - } - - return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Pet[]'); + return null; } @@ -416,6 +424,9 @@ class PetApi $httpBody = $formParams; // for HTTP post (form) } + + //TODO support oauth + $apiKey = $this->apiClient->getApiKeyWithPrefix('api_key'); if (isset($apiKey)) { $headerParams['api_key'] = $apiKey; @@ -423,9 +434,6 @@ class PetApi - - //TODO support oauth - // make the API Call try { @@ -434,6 +442,13 @@ class PetApi $queryParams, $httpBody, $headerParams, '\Swagger\Client\Model\Pet' ); + + if (!$response) { + return null; + } + + return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Pet', $httpHeader); + } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -445,11 +460,7 @@ class PetApi throw $e; } - if (!$response) { - return null; - } - - return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Pet'); + return null; } @@ -523,6 +534,7 @@ class PetApi $queryParams, $httpBody, $headerParams ); + } catch (ApiException $e) { switch ($e->getCode()) { } @@ -598,6 +610,7 @@ class PetApi $queryParams, $httpBody, $headerParams ); + } catch (ApiException $e) { switch ($e->getCode()) { } @@ -677,6 +690,7 @@ class PetApi $queryParams, $httpBody, $headerParams ); + } catch (ApiException $e) { switch ($e->getCode()) { } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php index ede8a3c14d..bab53eaa4d 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php @@ -145,6 +145,13 @@ class StoreApi $queryParams, $httpBody, $headerParams, 'map[string,int]' ); + + if (!$response) { + return null; + } + + return $this->apiClient->getSerializer()->deserialize($response, 'map[string,int]', $httpHeader); + } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -156,11 +163,7 @@ class StoreApi throw $e; } - if (!$response) { - return null; - } - - return $this->apiClient->getSerializer()->deserialize($response, 'map[string,int]'); + return null; } @@ -216,6 +219,13 @@ class StoreApi $queryParams, $httpBody, $headerParams, '\Swagger\Client\Model\Order' ); + + if (!$response) { + return null; + } + + return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Order', $httpHeader); + } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -227,11 +237,7 @@ class StoreApi throw $e; } - if (!$response) { - return null; - } - - return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Order'); + return null; } @@ -294,6 +300,13 @@ class StoreApi $queryParams, $httpBody, $headerParams, '\Swagger\Client\Model\Order' ); + + if (!$response) { + return null; + } + + return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Order', $httpHeader); + } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -305,11 +318,7 @@ class StoreApi throw $e; } - if (!$response) { - return null; - } - - return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\Order'); + return null; } @@ -372,6 +381,7 @@ class StoreApi $queryParams, $httpBody, $headerParams ); + } catch (ApiException $e) { switch ($e->getCode()) { } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php index d23731e08f..66024f4db4 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php @@ -143,6 +143,7 @@ class UserApi $queryParams, $httpBody, $headerParams ); + } catch (ApiException $e) { switch ($e->getCode()) { } @@ -204,6 +205,7 @@ class UserApi $queryParams, $httpBody, $headerParams ); + } catch (ApiException $e) { switch ($e->getCode()) { } @@ -265,6 +267,7 @@ class UserApi $queryParams, $httpBody, $headerParams ); + } catch (ApiException $e) { switch ($e->getCode()) { } @@ -329,6 +332,13 @@ class UserApi $queryParams, $httpBody, $headerParams, 'string' ); + + if (!$response) { + return null; + } + + return $this->apiClient->getSerializer()->deserialize($response, 'string', $httpHeader); + } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -340,11 +350,7 @@ class UserApi throw $e; } - if (!$response) { - return null; - } - - return $this->apiClient->getSerializer()->deserialize($response, 'string'); + return null; } @@ -395,6 +401,7 @@ class UserApi $queryParams, $httpBody, $headerParams ); + } catch (ApiException $e) { switch ($e->getCode()) { } @@ -463,6 +470,13 @@ class UserApi $queryParams, $httpBody, $headerParams, '\Swagger\Client\Model\User' ); + + if (!$response) { + return null; + } + + return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\User', $httpHeader); + } catch (ApiException $e) { switch ($e->getCode()) { case 200: @@ -474,11 +488,7 @@ class UserApi throw $e; } - if (!$response) { - return null; - } - - return $this->apiClient->getSerializer()->deserialize($response, '\Swagger\Client\Model\User'); + return null; } @@ -546,6 +556,7 @@ class UserApi $queryParams, $httpBody, $headerParams ); + } catch (ApiException $e) { switch ($e->getCode()) { } @@ -614,6 +625,7 @@ class UserApi $queryParams, $httpBody, $headerParams ); + } catch (ApiException $e) { switch ($e->getCode()) { } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php b/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php index 0d281b9d1f..efdc1c896a 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php @@ -193,7 +193,7 @@ class ObjectSerializer $deserialized = $values; } elseif ($class === '\DateTime') { $deserialized = new \DateTime($data); - } elseif (in_array($class, array('integer', 'int', 'void', 'number', 'object', 'double', 'float', 'byte', 'DateTime', 'string', 'mixed', 'boolean', 'bool'))) { + } elseif (in_array($class, array('void', 'bool', 'string', 'double', 'byte', 'mixed', 'integer', 'float', 'int', 'DateTime', 'number', 'boolean', 'object'))) { settype($data, $class); $deserialized = $data; } elseif ($class === '\SplFileObject') {