Skip to content

Commit ef44271

Browse files
thomasphansenJayAtOC
authored andcommitted
[PHP] Bugfix: DateTime object on query (OpenAPITools#13583)
* [PHP] BUGFIX: fix code breaking when query params contain a DateTime object * [PHP] Autogenerated files
1 parent 8a1d445 commit ef44271

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

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

+5
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ class ObjectSerializer
180180
}
181181
}
182182
183+
# Handle DateTime objects in query
184+
if($openApiType === "\\DateTime" && $value instanceof \DateTime) {
185+
return ["{$paramName}" => $value->format(self::$dateTimeFormat)];
186+
}
187+
183188
$query = [];
184189
$value = (in_array($openApiType, ['object', 'array'], true)) ? (array)$value : $value;
185190

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

+5
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ public static function toQueryValue(
189189
}
190190
}
191191

192+
# Handle DateTime objects in query
193+
if($openApiType === "\\DateTime" && $value instanceof \DateTime) {
194+
return ["{$paramName}" => $value->format(self::$dateTimeFormat)];
195+
}
196+
192197
$query = [];
193198
$value = (in_array($openApiType, ['object', 'array'], true)) ? (array)$value : $value;
194199

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

+9
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,15 @@ public function provideQueryParams(): array
327327
true,
328328
'filter%5Bor%5D%5B0%5D%5Bname%5D=John&filter%5Bor%5D%5B1%5D%5Bemail%5D=john%40doe.com'
329329
],
330+
'form DateTime object, explode on, required true' => [
331+
new DateTime('2021-10-06T20:17:16'), 'dateTime', '\DateTime', 'form', true, true, 'dateTime=2021-10-06T20%3A17%3A16%2B00%3A00',
332+
],
333+
'form null DateTime object, explode on, required true' => [
334+
null, 'dateTime', '\DateTime', 'form', true, true, 'dateTime=',
335+
],
336+
'form null DateTime object, explode on, required false' => [
337+
null, 'dateTime', '\DateTime', 'form', true, false, '',
338+
],
330339
];
331340
}
332341

0 commit comments

Comments
 (0)