OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Kotlin] Bug generating array of files multipart

Open
#14,453 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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

When generating API code using kotlin, with the use of the jvm-retrofit2 library. An issue occurs when generating code for an array of files. What it generates:

    @Multipart
    @POST("api/Example/Send")
    fun messagesSend(@Part attachments: MultipartBody.Part? = null): Completable

What is expected and works with the actual backend implementation

    @Multipart
    @POST("api/Example/Send")
    fun messagesSend(@Part attachments: Array<MultipartBody.Part?>? = null): Completable

It doesn't generate the attachments as a list, this way only 1 attachment can be uploaded. Api specification also includes that it should be an array.

openapi-generator version

6.2.1

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: Example.API
  version: v1
paths:
  /api/Example/Send:
    post:
      tags:
        - Example
      operationId: SendExample
      requestBody:
        content:
          multipart/form-data:
            schema:
              required:
                - Content
                - Title
              type: object
              properties:
                attachments:
                  type: array
                  items:
                    type: string
                    format: binary
                  nullable: true
            encoding:
              attachments:
                style: form
      responses:
        '200':
          description: Success
Generation Details

Complete config

openApiGenerate {
    generatorName = "kotlin"
    library = "jvm-retrofit2"
    configOptions = [
            useRxJava3: "true",
            serializationLibrary: "gson",
            artifactId: "api-client",
            serializableModel: "true"
    ]
}
Steps to reproduce

I created an example repository for this issue. After running the gradle task: 'openApiGenerate' it will generate the OpenApi code, where you will see that it generates a single item as previously stated.
https://github.com/StijnAppec/OpenApiMultipartIssue

Suggest a fix

Solution would be that it generates the signature so that it includes a list of multipart part's. Instead of a single one.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the linked example repository and the Gradle openApiGenerate task using the Kotlin jvm-retrofit2 configuration. Compare the generated multipart method with the OpenAPI declaration's array of binary attachments; done means the generated client signature preserves multiple multipart parts.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.