Commit f6b457a
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 #180941 parent 165465a commit f6b457a
1 file changed
Lines changed: 7 additions & 0 deletions
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
66 | 72 | | |
| 73 | + | |
67 | 74 | | |
68 | 75 | | |
69 | 76 | | |
| |||
0 commit comments