From 6a18b5c5cbbd5fcfb3ecd8f469a5bff0148c8008 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20=C4=8Cern=C3=BD?= Date: Tue, 24 Jun 2025 13:45:11 +0200 Subject: [PATCH 1/2] php-nextgen - Fix flatten() to support arrays of files in multipart/form-data Previously, FormDataProcessor::flatten() unconditionally passed all values through ObjectSerializer::toString(), which caused an error when flattening arrays containing file resources (e.g. for OpenAPI multipart/form-data definitions with `type: array`, `items: type: string, format: binary`). This change adds a check for is_resource() to preserve stream handles without serialization, ensuring correct behavior when uploading multiple files in a single request. --- .../main/resources/php-nextgen/FormDataProcessor.mustache | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/resources/php-nextgen/FormDataProcessor.mustache b/modules/openapi-generator/src/main/resources/php-nextgen/FormDataProcessor.mustache index ad9808c4ab12..4f73458ecf81 100644 --- a/modules/openapi-generator/src/main/resources/php-nextgen/FormDataProcessor.mustache +++ b/modules/openapi-generator/src/main/resources/php-nextgen/FormDataProcessor.mustache @@ -104,7 +104,11 @@ class FormDataProcessor $currentName .= $currentSuffix; } - $result[$currentName] = ObjectSerializer::toString($val); + if (is_resource($val)) { + $result[$currentName] = $val; + } else { + $result[$currentName] = ObjectSerializer::toString($val); + } } $currentName = $start; From ae801eae635d35caaa6cb6c17d2926f527a20492 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20=C4=8Cern=C3=BD?= Date: Thu, 26 Jun 2025 23:58:21 +0200 Subject: [PATCH 2/2] php-nextgen - Fix flatten() to support arrays of files in multipart/form-data - samples --- .../php-nextgen-streaming/src/FormDataProcessor.php | 6 +++++- .../client/echo_api/php-nextgen/src/FormDataProcessor.php | 6 +++++- .../php-nextgen/OpenAPIClient-php/src/FormDataProcessor.php | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/samples/client/echo_api/php-nextgen-streaming/src/FormDataProcessor.php b/samples/client/echo_api/php-nextgen-streaming/src/FormDataProcessor.php index 4699219af6ba..402f90c0c586 100644 --- a/samples/client/echo_api/php-nextgen-streaming/src/FormDataProcessor.php +++ b/samples/client/echo_api/php-nextgen-streaming/src/FormDataProcessor.php @@ -114,7 +114,11 @@ public static function flatten(array $source, string $start = ''): array $currentName .= $currentSuffix; } - $result[$currentName] = ObjectSerializer::toString($val); + if (is_resource($val)) { + $result[$currentName] = $val; + } else { + $result[$currentName] = ObjectSerializer::toString($val); + } } $currentName = $start; diff --git a/samples/client/echo_api/php-nextgen/src/FormDataProcessor.php b/samples/client/echo_api/php-nextgen/src/FormDataProcessor.php index 4699219af6ba..402f90c0c586 100644 --- a/samples/client/echo_api/php-nextgen/src/FormDataProcessor.php +++ b/samples/client/echo_api/php-nextgen/src/FormDataProcessor.php @@ -114,7 +114,11 @@ public static function flatten(array $source, string $start = ''): array $currentName .= $currentSuffix; } - $result[$currentName] = ObjectSerializer::toString($val); + if (is_resource($val)) { + $result[$currentName] = $val; + } else { + $result[$currentName] = ObjectSerializer::toString($val); + } } $currentName = $start; diff --git a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/FormDataProcessor.php b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/FormDataProcessor.php index ea0897ce17fa..c6a2a185bf3a 100644 --- a/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/FormDataProcessor.php +++ b/samples/client/petstore/php-nextgen/OpenAPIClient-php/src/FormDataProcessor.php @@ -113,7 +113,11 @@ public static function flatten(array $source, string $start = ''): array $currentName .= $currentSuffix; } - $result[$currentName] = ObjectSerializer::toString($val); + if (is_resource($val)) { + $result[$currentName] = $val; + } else { + $result[$currentName] = ObjectSerializer::toString($val); + } } $currentName = $start;