OpenAPITools / OpenAPITools/openapi-generator
[kotlin][retrofit] UUID parameters in multipart/formdata are incorrectly encoded as JSON
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
This generates the following interface:
@Multipart
@POST("v1/receipt")
suspend fun v1ReceiptPost(@Part("id") id: java.util.UUID, @Header("Accept-Language") acceptLanguage: kotlin.String? = de-DE, @Part documents: MultipartBody.Part? = null): Response<Receipt>
Which is ok (except for the enum bug, which is another issue, just add "" around de-DE).
actual result
However, when i send a request, i get the following HTTP Post body:
I/okhttp.OkHttpClient: Content-Disposition: form-data; name="id"
I/okhttp.OkHttpClient: Content-Transfer-Encoding: binary
I/okhttp.OkHttpClient: Content-Type: application/json; charset=UTF-8
I/okhttp.OkHttpClient: Content-Length: 38
I/okhttp.OkHttpClient:
I/okhttp.OkHttpClient: "09446045-818b-4b32-96d3-61bdfdd0f257"
The id field is encoded as application/json, which is wrong according to OpenApi Spec: https://swagger.io/docs/specification/describing-request-body/multipart-requests/
expected result
The above swagger page actually has an example:
id: # Part 1 (string value)
type: string
format: uuid
which should produce, according to the web page:
Content-Disposition: form-data; name="id"
Content-Type: text/plain
123e4567-e89b-12d3-a456-426655440000
openapi-generator version
6.0.1
OpenAPI declaration file content or url
Test spec to reproduce this error:
https://gist.github.com/kalinjul/9d69267fa17ee4eb494f861d8cddb84f
config json: https://gist.github.com/kalinjul/5a74d7224afb04ef4efec5304e612062
Steps to reproduce
Related issues/PRs
Suggest a fix
Retrofit is configured to use it's MoshiConverter, because it sees the the format "UUID". Instead, it should see type: string and just use a ScalarConverter(?).
When i register a custom ScalarConverter for UUID before the default MoshiConverter is registered, it works as expected.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by generating the Kotlin Retrofit client from the linked test spec and configuration, then inspect how the UUID multipart parameter selects the MoshiConverter versus a ScalarConverter. Compare the request body with the issue's actual and expected examples; done means the UUID part is emitted as a plain text value rather than JSON.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100