Commit 561e5bf
authored
[kotlin][jvm-okhttp4] Fix multipart/form-data with JSON content-type (#22856)
* [kotlin][jvm-okhttp4] Fix multipart/form-data with JSON content-type
Fixes #16457
Fixes two critical bugs in multipart/form-data handling when parts
have Content-Type application/json:
1. IllegalArgumentException: OkHttp throws "Unexpected header: Content-Type"
because Content-Type was passed in headers map instead of via
asRequestBody(mediaType)/toRequestBody(mediaType) parameter.
2. Invalid JSON serialization: Non-file parts with application/json
Content-Type were serialized using toString() instead of proper
JSON serialization, producing invalid output like:
"MyObject(field1=value, field2=123)" instead of
'{"field1":"value","field2":123}'
Changes:
- Filter Content-Type from headers before passing to OkHttp
- Check part Content-Type and use appropriate serializer (JSON vs toString)
- Add integration tests with echo server to verify fix
- Support all serialization libraries (gson, moshi, jackson, kotlinx)
Fixes issues with multipart endpoints that mix file uploads with
JSON metadata, common in REST APIs for document/image uploads.
* Run mvn clean/package, and regenerate samples
* Add fix for kotlinx serialisation issue
* Refactor multipart helpers for reified type parameter support
* Fix kotlinx.serialization multipart by adding serializer lambda to PartConfig
* Fix internal Ktor API usage in multipart forms1 parent 9547ebd commit 561e5bf
File tree
125 files changed
+3885
-331
lines changed- .github/workflows
- modules/openapi-generator/src
- main/resources/kotlin-client
- infrastructure
- libraries
- jvm-okhttp
- infrastructure
- multiplatform
- test/resources/3_0/kotlin
- samples/client
- echo_api
- kotlin-jvm-okhttp-multipart-json
- .openapi-generator
- docs
- gradle/wrapper
- src
- main/kotlin/org/openapitools/client
- apis
- infrastructure
- models
- test/kotlin/org/openapitools/client
- apis
- models
- kotlin-jvm-okhttp/src/main/kotlin/org/openapitools/client/infrastructure
- kotlin-jvm-spring-3-restclient/src/main/kotlin/org/openapitools/client/infrastructure
- kotlin-jvm-spring-3-webclient/src/main/kotlin/org/openapitools/client/infrastructure
- others
- kotlin-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure
- kotlin-jvm-okhttp-non-ascii-headers/src/main/kotlin/org/openapitools/client/infrastructure
- kotlin-jvm-okhttp-parameter-tests/src/main/kotlin/org/openapitools/client/infrastructure
- kotlin-jvm-okhttp-path-comments/src/main/kotlin/org/openapitools/client/infrastructure
- petstore
- kotlin-allOf-discriminator-kotlinx-serialization
- docs
- src
- main/kotlin/org/openapitools/client
- apis
- infrastructure
- test/kotlin/org/openapitools/client/infrastructure
- kotlin-allOf-discriminator/src/main/kotlin/org/openapitools/client/infrastructure
- kotlin-array-integer-enum/src/main/kotlin/org/openapitools/client/infrastructure
- kotlin-array-simple-string-jvm-okhttp4
- src/main/kotlin/org/openapitools/client/infrastructure
- kotlin-array-simple-string-multiplatform/src/commonMain/kotlin/org/openapitools/client
- apis
- infrastructure
- kotlin-bigdecimal-default-multiplatform/src/commonMain/kotlin/org/openapitools/client
- apis
- infrastructure
- kotlin-bigdecimal-default-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure
- kotlin-default-values-jvm-okhttp4/src/main/kotlin/org/openapitools/client/infrastructure
- kotlin-default-values-multiplatform/src/commonMain/kotlin/org/openapitools/client
- apis
- infrastructure
- kotlin-enum-default-value/src/main/kotlin/org/openapitools/client/infrastructure
- kotlin-explicit/src/main/kotlin/org/openapitools/client/infrastructure
- kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure
- kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure
- kotlin-json-request-string/src/main/kotlin/org/openapitools/client
- apis
- infrastructure
- kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure
- kotlin-jvm-spring-2-webclient/src/main/kotlin/org/openapitools/client/infrastructure
- kotlin-jvm-spring-3-restclient/src/main/kotlin/org/openapitools/client/infrastructure
- kotlin-jvm-spring-3-webclient/src/main/kotlin/org/openapitools/client/infrastructure
- kotlin-kotlinx-datetime/src/main/kotlin/org/openapitools/client/infrastructure
- kotlin-modelMutable/src/main/kotlin/org/openapitools/client/infrastructure
- kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure
- kotlin-multiplatform-allOf-discriminator
- docs
- src/commonMain/kotlin/org/openapitools/client
- apis
- infrastructure
- kotlin-multiplatform-kotlinx-datetime/src/commonMain/kotlin/org/openapitools/client
- apis
- infrastructure
- kotlin-multiplatform/src/commonMain/kotlin/org/openapitools/client
- apis
- infrastructure
- kotlin-name-parameter-mappings/src/main/kotlin/org/openapitools/client/infrastructure
- kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure
- kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure
- kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure
- kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure
- kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client
- apis
- infrastructure
- kotlin/src/main/kotlin/org/openapitools/client/infrastructure
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
125 files changed
+3885
-331
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
229 | 229 | | |
230 | 230 | | |
231 | 231 | | |
| 232 | + | |
232 | 233 | | |
| 234 | + | |
233 | 235 | | |
234 | 236 | | |
235 | 237 | | |
| |||
Lines changed: 9 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
7 | 14 | | |
8 | 15 | | |
9 | 16 | | |
10 | | - | |
| 17 | + | |
| 18 | + | |
11 | 19 | | |
Lines changed: 4 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
49 | 52 | | |
50 | 53 | | |
51 | 54 | | |
| |||
199 | 202 | | |
200 | 203 | | |
201 | 204 | | |
202 | | - | |
| 205 | + | |
203 | 206 | | |
204 | 207 | | |
205 | 208 | | |
| |||
Lines changed: 64 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
118 | 137 | | |
119 | 138 | | |
120 | 139 | | |
| |||
127 | 146 | | |
128 | 147 | | |
129 | 148 | | |
130 | | - | |
131 | | - | |
132 | 149 | | |
133 | 150 | | |
134 | | - | |
| 151 | + | |
135 | 152 | | |
136 | 153 | | |
137 | 154 | | |
138 | 155 | | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
139 | 191 | | |
140 | 192 | | |
141 | 193 | | |
| |||
144 | 196 | | |
145 | 197 | | |
146 | 198 | | |
| 199 | + | |
147 | 200 | | |
148 | 201 | | |
149 | 202 | | |
150 | | - | |
151 | | - | |
152 | | - | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
153 | 207 | | |
154 | | - | |
155 | | - | |
| 208 | + | |
| 209 | + | |
156 | 210 | | |
157 | 211 | | |
158 | 212 | | |
| |||
174 | 228 | | |
175 | 229 | | |
176 | 230 | | |
177 | | - | |
| 231 | + | |
178 | 232 | | |
179 | 233 | | |
180 | 234 | | |
181 | | - | |
| 235 | + | |
182 | 236 | | |
183 | 237 | | |
184 | 238 | | |
| |||
Lines changed: 26 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
14 | 18 | | |
15 | 19 | | |
16 | 20 | | |
| |||
76 | 80 | | |
77 | 81 | | |
78 | 82 | | |
79 | | - | |
| 83 | + | |
80 | 84 | | |
81 | 85 | | |
82 | 86 | | |
83 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
84 | 108 | | |
85 | 109 | | |
86 | 110 | | |
| |||
Lines changed: 69 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
Lines changed: 29 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
33 | 62 | | |
34 | 63 | | |
35 | 64 | | |
| |||
Lines changed: 23 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
Lines changed: 24 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
0 commit comments