From d5b3cc0534eeb69324de169f72ddcaf5d28e3ad9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arne=20J=C3=B8rgensen?= Date: Sun, 4 Jun 2017 18:47:56 +0200 Subject: [PATCH] [PHP] Fix `date` format serialization (#5754) * [PHP] Honor Swagger/OpenAPI 'date' format Per spec (https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types), DateTime instances defined as 'date' datatype need to be serialized as defined by full-date - RFC3339, which has the format: full-date = date-fullyear "-" date-month "-" date-mday ref: https://xml2rfc.tools.ietf.org/public/rfc/html/rfc3339.html#anchor14 see #5531 fixes #5607 * [PHP] Add `date` and `date-time` serializer tests See #5531 See #5607 * [PHP] Improve codestyle of generated code * [PHP] Regenerate PHP Petstore sample * [PHP] Regenerate PHP Security sample --- .../resources/php/ObjectSerializer.mustache | 11 +++--- .../src/main/resources/php/api.mustache | 4 +++ .../src/main/resources/php/api_test.mustache | 8 +---- .../main/resources/php/model_enum.mustache | 3 +- .../main/resources/php/model_generic.mustache | 14 ++++++++ .../main/resources/php/model_test.mustache | 9 +---- .../php/.swagger-codegen/VERSION | 1 + .../php/SwaggerClient-php/lib/Api/FakeApi.php | 2 +- .../php/SwaggerClient-php/lib/ApiClient.php | 6 +++- .../SwaggerClient-php/lib/Configuration.php | 26 ++++++++++++++ .../lib/Model/ModelReturn.php | 13 +++++++ .../lib/ObjectSerializer.php | 11 +++--- .../php/SwaggerClient-php/lib/Api/FakeApi.php | 16 --------- .../lib/Model/AdditionalPropertiesClass.php | 14 ++++++++ .../SwaggerClient-php/lib/Model/Animal.php | 14 ++++++++ .../lib/Model/AnimalFarm.php | 13 +++++++ .../lib/Model/ApiResponse.php | 15 ++++++++ .../lib/Model/ArrayOfArrayOfNumberOnly.php | 13 +++++++ .../lib/Model/ArrayOfNumberOnly.php | 13 +++++++ .../SwaggerClient-php/lib/Model/ArrayTest.php | 15 ++++++++ .../lib/Model/Capitalization.php | 18 ++++++++++ .../php/SwaggerClient-php/lib/Model/Cat.php | 13 +++++++ .../SwaggerClient-php/lib/Model/Category.php | 14 ++++++++ .../lib/Model/ClassModel.php | 13 +++++++ .../SwaggerClient-php/lib/Model/Client.php | 13 +++++++ .../php/SwaggerClient-php/lib/Model/Dog.php | 13 +++++++ .../lib/Model/EnumArrays.php | 14 ++++++++ .../SwaggerClient-php/lib/Model/EnumClass.php | 3 +- .../SwaggerClient-php/lib/Model/EnumTest.php | 16 +++++++++ .../lib/Model/FormatTest.php | 25 ++++++++++++++ .../lib/Model/HasOnlyReadOnly.php | 14 ++++++++ .../SwaggerClient-php/lib/Model/MapTest.php | 14 ++++++++ ...PropertiesAndAdditionalPropertiesClass.php | 15 ++++++++ .../lib/Model/Model200Response.php | 14 ++++++++ .../SwaggerClient-php/lib/Model/ModelList.php | 13 +++++++ .../lib/Model/ModelReturn.php | 13 +++++++ .../php/SwaggerClient-php/lib/Model/Name.php | 16 +++++++++ .../lib/Model/NumberOnly.php | 13 +++++++ .../php/SwaggerClient-php/lib/Model/Order.php | 18 ++++++++++ .../lib/Model/OuterBoolean.php | 13 +++++++ .../lib/Model/OuterComposite.php | 15 ++++++++ .../SwaggerClient-php/lib/Model/OuterEnum.php | 3 +- .../lib/Model/OuterNumber.php | 13 +++++++ .../lib/Model/OuterString.php | 13 +++++++ .../php/SwaggerClient-php/lib/Model/Pet.php | 18 ++++++++++ .../lib/Model/ReadOnlyFirst.php | 14 ++++++++ .../lib/Model/SpecialModelName.php | 13 +++++++ .../php/SwaggerClient-php/lib/Model/Tag.php | 14 ++++++++ .../php/SwaggerClient-php/lib/Model/User.php | 20 +++++++++++ .../lib/ObjectSerializer.php | 11 +++--- .../phpcs-generated-code.xml | 9 ++++- .../tests/DateTimeSerializerTest.php | 34 +++++++++++++++++++ .../SwaggerClient-php/tests/PetApiTest.php | 5 ++- .../SwaggerClient-php/tests/UserApiTest.php | 1 - 54 files changed, 636 insertions(+), 53 deletions(-) create mode 100644 samples/client/petstore-security-test/php/.swagger-codegen/VERSION create mode 100644 samples/client/petstore/php/SwaggerClient-php/tests/DateTimeSerializerTest.php diff --git a/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache b/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache index 64cf90a72ca..0f5de349aca 100644 --- a/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache +++ b/modules/swagger-codegen/src/main/resources/php/ObjectSerializer.mustache @@ -32,16 +32,18 @@ class ObjectSerializer /** * Serialize data * - * @param mixed $data the data to serialize + * @param mixed $data the data to serialize + * @param string $type the SwaggerType of the data + * @param string $format the format of the Swagger type of the data * * @return string|object serialized form of $data */ - public static function sanitizeForSerialization($data) + public static function sanitizeForSerialization($data, $type = null, $format = null) { if (is_scalar($data) || null === $data) { return $data; } elseif ($data instanceof \DateTime) { - return $data->format(\DateTime::ATOM); + return ($format === 'date') ? $data->format('Y-m-d') : $data->format(\DateTime::ATOM); } elseif (is_array($data)) { foreach ($data as $property => $value) { $data[$property] = self::sanitizeForSerialization($value); @@ -49,6 +51,7 @@ class ObjectSerializer return $data; } elseif (is_object($data)) { $values = []; + $formats = $data::swaggerFormats(); foreach ($data::swaggerTypes() as $property => $swaggerType) { $getter = $data::getters()[$property]; $value = $data->$getter(); @@ -58,7 +61,7 @@ class ObjectSerializer throw new \InvalidArgumentException("Invalid value for enum '$swaggerType', must be one of: '$imploded'"); } if ($value !== null) { - $values[$data::attributeMap()[$property]] = self::sanitizeForSerialization($value); + $values[$data::attributeMap()[$property]] = self::sanitizeForSerialization($value, $swaggerType, $formats[$property]); } } return (object)$values; diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index dfde3fc3b5b..1efbe254d8f 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -80,8 +80,10 @@ use \{{invokerPackage}}\ObjectSerializer; /** * Operation {{{operationId}}} +{{#summary}} * * {{{summary}}} +{{/summary}} * {{#description}} * {{.}} @@ -101,8 +103,10 @@ use \{{invokerPackage}}\ObjectSerializer; /** * Operation {{{operationId}}}WithHttpInfo +{{#summary}} * * {{{summary}}} +{{/summary}} * {{#description}} * {{.}} diff --git a/modules/swagger-codegen/src/main/resources/php/api_test.mustache b/modules/swagger-codegen/src/main/resources/php/api_test.mustache index c6504437012..adf6455ef9b 100644 --- a/modules/swagger-codegen/src/main/resources/php/api_test.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api_test.mustache @@ -39,7 +39,6 @@ use \{{invokerPackage}}\ObjectSerializer; */ public static function setUpBeforeClass() { - } /** @@ -47,7 +46,6 @@ use \{{invokerPackage}}\ObjectSerializer; */ public function setUp() { - } /** @@ -55,7 +53,6 @@ use \{{invokerPackage}}\ObjectSerializer; */ public function tearDown() { - } /** @@ -63,10 +60,9 @@ use \{{invokerPackage}}\ObjectSerializer; */ public static function tearDownAfterClass() { - } - {{#operation}} + /** * Test case for {{{operationId}}} * @@ -75,9 +71,7 @@ use \{{invokerPackage}}\ObjectSerializer; */ public function test{{vendorExtensions.x-testOperationId}}() { - } - {{/operation}} } {{/operations}} diff --git a/modules/swagger-codegen/src/main/resources/php/model_enum.mustache b/modules/swagger-codegen/src/main/resources/php/model_enum.mustache index c34cfb3faac..5e6b2aea215 100644 --- a/modules/swagger-codegen/src/main/resources/php/model_enum.mustache +++ b/modules/swagger-codegen/src/main/resources/php/model_enum.mustache @@ -1,4 +1,5 @@ -class {{classname}} { +class {{classname}} +{ /** * Possible values of this enum */ diff --git a/modules/swagger-codegen/src/main/resources/php/model_generic.mustache b/modules/swagger-codegen/src/main/resources/php/model_generic.mustache index 83cf38deb46..611cdcb013f 100644 --- a/modules/swagger-codegen/src/main/resources/php/model_generic.mustache +++ b/modules/swagger-codegen/src/main/resources/php/model_generic.mustache @@ -17,11 +17,25 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}imple {{/hasMore}}{{/vars}} ]; + /** + * Array of property to format mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerFormats = [ + {{#vars}}'{{name}}' => {{#dataFormat}}'{{{dataFormat}}}'{{/dataFormat}}{{^dataFormat}}null{{/dataFormat}}{{#hasMore}}, + {{/hasMore}}{{/vars}} + ]; + public static function swaggerTypes() { return self::$swaggerTypes{{#parentSchema}} + parent::swaggerTypes(){{/parentSchema}}; } + public static function swaggerFormats() + { + return self::$swaggerFormats{{#parentSchema}} + parent::swaggerFormats(){{/parentSchema}}; + } + /** * Array of attributes where the key is the local name, and the value is the original name * @var string[] diff --git a/modules/swagger-codegen/src/main/resources/php/model_test.mustache b/modules/swagger-codegen/src/main/resources/php/model_test.mustache index 396a3eccb7a..363be167fcb 100644 --- a/modules/swagger-codegen/src/main/resources/php/model_test.mustache +++ b/modules/swagger-codegen/src/main/resources/php/model_test.mustache @@ -39,7 +39,6 @@ class {{classname}}Test extends \PHPUnit_Framework_TestCase */ public static function setUpBeforeClass() { - } /** @@ -47,7 +46,6 @@ class {{classname}}Test extends \PHPUnit_Framework_TestCase */ public function setUp() { - } /** @@ -55,7 +53,6 @@ class {{classname}}Test extends \PHPUnit_Framework_TestCase */ public function tearDown() { - } /** @@ -63,7 +60,6 @@ class {{classname}}Test extends \PHPUnit_Framework_TestCase */ public static function tearDownAfterClass() { - } /** @@ -71,18 +67,15 @@ class {{classname}}Test extends \PHPUnit_Framework_TestCase */ public function test{{classname}}() { - } - {{#vars}} + /** * Test attribute "{{name}}" */ public function testProperty{{nameInCamelCase}}() { - } - {{/vars}} } {{/model}} diff --git a/samples/client/petstore-security-test/php/.swagger-codegen/VERSION b/samples/client/petstore-security-test/php/.swagger-codegen/VERSION new file mode 100644 index 00000000000..7fea99011a6 --- /dev/null +++ b/samples/client/petstore-security-test/php/.swagger-codegen/VERSION @@ -0,0 +1 @@ +2.2.3-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Api/FakeApi.php b/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Api/FakeApi.php index 7c6c1e4a8c8..419750c64da 100644 --- a/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Api/FakeApi.php +++ b/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Api/FakeApi.php @@ -129,7 +129,7 @@ class FakeApi if ($test_code_inject____end____rn_n_r !== null) { $formParams['test code inject */ ' " =end -- \r\n \n \r'] = $this->apiClient->getSerializer()->toFormValue($test_code_inject____end____rn_n_r); } - + // for model (json/xml) if (isset($_tempBody)) { $httpBody = $_tempBody; // $_tempBody is the method argument, if present diff --git a/samples/client/petstore-security-test/php/SwaggerClient-php/lib/ApiClient.php b/samples/client/petstore-security-test/php/SwaggerClient-php/lib/ApiClient.php index ea22b4f99ee..6d600a1bf2a 100644 --- a/samples/client/petstore-security-test/php/SwaggerClient-php/lib/ApiClient.php +++ b/samples/client/petstore-security-test/php/SwaggerClient-php/lib/ApiClient.php @@ -167,7 +167,7 @@ class ApiClient if ($this->config->getCurlConnectTimeout() != 0) { curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $this->config->getCurlConnectTimeout()); } - + // return the result on success, rather than just true curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); @@ -199,6 +199,10 @@ class ApiClient $url = ($url . '?' . http_build_query($queryParams)); } + if ($this->config->getAllowEncoding()) { + curl_setopt($curl, CURLOPT_ENCODING, ''); + } + if ($method === self::$POST) { curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); diff --git a/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Configuration.php b/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Configuration.php index 5f19f8df53a..8aad4356eee 100644 --- a/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Configuration.php +++ b/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Configuration.php @@ -177,6 +177,13 @@ class Configuration */ protected $proxyPassword; + /** + * Allow Curl encoding header + * + * @var bool + */ + protected $allowEncoding = false; + /** * Constructor */ @@ -445,6 +452,16 @@ class Configuration return $this; } + /** + * Set whether to accept encoding + * @param bool $allowEncoding + */ + public function setAllowEncoding($allowEncoding) + { + $this->allowEncoding = $allowEncoding; + return $this; + } + /** * Gets the HTTP connect timeout value * @@ -455,6 +472,15 @@ class Configuration return $this->curlConnectTimeout; } + /** + * Get whether to allow encoding + * + * @return bool + */ + public function getAllowEncoding() + { + return $this->allowEncoding; + } /** * Sets the HTTP Proxy Host diff --git a/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Model/ModelReturn.php b/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Model/ModelReturn.php index 7f68442329a..e71899f4a49 100644 --- a/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Model/ModelReturn.php +++ b/samples/client/petstore-security-test/php/SwaggerClient-php/lib/Model/ModelReturn.php @@ -58,11 +58,24 @@ class ModelReturn implements ArrayAccess 'return' => 'int' ]; + /** + * Array of property to format mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerFormats = [ + 'return' => 'int32' + ]; + public static function swaggerTypes() { return self::$swaggerTypes; } + public static function swaggerFormats() + { + return self::$swaggerFormats; + } + /** * Array of attributes where the key is the local name, and the value is the original name * @var string[] diff --git a/samples/client/petstore-security-test/php/SwaggerClient-php/lib/ObjectSerializer.php b/samples/client/petstore-security-test/php/SwaggerClient-php/lib/ObjectSerializer.php index 3756fd644be..6e0dbb437be 100644 --- a/samples/client/petstore-security-test/php/SwaggerClient-php/lib/ObjectSerializer.php +++ b/samples/client/petstore-security-test/php/SwaggerClient-php/lib/ObjectSerializer.php @@ -42,16 +42,18 @@ class ObjectSerializer /** * Serialize data * - * @param mixed $data the data to serialize + * @param mixed $data the data to serialize + * @param string $type the SwaggerType of the data + * @param string $format the format of the Swagger type of the data * * @return string|object serialized form of $data */ - public static function sanitizeForSerialization($data) + public static function sanitizeForSerialization($data, $type = null, $format = null) { if (is_scalar($data) || null === $data) { return $data; } elseif ($data instanceof \DateTime) { - return $data->format(\DateTime::ATOM); + return ($format === 'date') ? $data->format('Y-m-d') : $data->format(\DateTime::ATOM); } elseif (is_array($data)) { foreach ($data as $property => $value) { $data[$property] = self::sanitizeForSerialization($value); @@ -59,6 +61,7 @@ class ObjectSerializer return $data; } elseif (is_object($data)) { $values = []; + $formats = $data::swaggerFormats(); foreach ($data::swaggerTypes() as $property => $swaggerType) { $getter = $data::getters()[$property]; $value = $data->$getter(); @@ -68,7 +71,7 @@ class ObjectSerializer throw new \InvalidArgumentException("Invalid value for enum '$swaggerType', must be one of: '$imploded'"); } if ($value !== null) { - $values[$data::attributeMap()[$property]] = self::sanitizeForSerialization($value); + $values[$data::attributeMap()[$property]] = self::sanitizeForSerialization($value, $swaggerType, $formats[$property]); } } return (object)$values; diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php index ec943d9906f..916adfe43c2 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php @@ -90,8 +90,6 @@ class FakeApi /** * Operation fakeOuterBooleanSerialize * - * - * * @param \Swagger\Client\Model\OuterBoolean $body Input boolean as post body (optional) * @throws \Swagger\Client\ApiException on non-2xx response * @return \Swagger\Client\Model\OuterBoolean @@ -105,8 +103,6 @@ class FakeApi /** * Operation fakeOuterBooleanSerializeWithHttpInfo * - * - * * @param \Swagger\Client\Model\OuterBoolean $body Input boolean as post body (optional) * @throws \Swagger\Client\ApiException on non-2xx response * @return array of \Swagger\Client\Model\OuterBoolean, HTTP status code, HTTP response headers (array of strings) @@ -165,8 +161,6 @@ class FakeApi /** * Operation fakeOuterCompositeSerialize * - * - * * @param \Swagger\Client\Model\OuterComposite $body Input composite as post body (optional) * @throws \Swagger\Client\ApiException on non-2xx response * @return \Swagger\Client\Model\OuterComposite @@ -180,8 +174,6 @@ class FakeApi /** * Operation fakeOuterCompositeSerializeWithHttpInfo * - * - * * @param \Swagger\Client\Model\OuterComposite $body Input composite as post body (optional) * @throws \Swagger\Client\ApiException on non-2xx response * @return array of \Swagger\Client\Model\OuterComposite, HTTP status code, HTTP response headers (array of strings) @@ -240,8 +232,6 @@ class FakeApi /** * Operation fakeOuterNumberSerialize * - * - * * @param \Swagger\Client\Model\OuterNumber $body Input number as post body (optional) * @throws \Swagger\Client\ApiException on non-2xx response * @return \Swagger\Client\Model\OuterNumber @@ -255,8 +245,6 @@ class FakeApi /** * Operation fakeOuterNumberSerializeWithHttpInfo * - * - * * @param \Swagger\Client\Model\OuterNumber $body Input number as post body (optional) * @throws \Swagger\Client\ApiException on non-2xx response * @return array of \Swagger\Client\Model\OuterNumber, HTTP status code, HTTP response headers (array of strings) @@ -315,8 +303,6 @@ class FakeApi /** * Operation fakeOuterStringSerialize * - * - * * @param \Swagger\Client\Model\OuterString $body Input string as post body (optional) * @throws \Swagger\Client\ApiException on non-2xx response * @return \Swagger\Client\Model\OuterString @@ -330,8 +316,6 @@ class FakeApi /** * Operation fakeOuterStringSerializeWithHttpInfo * - * - * * @param \Swagger\Client\Model\OuterString $body Input string as post body (optional) * @throws \Swagger\Client\ApiException on non-2xx response * @return array of \Swagger\Client\Model\OuterString, HTTP status code, HTTP response headers (array of strings) diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/AdditionalPropertiesClass.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/AdditionalPropertiesClass.php index 8f901b731a2..14d068ffbe3 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/AdditionalPropertiesClass.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/AdditionalPropertiesClass.php @@ -58,11 +58,25 @@ class AdditionalPropertiesClass implements ArrayAccess 'map_of_map_property' => 'map[string,map[string,string]]' ]; + /** + * Array of property to format mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerFormats = [ + 'map_property' => null, + 'map_of_map_property' => null + ]; + public static function swaggerTypes() { return self::$swaggerTypes; } + public static function swaggerFormats() + { + return self::$swaggerFormats; + } + /** * Array of attributes where the key is the local name, and the value is the original name * @var string[] diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Animal.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Animal.php index a0f1de3c08c..a0c94f0e553 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Animal.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Animal.php @@ -58,11 +58,25 @@ class Animal implements ArrayAccess 'color' => 'string' ]; + /** + * Array of property to format mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerFormats = [ + 'class_name' => null, + 'color' => null + ]; + public static function swaggerTypes() { return self::$swaggerTypes; } + public static function swaggerFormats() + { + return self::$swaggerFormats; + } + /** * Array of attributes where the key is the local name, and the value is the original name * @var string[] diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/AnimalFarm.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/AnimalFarm.php index d1736598716..30bace59f7a 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/AnimalFarm.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/AnimalFarm.php @@ -57,11 +57,24 @@ class AnimalFarm implements ArrayAccess ]; + /** + * Array of property to format mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerFormats = [ + + ]; + public static function swaggerTypes() { return self::$swaggerTypes; } + public static function swaggerFormats() + { + return self::$swaggerFormats; + } + /** * Array of attributes where the key is the local name, and the value is the original name * @var string[] diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ApiResponse.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ApiResponse.php index 95148c75e22..e20c4808486 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ApiResponse.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ApiResponse.php @@ -59,11 +59,26 @@ class ApiResponse implements ArrayAccess 'message' => 'string' ]; + /** + * Array of property to format mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerFormats = [ + 'code' => 'int32', + 'type' => null, + 'message' => null + ]; + public static function swaggerTypes() { return self::$swaggerTypes; } + public static function swaggerFormats() + { + return self::$swaggerFormats; + } + /** * Array of attributes where the key is the local name, and the value is the original name * @var string[] diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ArrayOfArrayOfNumberOnly.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ArrayOfArrayOfNumberOnly.php index 48f3b369b77..a615072618a 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ArrayOfArrayOfNumberOnly.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ArrayOfArrayOfNumberOnly.php @@ -57,11 +57,24 @@ class ArrayOfArrayOfNumberOnly implements ArrayAccess 'array_array_number' => 'float[][]' ]; + /** + * Array of property to format mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerFormats = [ + 'array_array_number' => null + ]; + public static function swaggerTypes() { return self::$swaggerTypes; } + public static function swaggerFormats() + { + return self::$swaggerFormats; + } + /** * Array of attributes where the key is the local name, and the value is the original name * @var string[] diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ArrayOfNumberOnly.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ArrayOfNumberOnly.php index 103297a25e0..ab0e1b9f9e7 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ArrayOfNumberOnly.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ArrayOfNumberOnly.php @@ -57,11 +57,24 @@ class ArrayOfNumberOnly implements ArrayAccess 'array_number' => 'float[]' ]; + /** + * Array of property to format mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerFormats = [ + 'array_number' => null + ]; + public static function swaggerTypes() { return self::$swaggerTypes; } + public static function swaggerFormats() + { + return self::$swaggerFormats; + } + /** * Array of attributes where the key is the local name, and the value is the original name * @var string[] diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ArrayTest.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ArrayTest.php index f95c8cf869b..a723c141fb1 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ArrayTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ArrayTest.php @@ -59,11 +59,26 @@ class ArrayTest implements ArrayAccess 'array_array_of_model' => '\Swagger\Client\Model\ReadOnlyFirst[][]' ]; + /** + * Array of property to format mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerFormats = [ + 'array_of_string' => null, + 'array_array_of_integer' => 'int64', + 'array_array_of_model' => null + ]; + public static function swaggerTypes() { return self::$swaggerTypes; } + public static function swaggerFormats() + { + return self::$swaggerFormats; + } + /** * Array of attributes where the key is the local name, and the value is the original name * @var string[] diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Capitalization.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Capitalization.php index 9e124413199..c1caafda4a8 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Capitalization.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Capitalization.php @@ -62,11 +62,29 @@ class Capitalization implements ArrayAccess 'att_name' => 'string' ]; + /** + * Array of property to format mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerFormats = [ + 'small_camel' => null, + 'capital_camel' => null, + 'small_snake' => null, + 'capital_snake' => null, + 'sca_eth_flow_points' => null, + 'att_name' => null + ]; + public static function swaggerTypes() { return self::$swaggerTypes; } + public static function swaggerFormats() + { + return self::$swaggerFormats; + } + /** * Array of attributes where the key is the local name, and the value is the original name * @var string[] diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Cat.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Cat.php index 611f01e36f4..2acf8d71d01 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Cat.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Cat.php @@ -57,11 +57,24 @@ class Cat extends Animal implements ArrayAccess 'declawed' => 'bool' ]; + /** + * Array of property to format mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerFormats = [ + 'declawed' => null + ]; + public static function swaggerTypes() { return self::$swaggerTypes + parent::swaggerTypes(); } + public static function swaggerFormats() + { + return self::$swaggerFormats + parent::swaggerFormats(); + } + /** * Array of attributes where the key is the local name, and the value is the original name * @var string[] diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php index f8848cb956e..b1796844d4e 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php @@ -58,11 +58,25 @@ class Category implements ArrayAccess 'name' => 'string' ]; + /** + * Array of property to format mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerFormats = [ + 'id' => 'int64', + 'name' => null + ]; + public static function swaggerTypes() { return self::$swaggerTypes; } + public static function swaggerFormats() + { + return self::$swaggerFormats; + } + /** * Array of attributes where the key is the local name, and the value is the original name * @var string[] diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ClassModel.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ClassModel.php index 18aa0fcbd4b..3fa669ece95 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ClassModel.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ClassModel.php @@ -58,11 +58,24 @@ class ClassModel implements ArrayAccess '_class' => 'string' ]; + /** + * Array of property to format mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerFormats = [ + '_class' => null + ]; + public static function swaggerTypes() { return self::$swaggerTypes; } + public static function swaggerFormats() + { + return self::$swaggerFormats; + } + /** * Array of attributes where the key is the local name, and the value is the original name * @var string[] diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Client.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Client.php index a6a09cfa3a7..34c82824f89 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Client.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Client.php @@ -57,11 +57,24 @@ class Client implements ArrayAccess 'client' => 'string' ]; + /** + * Array of property to format mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerFormats = [ + 'client' => null + ]; + public static function swaggerTypes() { return self::$swaggerTypes; } + public static function swaggerFormats() + { + return self::$swaggerFormats; + } + /** * Array of attributes where the key is the local name, and the value is the original name * @var string[] diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Dog.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Dog.php index ba325f2f8bc..111de31a6d4 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Dog.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Dog.php @@ -57,11 +57,24 @@ class Dog extends Animal implements ArrayAccess 'breed' => 'string' ]; + /** + * Array of property to format mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerFormats = [ + 'breed' => null + ]; + public static function swaggerTypes() { return self::$swaggerTypes + parent::swaggerTypes(); } + public static function swaggerFormats() + { + return self::$swaggerFormats + parent::swaggerFormats(); + } + /** * Array of attributes where the key is the local name, and the value is the original name * @var string[] diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumArrays.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumArrays.php index 34daaaa701e..ea05271e2d2 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumArrays.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumArrays.php @@ -58,11 +58,25 @@ class EnumArrays implements ArrayAccess 'array_enum' => 'string[]' ]; + /** + * Array of property to format mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerFormats = [ + 'just_symbol' => null, + 'array_enum' => null + ]; + public static function swaggerTypes() { return self::$swaggerTypes; } + public static function swaggerFormats() + { + return self::$swaggerFormats; + } + /** * Array of attributes where the key is the local name, and the value is the original name * @var string[] diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumClass.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumClass.php index 1e12ea14587..44056f7a9df 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumClass.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumClass.php @@ -37,7 +37,8 @@ namespace Swagger\Client\Model; * @author Swagger Codegen team * @link https://github.com/swagger-api/swagger-codegen */ -class EnumClass { +class EnumClass +{ /** * Possible values of this enum */ diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumTest.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumTest.php index b3620adae3f..d4dcdb55ac2 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumTest.php @@ -60,11 +60,27 @@ class EnumTest implements ArrayAccess 'outer_enum' => '\Swagger\Client\Model\OuterEnum' ]; + /** + * Array of property to format mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerFormats = [ + 'enum_string' => null, + 'enum_integer' => 'int32', + 'enum_number' => 'double', + 'outer_enum' => null + ]; + public static function swaggerTypes() { return self::$swaggerTypes; } + public static function swaggerFormats() + { + return self::$swaggerFormats; + } + /** * Array of attributes where the key is the local name, and the value is the original name * @var string[] diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/FormatTest.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/FormatTest.php index 400d9adf3c3..31ca7fbf138 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/FormatTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/FormatTest.php @@ -69,11 +69,36 @@ class FormatTest implements ArrayAccess 'password' => 'string' ]; + /** + * Array of property to format mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerFormats = [ + 'integer' => null, + 'int32' => 'int32', + 'int64' => 'int64', + 'number' => null, + 'float' => 'float', + 'double' => 'double', + 'string' => null, + 'byte' => 'byte', + 'binary' => 'binary', + 'date' => 'date', + 'date_time' => 'date-time', + 'uuid' => 'uuid', + 'password' => 'password' + ]; + public static function swaggerTypes() { return self::$swaggerTypes; } + public static function swaggerFormats() + { + return self::$swaggerFormats; + } + /** * Array of attributes where the key is the local name, and the value is the original name * @var string[] diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/HasOnlyReadOnly.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/HasOnlyReadOnly.php index 953f1550bbc..48335af8df5 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/HasOnlyReadOnly.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/HasOnlyReadOnly.php @@ -58,11 +58,25 @@ class HasOnlyReadOnly implements ArrayAccess 'foo' => 'string' ]; + /** + * Array of property to format mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerFormats = [ + 'bar' => null, + 'foo' => null + ]; + public static function swaggerTypes() { return self::$swaggerTypes; } + public static function swaggerFormats() + { + return self::$swaggerFormats; + } + /** * Array of attributes where the key is the local name, and the value is the original name * @var string[] diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/MapTest.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/MapTest.php index 4acee7ceeeb..5fb0c5a86fa 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/MapTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/MapTest.php @@ -58,11 +58,25 @@ class MapTest implements ArrayAccess 'map_of_enum_string' => 'map[string,string]' ]; + /** + * Array of property to format mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerFormats = [ + 'map_map_of_string' => null, + 'map_of_enum_string' => null + ]; + public static function swaggerTypes() { return self::$swaggerTypes; } + public static function swaggerFormats() + { + return self::$swaggerFormats; + } + /** * Array of attributes where the key is the local name, and the value is the original name * @var string[] diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/MixedPropertiesAndAdditionalPropertiesClass.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/MixedPropertiesAndAdditionalPropertiesClass.php index a7b8eb94812..49a19cbef7c 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/MixedPropertiesAndAdditionalPropertiesClass.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/MixedPropertiesAndAdditionalPropertiesClass.php @@ -59,11 +59,26 @@ class MixedPropertiesAndAdditionalPropertiesClass implements ArrayAccess 'map' => 'map[string,\Swagger\Client\Model\Animal]' ]; + /** + * Array of property to format mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerFormats = [ + 'uuid' => 'uuid', + 'date_time' => 'date-time', + 'map' => null + ]; + public static function swaggerTypes() { return self::$swaggerTypes; } + public static function swaggerFormats() + { + return self::$swaggerFormats; + } + /** * Array of attributes where the key is the local name, and the value is the original name * @var string[] diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Model200Response.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Model200Response.php index 36473dc1dcc..f18c114ba63 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Model200Response.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Model200Response.php @@ -59,11 +59,25 @@ class Model200Response implements ArrayAccess 'class' => 'string' ]; + /** + * Array of property to format mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerFormats = [ + 'name' => 'int32', + 'class' => null + ]; + public static function swaggerTypes() { return self::$swaggerTypes; } + public static function swaggerFormats() + { + return self::$swaggerFormats; + } + /** * Array of attributes where the key is the local name, and the value is the original name * @var string[] diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ModelList.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ModelList.php index d2fae7b53f9..2cfe213eeba 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ModelList.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ModelList.php @@ -57,11 +57,24 @@ class ModelList implements ArrayAccess '_123_list' => 'string' ]; + /** + * Array of property to format mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerFormats = [ + '_123_list' => null + ]; + public static function swaggerTypes() { return self::$swaggerTypes; } + public static function swaggerFormats() + { + return self::$swaggerFormats; + } + /** * Array of attributes where the key is the local name, and the value is the original name * @var string[] diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ModelReturn.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ModelReturn.php index f959dbd5065..bbb1a8e6335 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ModelReturn.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ModelReturn.php @@ -58,11 +58,24 @@ class ModelReturn implements ArrayAccess 'return' => 'int' ]; + /** + * Array of property to format mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerFormats = [ + 'return' => 'int32' + ]; + public static function swaggerTypes() { return self::$swaggerTypes; } + public static function swaggerFormats() + { + return self::$swaggerFormats; + } + /** * Array of attributes where the key is the local name, and the value is the original name * @var string[] diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Name.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Name.php index 61a6838537b..97ae1e0211f 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Name.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Name.php @@ -61,11 +61,27 @@ class Name implements ArrayAccess '_123_number' => 'int' ]; + /** + * Array of property to format mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerFormats = [ + 'name' => 'int32', + 'snake_case' => 'int32', + 'property' => null, + '_123_number' => null + ]; + public static function swaggerTypes() { return self::$swaggerTypes; } + public static function swaggerFormats() + { + return self::$swaggerFormats; + } + /** * Array of attributes where the key is the local name, and the value is the original name * @var string[] diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/NumberOnly.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/NumberOnly.php index eb5e7f10698..8cc2f4e24f0 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/NumberOnly.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/NumberOnly.php @@ -57,11 +57,24 @@ class NumberOnly implements ArrayAccess 'just_number' => 'float' ]; + /** + * Array of property to format mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerFormats = [ + 'just_number' => null + ]; + public static function swaggerTypes() { return self::$swaggerTypes; } + public static function swaggerFormats() + { + return self::$swaggerFormats; + } + /** * Array of attributes where the key is the local name, and the value is the original name * @var string[] diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php index 8871ecfbd97..e6f1c6c22f1 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php @@ -62,11 +62,29 @@ class Order implements ArrayAccess 'complete' => 'bool' ]; + /** + * Array of property to format mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerFormats = [ + 'id' => 'int64', + 'pet_id' => 'int64', + 'quantity' => 'int32', + 'ship_date' => 'date-time', + 'status' => null, + 'complete' => null + ]; + public static function swaggerTypes() { return self::$swaggerTypes; } + public static function swaggerFormats() + { + return self::$swaggerFormats; + } + /** * Array of attributes where the key is the local name, and the value is the original name * @var string[] diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/OuterBoolean.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/OuterBoolean.php index 34a56535ad3..7698e46c17f 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/OuterBoolean.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/OuterBoolean.php @@ -57,11 +57,24 @@ class OuterBoolean implements ArrayAccess ]; + /** + * Array of property to format mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerFormats = [ + + ]; + public static function swaggerTypes() { return self::$swaggerTypes; } + public static function swaggerFormats() + { + return self::$swaggerFormats; + } + /** * Array of attributes where the key is the local name, and the value is the original name * @var string[] diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/OuterComposite.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/OuterComposite.php index 1979b28f847..4165c715b44 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/OuterComposite.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/OuterComposite.php @@ -59,11 +59,26 @@ class OuterComposite implements ArrayAccess 'my_boolean' => '\Swagger\Client\Model\OuterBoolean' ]; + /** + * Array of property to format mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerFormats = [ + 'my_number' => null, + 'my_string' => null, + 'my_boolean' => null + ]; + public static function swaggerTypes() { return self::$swaggerTypes; } + public static function swaggerFormats() + { + return self::$swaggerFormats; + } + /** * Array of attributes where the key is the local name, and the value is the original name * @var string[] diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/OuterEnum.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/OuterEnum.php index e1247e2423e..6d2cbae69d1 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/OuterEnum.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/OuterEnum.php @@ -37,7 +37,8 @@ namespace Swagger\Client\Model; * @author Swagger Codegen team * @link https://github.com/swagger-api/swagger-codegen */ -class OuterEnum { +class OuterEnum +{ /** * Possible values of this enum */ diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/OuterNumber.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/OuterNumber.php index 3bf5d2fe4a0..79e25a83dff 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/OuterNumber.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/OuterNumber.php @@ -57,11 +57,24 @@ class OuterNumber implements ArrayAccess ]; + /** + * Array of property to format mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerFormats = [ + + ]; + public static function swaggerTypes() { return self::$swaggerTypes; } + public static function swaggerFormats() + { + return self::$swaggerFormats; + } + /** * Array of attributes where the key is the local name, and the value is the original name * @var string[] diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/OuterString.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/OuterString.php index 9e441c8d3fa..2e172dfaf9c 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/OuterString.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/OuterString.php @@ -57,11 +57,24 @@ class OuterString implements ArrayAccess ]; + /** + * Array of property to format mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerFormats = [ + + ]; + public static function swaggerTypes() { return self::$swaggerTypes; } + public static function swaggerFormats() + { + return self::$swaggerFormats; + } + /** * Array of attributes where the key is the local name, and the value is the original name * @var string[] diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php index 6cc91fe88fe..3f66a60e76d 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php @@ -62,11 +62,29 @@ class Pet implements ArrayAccess 'status' => 'string' ]; + /** + * Array of property to format mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerFormats = [ + 'id' => 'int64', + 'category' => null, + 'name' => null, + 'photo_urls' => null, + 'tags' => null, + 'status' => null + ]; + public static function swaggerTypes() { return self::$swaggerTypes; } + public static function swaggerFormats() + { + return self::$swaggerFormats; + } + /** * Array of attributes where the key is the local name, and the value is the original name * @var string[] diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ReadOnlyFirst.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ReadOnlyFirst.php index b53677fc495..4bc008ba9c4 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ReadOnlyFirst.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ReadOnlyFirst.php @@ -58,11 +58,25 @@ class ReadOnlyFirst implements ArrayAccess 'baz' => 'string' ]; + /** + * Array of property to format mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerFormats = [ + 'bar' => null, + 'baz' => null + ]; + public static function swaggerTypes() { return self::$swaggerTypes; } + public static function swaggerFormats() + { + return self::$swaggerFormats; + } + /** * Array of attributes where the key is the local name, and the value is the original name * @var string[] diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/SpecialModelName.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/SpecialModelName.php index ac73ff0a376..da04522ec35 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/SpecialModelName.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/SpecialModelName.php @@ -57,11 +57,24 @@ class SpecialModelName implements ArrayAccess 'special_property_name' => 'int' ]; + /** + * Array of property to format mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerFormats = [ + 'special_property_name' => 'int64' + ]; + public static function swaggerTypes() { return self::$swaggerTypes; } + public static function swaggerFormats() + { + return self::$swaggerFormats; + } + /** * Array of attributes where the key is the local name, and the value is the original name * @var string[] diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php index 1705129380b..96026984207 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php @@ -58,11 +58,25 @@ class Tag implements ArrayAccess 'name' => 'string' ]; + /** + * Array of property to format mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerFormats = [ + 'id' => 'int64', + 'name' => null + ]; + public static function swaggerTypes() { return self::$swaggerTypes; } + public static function swaggerFormats() + { + return self::$swaggerFormats; + } + /** * Array of attributes where the key is the local name, and the value is the original name * @var string[] diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php index 583a94ca57c..59dd2f7268c 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php @@ -64,11 +64,31 @@ class User implements ArrayAccess 'user_status' => 'int' ]; + /** + * Array of property to format mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerFormats = [ + 'id' => 'int64', + 'username' => null, + 'first_name' => null, + 'last_name' => null, + 'email' => null, + 'password' => null, + 'phone' => null, + 'user_status' => 'int32' + ]; + public static function swaggerTypes() { return self::$swaggerTypes; } + public static function swaggerFormats() + { + return self::$swaggerFormats; + } + /** * Array of attributes where the key is the local name, and the value is the original name * @var string[] diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php b/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php index 32143b2c607..0f9f527a2ac 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php @@ -42,16 +42,18 @@ class ObjectSerializer /** * Serialize data * - * @param mixed $data the data to serialize + * @param mixed $data the data to serialize + * @param string $type the SwaggerType of the data + * @param string $format the format of the Swagger type of the data * * @return string|object serialized form of $data */ - public static function sanitizeForSerialization($data) + public static function sanitizeForSerialization($data, $type = null, $format = null) { if (is_scalar($data) || null === $data) { return $data; } elseif ($data instanceof \DateTime) { - return $data->format(\DateTime::ATOM); + return ($format === 'date') ? $data->format('Y-m-d') : $data->format(\DateTime::ATOM); } elseif (is_array($data)) { foreach ($data as $property => $value) { $data[$property] = self::sanitizeForSerialization($value); @@ -59,6 +61,7 @@ class ObjectSerializer return $data; } elseif (is_object($data)) { $values = []; + $formats = $data::swaggerFormats(); foreach ($data::swaggerTypes() as $property => $swaggerType) { $getter = $data::getters()[$property]; $value = $data->$getter(); @@ -68,7 +71,7 @@ class ObjectSerializer throw new \InvalidArgumentException("Invalid value for enum '$swaggerType', must be one of: '$imploded'"); } if ($value !== null) { - $values[$data::attributeMap()[$property]] = self::sanitizeForSerialization($value); + $values[$data::attributeMap()[$property]] = self::sanitizeForSerialization($value, $swaggerType, $formats[$property]); } } return (object)$values; diff --git a/samples/client/petstore/php/SwaggerClient-php/phpcs-generated-code.xml b/samples/client/petstore/php/SwaggerClient-php/phpcs-generated-code.xml index a0173077aa9..af658f0b999 100644 --- a/samples/client/petstore/php/SwaggerClient-php/phpcs-generated-code.xml +++ b/samples/client/petstore/php/SwaggerClient-php/phpcs-generated-code.xml @@ -4,7 +4,14 @@ Arnes Drupal code checker - + + + + * + + + + * diff --git a/samples/client/petstore/php/SwaggerClient-php/tests/DateTimeSerializerTest.php b/samples/client/petstore/php/SwaggerClient-php/tests/DateTimeSerializerTest.php new file mode 100644 index 00000000000..cea8db4a067 --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/tests/DateTimeSerializerTest.php @@ -0,0 +1,34 @@ + $dateTime, + ]); + + $data = ObjectSerializer::sanitizeForSerialization($input); + + $this->assertEquals($data->dateTime, '1973-04-30T17:05:00+02:00'); + } + + public function testDateSanitazion() + { + $dateTime = new \DateTime('April 30, 1973 17:05 CEST'); + + $input = new FormatTest([ + 'date' => $dateTime, + ]); + + $data = ObjectSerializer::sanitizeForSerialization($input); + + $this->assertEquals($data->date, '1973-04-30'); + } +} diff --git a/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php b/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php index bad55050ece..368b5f6df50 100644 --- a/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php @@ -349,7 +349,6 @@ class PetApiTest extends \PHPUnit_Framework_TestCase $response = $pet_api->uploadFile($pet_id, "test meta", "./composer.json"); // return ApiResponse $this->assertInstanceOf('Swagger\Client\Model\ApiResponse', $response); - } // test get inventory @@ -402,7 +401,6 @@ class PetApiTest extends \PHPUnit_Framework_TestCase $new_pet = new Model\Pet; // the empty object should be serialised to {} $this->assertSame("{}", "$new_pet"); - } // test inheritance in the model @@ -493,6 +491,7 @@ class PetApiTest extends \PHPUnit_Framework_TestCase $pet_host = $pet_api->getApiClient()->getConfig()->getHost(); $this->assertSame($pet_host, $new_default->getHost()); - Configuration::setDefaultConfiguration($orig_default); // Reset to original to prevent failure of other tests that rely on this state + // Reset to original to prevent failure of other tests that rely on this state + Configuration::setDefaultConfiguration($orig_default); } } diff --git a/samples/client/petstore/php/SwaggerClient-php/tests/UserApiTest.php b/samples/client/petstore/php/SwaggerClient-php/tests/UserApiTest.php index a8487e58764..701479bab05 100644 --- a/samples/client/petstore/php/SwaggerClient-php/tests/UserApiTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/tests/UserApiTest.php @@ -29,6 +29,5 @@ class UserApiTest extends \PHPUnit_Framework_TestCase $response, "response string starts with 'logged in user session'" ); - } }