swagger-api / swagger-api/swagger-codegen

[JAVA] Serialization of parts of multipart request bodies

Open
#9,139 9 comments 6 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

I am using the Swagger Codegen to generate a JAVA client to request a Spring Boot API.
This API provides a POST web service which takes a JSON parameter "dto" as a part of multipart/form-data.
I am using the "encoding" attribute in the swagger declaration but the client does not seem to use it.
The parameter is not serialized to JSON but is sent as the string representation of the class.

Swagger-codegen version

swagger-codegen-cli-3.0.5-20190130.172841-36.jar

Swagger declaration file content or url

Open API v3.0.2

"requestBody": {
  "content": {
    "multipart/form-data": {
      "schema": {
        "type": "object",
        "properties": {
          "dto": {
            "$ref": "#/components/schemas/PushConfigurationDto"
          }
        }
      },
      "encoding": {
        "dto": {
          "contentType": "application/json"
        }
      }
    }
  }
}

This case corresponds to the "Complex Serialization in Form Data" example described into this documentation.

Command line used for generation

java -jar swagger-codegen-cli-3.0.5-20190130.172841-36.jar generate -i http://192.168.5.159:8080/openApi -l java -o ./java_api_client

Suggest a fix/enhancement

Is there a solution to make the client serializing multiparts other than String?

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

Start with the supplied OpenAPI 3.0.2 multipart/form-data declaration and the Java generation command, then inspect the generated client's multipart parameter handling. Confirm how the dto part is serialized and verify that it is sent as application/json rather than the class's string representation.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.