diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..9f11b755 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ diff --git a/src/ObjectSerializer.php b/src/ObjectSerializer.php index 8f0a7cf8..4961cdc7 100644 --- a/src/ObjectSerializer.php +++ b/src/ObjectSerializer.php @@ -79,7 +79,7 @@ public static function sanitizeForSerialization($data) * * @return string the sanitized filename */ - public function sanitizeFilename($filename) + public static function sanitizeFilename($filename) { if (preg_match("/.*[\/\\\\](.*)$/", $filename, $match)) { return $match[1]; @@ -251,14 +251,17 @@ public static function deserialize($data, $class, $httpHeaders = null) } else { return null; } - } elseif (in_array($class, ['DateTime', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true)) { + } elseif ($class === 'DateTime' || in_array(strtolower($class), ['bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true)) { + if ($class !== 'DateTime') { + $class = strtolower($class); + } settype($data, $class); return $data; } elseif ($class === '\SplFileObject') { // determine file name if (array_key_exists('Content-Disposition', $httpHeaders) && preg_match('/inline; filename=[\'"]?([^\'"\s]+)[\'"]?$/i', $httpHeaders['Content-Disposition'], $match)) { - $filename = Configuration::getDefaultConfiguration()->getTempFolderPath() . sanitizeFilename($match[1]); + $filename = Configuration::getDefaultConfiguration()->getTempFolderPath() . self::sanitizeFilename($match[1]); } else { $filename = tempnam(Configuration::getDefaultConfiguration()->getTempFolderPath(), ''); } @@ -269,7 +272,7 @@ public static function deserialize($data, $class, $httpHeaders = null) } return $deserialized; - } else { + } elseif (class_exists($class)) { // If a discriminator is defined and points to a valid subclass, use it. $discriminator = $class::DISCRIMINATOR; if (!empty($discriminator) && isset($data->{$discriminator}) && is_string($data->{$discriminator})) { @@ -292,6 +295,11 @@ public static function deserialize($data, $class, $httpHeaders = null) } } return $instance; + } else { + throw new ApiException( + "Invalid form field type `" . $class . "` found.", + 400 + ); } } }