Skip to content

Commit b444de2

Browse files
php-nextgen - Fix flatten() to support arrays of files (#21458)
* 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. * php-nextgen - Fix flatten() to support arrays of files in multipart/form-data - samples
1 parent d0327b2 commit b444de2

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

modules/openapi-generator/src/main/resources/php-nextgen/FormDataProcessor.mustache

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,11 @@ class FormDataProcessor
104104
$currentName .= $currentSuffix;
105105
}
106106

107-
$result[$currentName] = ObjectSerializer::toString($val);
107+
if (is_resource($val)) {
108+
$result[$currentName] = $val;
109+
} else {
110+
$result[$currentName] = ObjectSerializer::toString($val);
111+
}
108112
}
109113

110114
$currentName = $start;

samples/client/echo_api/php-nextgen-streaming/src/FormDataProcessor.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ public static function flatten(array $source, string $start = ''): array
114114
$currentName .= $currentSuffix;
115115
}
116116

117-
$result[$currentName] = ObjectSerializer::toString($val);
117+
if (is_resource($val)) {
118+
$result[$currentName] = $val;
119+
} else {
120+
$result[$currentName] = ObjectSerializer::toString($val);
121+
}
118122
}
119123

120124
$currentName = $start;

samples/client/echo_api/php-nextgen/src/FormDataProcessor.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ public static function flatten(array $source, string $start = ''): array
114114
$currentName .= $currentSuffix;
115115
}
116116

117-
$result[$currentName] = ObjectSerializer::toString($val);
117+
if (is_resource($val)) {
118+
$result[$currentName] = $val;
119+
} else {
120+
$result[$currentName] = ObjectSerializer::toString($val);
121+
}
118122
}
119123

120124
$currentName = $start;

samples/client/petstore/php-nextgen/OpenAPIClient-php/src/FormDataProcessor.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,11 @@ public static function flatten(array $source, string $start = ''): array
113113
$currentName .= $currentSuffix;
114114
}
115115

116-
$result[$currentName] = ObjectSerializer::toString($val);
116+
if (is_resource($val)) {
117+
$result[$currentName] = $val;
118+
} else {
119+
$result[$currentName] = ObjectSerializer::toString($val);
120+
}
117121
}
118122

119123
$currentName = $start;

0 commit comments

Comments
 (0)