Skip to content

[BUG][kotlin][client][okhttp4] non-file parts are serialized as the string without Content-Type in multipart/form-data (variant of #7658 / #11289) #11910

@koscejev

Description

@koscejev

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

Most of the investigation of this bug is based on code (including checking the latest master). The relevant code is still the same in latest master, so I didn't explicitly verify it.

I will provide PR with actual fix for at least the "okhttp4" and "okhttp3" libraries. The fix is verified on our project. Perhaps others can improve upon the fix to allow other libraries to handle this properly too.

openapi-generator version

5.4.0

OpenAPI declaration file content or url

Just for the reference, this is how our multipart request is defined (used to verify the fix). We don't actually have the encoding section, since it's supposed to default to "application/json" anyway, but I have verified it works with this section defined:

requestBody:
  required: true
  content:
    multipart/form-data:
      schema:
        type: object
        required:
          - interaction
        properties:
          interaction:
            $ref: '#/components/schemas/InteractionWithRelatedDataDto'
          media:
            type: array
            items:
              type: string
              format: binary
      encoding:
        interaction:
          contentType: application/json
Generation Details

We're generating code using the following settings:

  • skipFormModel = false
  • library = jvm-okhttp4
  • serializationLibrary = jackson
  • enumPropertyNaming = UPPERCASE
Steps to reproduce
  1. Generate client code based on OpenApi 3 spec with multipart request as defined above.
  2. Send the corresponding request
  3. Notice the request correctly has "Content-Type" header with value starting with "multipart/form-data"
  4. Notice the request is incorrectly missing "Content-Type" header for all parts
  5. Notice the request incorrectly contains the first part serialized via toString() instead of JSON
Related issues/PRs

PR: #11911
Related: #7658 and #11289
Also, #5284 is related, but seems to be outdated, since it works in 5.4.0 - maybe close it?

Suggest a fix

See PR above.

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