swagger-api / swagger-api/swagger-codegen

[JavaSpring] @MultiParam generated for multipart/form-data part with complex data instead of @MultiPart

Open
#10,007 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

When the OpenAPI 3.0 YAML definition contains a multipart/form-data with a part referencing a complex schema, then the generated server-side interface defines a @MultiParam for the given part instead of a @MultiPart.

Swagger-codegen version

3.0.16

Swagger declaration file content or url
openapi: 3.0.0
info:
  version: "0.1"
paths:
  /testbug/:
    post:
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                firstPart:
                  $ref: "#/components/schemas/MyInput"
                secondPart:
                  type: string
                  format: binary
      responses:
        "200":
          description: OK
components:
  schemas:
    MyInput:
      type: object
      properties:
        myInputField:
          type: string
Command line used for generation

java -jar swagger-codegen-cli-3.0.16.jar generate -l spring -o output -i swagger.yaml

Steps to reproduce

Run above command on above OpenAPI 3.0 YAML content and check generated file output/src/main/java/io/swagger/api/TestbugApi.java

Related issues/PRs

None.

Suggest a fix/enhancement

Root cause seems bug in resource handlebars/JavaSpring/formParams.mustache in swagger-codegen-generators-1.0.16.jar.

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

Run the reported swagger-codegen CLI command with the supplied OpenAPI YAML and inspect output/src/main/java/io/swagger/api/TestbugApi.java. Then read resource handlebars/JavaSpring/formParams.mustache to trace how the complex multipart part is rendered. Done means the generated interface uses @MultiPart for firstPart instead of @MultiParam.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, spring
Domain
backend, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.