Skip to content

Commit f6b457a

Browse files
authored
[kotlin] Fix jvm-ktor multipart formData for array of file uploads (#23297)
When a multipart/form-data endpoint has an array of binary file parameters, the generated code calls `append(files)` with the entire List<FormPart<InputProvider>> instead of iterating over each element. This causes a compilation error: "Argument type mismatch: actual type is 'List<FormPart<InputProvider>>', but 'FormPart<T>' was expected" The root cause is that the `{{#isFile}}` block in the jvm-ktor api.mustache template does not check for `{{#isArray}}`. When `isFile` is true, the template unconditionally emits a single `append(paramName)` call. The `{{#isArray}}` block that would iterate is nested inside `{{^isFile}}`, so it is never reached for file parameters. PR #21056 (v7.13.0) correctly fixed the data type in the method signature (`List<FormPart<InputProvider>>`), but did not update the formData body to iterate over array file parameters. This fix adds an `{{#isArray}}`/`{{^isArray}}` check inside the `{{#isFile}}` block so that: - Single file params: `paramName?.apply { append(paramName) }` - Array file params: `for (x in paramName ?: listOf()) { append(x) }` Fixes #18094
1 parent 165465a commit f6b457a

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

  • modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-ktor

modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-ktor/api.mustache

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,14 @@ import com.fasterxml.jackson.databind.ObjectMapper
6363
formData {
6464
{{#formParams}}
6565
{{#isFile}}
66+
{{#isArray}}
67+
for (x in {{{paramName}}} ?: listOf()) {
68+
append(x)
69+
}
70+
{{/isArray}}
71+
{{^isArray}}
6672
{{{paramName}}}?.apply { append({{{paramName}}}) }
73+
{{/isArray}}
6774
{{/isFile}}
6875
{{^isFile}}
6976
{{^isArray}}

0 commit comments

Comments
 (0)