[php] enhance type mapping (#10457)

* map BigDecimal to float

* enhance type mapping in php generators

* update tests

* update doc, samples

* remove primitive types from phpdt, mezzio
This commit is contained in:
William Cheng
2021-09-25 12:09:34 +08:00
committed by GitHub
parent be3bd2e6c7
commit c9047a6faa
21 changed files with 58 additions and 28 deletions

View File

@@ -86,7 +86,7 @@ class ObjectSerializer
foreach ($data::openAPITypes() as $property => $openAPIType) {
$getter = $data::getters()[$property];
$value = $data->$getter();
if ($value !== null && !in_array($openAPIType, ['DateTime', 'array', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true)) {
if ($value !== null && !in_array($openAPIType, ['\DateTime', '\SplFileObject', 'array', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true)) {
$callable = [$openAPIType, 'getAllowableEnumValues'];
if (is_callable($callable)) {
/** array $callable */
@@ -330,7 +330,7 @@ class ObjectSerializer
}
/** @psalm-suppress ParadoxicalCondition */
if (in_array($class, ['DateTime', 'array', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true)) {
if (in_array($class, ['\DateTime', '\SplFileObject', 'array', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true)) {
settype($data, $class);
return $data;
}