Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PHP] Bugfix: DateTime object on query #13583

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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