From 40a00520aecce4636ac1526bf3af35337d8d087f Mon Sep 17 00:00:00 2001 From: Ian Lord Date: Tue, 23 Jun 2020 20:49:44 -0400 Subject: [PATCH 1/2] 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) --- .../src/main/resources/php/ObjectSerializer.mustache | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache b/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache index 4b4d39ad6be2..2694de44fe76 100644 --- a/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache +++ b/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache @@ -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) { From ede2150903f9aacaf8b6a1391492e8e7179fb163 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 2 Jul 2020 15:51:45 +0800 Subject: [PATCH 2/2] update samples --- .../petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php b/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php index 1a12604649f8..4c7108c94b6f 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php @@ -262,6 +262,11 @@ public static function deserialize($data, $class, $httpHeaders = null) 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) {