forked from loafle/openapi-generator-original
Handle empty date-time gracefully
Some API's return an invalid, empty string as a date-time property. DateTime::__construct() will return the current time for empty input which is probably not what is meant. The invalid empty string is probably to be interpreted as a missing field/value. Let's handle this graceful.
This commit is contained in:
parent
3147061345
commit
65b78f7ffe
@ -245,7 +245,17 @@ class ObjectSerializer
|
|||||||
settype($data, 'array');
|
settype($data, 'array');
|
||||||
$deserialized = $data;
|
$deserialized = $data;
|
||||||
} elseif ($class === '\DateTime') {
|
} elseif ($class === '\DateTime') {
|
||||||
|
// Some API's return an invalid, empty string as a
|
||||||
|
// date-time property. DateTime::__construct() will return
|
||||||
|
// the current time for empty input which is probably not
|
||||||
|
// what is meant. The invalid empty string is probably to
|
||||||
|
// be interpreted as a missing field/value. Let's handle
|
||||||
|
// this graceful.
|
||||||
|
if (!empty($data)) {
|
||||||
$deserialized = new \DateTime($data);
|
$deserialized = new \DateTime($data);
|
||||||
|
} else {
|
||||||
|
$deserialized = null;
|
||||||
|
}
|
||||||
} elseif (in_array($class, array({{&primitives}}))) {
|
} elseif (in_array($class, array({{&primitives}}))) {
|
||||||
settype($data, $class);
|
settype($data, $class);
|
||||||
$deserialized = $data;
|
$deserialized = $data;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user