forked from loafle/openapi-generator-original
[PHP] Better handling of invalid data (array) (#6760)
* Update ObjectSerializer.mustache If the $data is a wrongly formatted Json or if data is not an array, php gives error: Invalid argument supplied for foreach() at line 257 (Now line is 262) * update samples Co-authored-by: William Cheng <wing328hk@gmail.com>
This commit is contained in:
@@ -252,6 +252,11 @@ class ObjectSerializer
|
||||
return null;
|
||||
} elseif (strcasecmp(substr($class, -2), '[]') === 0) {
|
||||
$data = is_string($data) ? json_decode($data) : $data;
|
||||
|
||||
if (!is_array($data)) {
|
||||
throw new \InvalidArgumentException("Invalid array '$class'");
|
||||
}
|
||||
|
||||
$subClass = substr($class, 0, -2);
|
||||
$values = [];
|
||||
foreach ($data as $key => $value) {
|
||||
|
||||
@@ -262,6 +262,11 @@ class ObjectSerializer
|
||||
return null;
|
||||
} elseif (strcasecmp(substr($class, -2), '[]') === 0) {
|
||||
$data = is_string($data) ? json_decode($data) : $data;
|
||||
|
||||
if (!is_array($data)) {
|
||||
throw new \InvalidArgumentException("Invalid array '$class'");
|
||||
}
|
||||
|
||||
$subClass = substr($class, 0, -2);
|
||||
$values = [];
|
||||
foreach ($data as $key => $value) {
|
||||
|
||||
Reference in New Issue
Block a user