Skip to content

Commit 8f59bfd

Browse files
[php] make ObjectSerializer::toString actually return a string
1 parent 6a77660 commit 8f59bfd

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ class ObjectSerializer
260260
} elseif (is_bool($value)) {
261261
return $value ? 'true' : 'false';
262262
} else {
263-
return $value;
263+
return (string) $value;
264264
}
265265
}
266266

samples/client/petstore/php/OpenAPIClient-php/.openapi-generator/FILES

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ docs/Model/Tag.md
5858
docs/Model/User.md
5959
docs/Model/UserType.md
6060
git_push.sh
61+
lib/ApiException.php
6162
lib/Api/AnotherFakeApi.php
6263
lib/Api/DefaultApi.php
6364
lib/Api/FakeApi.php
6465
lib/Api/FakeClassnameTags123Api.php
6566
lib/Api/PetApi.php
6667
lib/Api/StoreApi.php
6768
lib/Api/UserApi.php
68-
lib/ApiException.php
6969
lib/Configuration.php
7070
lib/HeaderSelector.php
7171
lib/Model/AdditionalPropertiesClass.php

samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public static function toString($value)
269269
} elseif (is_bool($value)) {
270270
return $value ? 'true' : 'false';
271271
} else {
272-
return $value;
272+
return (string) $value;
273273
}
274274
}
275275

samples/client/petstore/php/OpenAPIClient-php/tests/ObjectSerializerTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,4 +334,44 @@ public function provideDeepObjects(): array
334334
],
335335
];
336336
}
337+
338+
/**
339+
* @dataProvider provideToStringInput
340+
*/
341+
public function testToString($input, string $expected): void
342+
{
343+
$result = ObjectSerializer::toString($input);
344+
345+
$this->assertSame($expected, $result);
346+
}
347+
348+
public function provideToStringInput(): array
349+
{
350+
return [
351+
'int' => [
352+
'input' => 1,
353+
'expected' => '1',
354+
],
355+
'int 0' => [
356+
'input' => 0,
357+
'expected' => '0',
358+
],
359+
'false' => [
360+
'input' => false,
361+
'expected' => 'false',
362+
],
363+
'true' => [
364+
'input' => true,
365+
'expected' => 'true',
366+
],
367+
'some string' => [
368+
'input' => 'some string',
369+
'expected' => 'some string',
370+
],
371+
'a date' => [
372+
'input' => new \DateTime('14-04-2022'),
373+
'expected' => '2022-04-14T00:00:00+00:00',
374+
],
375+
];
376+
}
337377
}

0 commit comments

Comments
 (0)