Skip to content

Commit

Permalink
[PHP] Bugfix: DateTime object on query (OpenAPITools#13583)
Browse files Browse the repository at this point in the history
* [PHP] BUGFIX: fix code breaking when query params contain a DateTime object

* [PHP] Autogenerated files
  • Loading branch information
thomasphansen authored and JayAtOC committed Oct 6, 2022
1 parent 8a1d445 commit ef44271
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ class ObjectSerializer
}
}
# Handle DateTime objects in query
if($openApiType === "\\DateTime" && $value instanceof \DateTime) {
return ["{$paramName}" => $value->format(self::$dateTimeFormat)];
}
$query = [];
$value = (in_array($openApiType, ['object', 'array'], true)) ? (array)$value : $value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ public static function toQueryValue(
}
}

# Handle DateTime objects in query
if($openApiType === "\\DateTime" && $value instanceof \DateTime) {
return ["{$paramName}" => $value->format(self::$dateTimeFormat)];
}

$query = [];
$value = (in_array($openApiType, ['object', 'array'], true)) ? (array)$value : $value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,15 @@ public function provideQueryParams(): array
true,
'filter%5Bor%5D%5B0%5D%5Bname%5D=John&filter%5Bor%5D%5B1%5D%5Bemail%5D=john%40doe.com'
],
'form DateTime object, explode on, required true' => [
new DateTime('2021-10-06T20:17:16'), 'dateTime', '\DateTime', 'form', true, true, 'dateTime=2021-10-06T20%3A17%3A16%2B00%3A00',
],
'form null DateTime object, explode on, required true' => [
null, 'dateTime', '\DateTime', 'form', true, true, 'dateTime=',
],
'form null DateTime object, explode on, required false' => [
null, 'dateTime', '\DateTime', 'form', true, false, '',
],
];
}

Expand Down

0 comments on commit ef44271

Please sign in to comment.