diff --git a/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache b/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache index 350c377dc4cd..3fbeb24abc44 100644 --- a/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache +++ b/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache @@ -260,7 +260,7 @@ class ObjectSerializer } elseif (is_bool($value)) { return $value ? 'true' : 'false'; } else { - return $value; + return (string) $value; } } diff --git a/samples/client/petstore/php/OpenAPIClient-php/.openapi-generator/FILES b/samples/client/petstore/php/OpenAPIClient-php/.openapi-generator/FILES index c41da42e1fca..cb323a922299 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/.openapi-generator/FILES +++ b/samples/client/petstore/php/OpenAPIClient-php/.openapi-generator/FILES @@ -59,6 +59,7 @@ docs/Model/SpecialModelName.md docs/Model/Tag.md docs/Model/User.md git_push.sh +lib/ApiException.php lib/Api/AnotherFakeApi.php lib/Api/DefaultApi.php lib/Api/FakeApi.php @@ -66,7 +67,6 @@ lib/Api/FakeClassnameTags123Api.php lib/Api/PetApi.php lib/Api/StoreApi.php lib/Api/UserApi.php -lib/ApiException.php lib/Configuration.php lib/HeaderSelector.php lib/Model/AdditionalPropertiesClass.php diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php b/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php index 927998508d93..599da5492da8 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php @@ -269,7 +269,7 @@ public static function toString($value) } elseif (is_bool($value)) { return $value ? 'true' : 'false'; } else { - return $value; + return (string) $value; } } diff --git a/samples/client/petstore/php/OpenAPIClient-php/tests/ObjectSerializerTest.php b/samples/client/petstore/php/OpenAPIClient-php/tests/ObjectSerializerTest.php index 64487202dd1a..2d41d9e726e8 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/tests/ObjectSerializerTest.php +++ b/samples/client/petstore/php/OpenAPIClient-php/tests/ObjectSerializerTest.php @@ -334,4 +334,44 @@ public function provideDeepObjects(): array ], ]; } + + /** + * @dataProvider provideToStringInput + */ + public function testToString($input, string $expected): void + { + $result = ObjectSerializer::toString($input); + + $this->assertSame($expected, $result); + } + + public function provideToStringInput(): array + { + return [ + 'int' => [ + 'input' => 1, + 'expected' => '1', + ], + 'int 0' => [ + 'input' => 0, + 'expected' => '0', + ], + 'false' => [ + 'input' => false, + 'expected' => 'false', + ], + 'true' => [ + 'input' => true, + 'expected' => 'true', + ], + 'some string' => [ + 'input' => 'some string', + 'expected' => 'some string', + ], + 'a date' => [ + 'input' => new \DateTime('14-04-2022'), + 'expected' => '2022-04-14T00:00:00+00:00', + ], + ]; + } }