Skip to content

[BUG] [kotlin] [okhttp4] generator for kotlin client with okhttp4 doesn't correctly serialize object part for multipart/form-data #16457

@Fynnyan

Description

@Fynnyan

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

Setting:
openapi generator with maven, generate client with generator kotlin, and the okhttp4 and jackson libraries

When useing the generator the generate a kotlin client for a multipart/form-data request that has a part json and a part file,
the generated code doesn't serialize the object to json.

That part has no Content-Type definition and the body is the toString() output of the object

Here a spring boot project to reproduce the issue: https://github.com/Fynnyan/kotlin-okhhtp-open-api-bug/tree/main
It contains, generator configs, spec and a test to showcase the issue.

payload of the generated client:

Content-Disposition: form-data; name="metadata"
Content-Length: 39
Metadata([email protected], locale=en)
--4975a2aa-2415-4a44-9231-a6c74e59088a
Content-Disposition: form-data; name="report"; filename="report-5cc1c8cf-9780-4268-b0dd-cc57c1b7a45c270820599018655007.xml"
Content-Type: application/xml
Content-Length: 83

<?xml version="1.0" encoding="UTF-8" ?>
<body>
    <value>Some Text</value>
</body>
--4975a2aa-2415-4a44-9231-a6c74e59088a--

expected payload:

Content-Disposition: form-data; name="metadata"
Content-Type: application/json

{ "email": "[email protected]" "locale": "en" }
--4975a2aa-2415-4a44-9231-a6c74e59088a
Content-Disposition: form-data; name="report"; filename="report-5cc1c8cf-9780-4268-b0dd-cc57c1b7a45c270820599018655007.xml"
Content-Type: application/xml
Content-Length: 83

<?xml version="1.0" encoding="UTF-8" ?>
<body>
    <value>Some Text</value>
</body>
--4975a2aa-2415-4a44-9231-a6c74e59088a--
openapi-generator version

On our project we currently use 6.4.0 but also the later versions have the issue.

Checked the following versions:

  • 6.4.0
  • 6.6.0
  • 7.0.0
OpenAPI declaration file content or url

https://github.com/Fynnyan/kotlin-okhhtp-open-api-bug/blob/main/src/main/resources/spec-for-client-generation.yaml

Generation Details

generator: kotlin
library: jvm-okhttp4
serializationLibrary: jackson

For more details see the config in the reprducer project.
mvn plugin config: https://github.com/Fynnyan/kotlin-okhhtp-open-api-bug/blob/main/pom.xml#L63-L94

Steps to reproduce

checkout the project: https://github.com/Fynnyan/kotlin-okhhtp-open-api-bug/tree/main

run ./mvnw test, there is a test that prints the request to console for inspection

or at least ./mvnw compile to generate the client code

Related issues/PRs
Suggest a fix

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions