OpenAPITools / OpenAPITools/openapi-generator
[BUG] [JAVA] Multipart requests in generated client contains class name
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
I'm trying to upload a file and also specify an object containing metadata with regards to that file. When I create the requestBody content and generate the client, it creates a class for that object. When I create an object of that class and set the values of the metadata, I then pass it to the method making the API request. However, the request parameter for that object comes out as a string and contains the class name of the object. An exmaple of the resulting params:
Parameters: {"data"=>"class SentFileData {\n from: me\n to: someone\n}", "file"=>"file"}
openapi-generator version
4.2.1-SNAPSHOT
OpenAPI declaration file content or url
/sent_file:
post:
tags:
- "SendFile"
operationId: "sendFile"
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
file:
type: string
format: binary
data:
type: object
properties:
from:
type: string
to:
type: string
name:
type: string
Command line used for generation
docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate
-i ./local/swagger.yaml
-g java
-o ./local/java
-c ./local/config.json
Steps to reproduce
- Generate the client using above command.
- Import it into an existing project.
- Use the code below to make a request to any endpoint (can be a mock server)
SendFileApi apiInstance = new SendFileApi(defaultClient);
File file = new File("/path/to/file"); // File |
SentFileData data = new SentFileData();
data.setFrom("me");
data.setTo("someone");
try {
SentFaxSuccessResponse result = apiInstance.sendFile(file, data);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling SendFileApi#sendFile");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by generating the Java client from the shown multipart/form-data declaration with the provided Docker command, then inspect the generated SendFileApi request handling for the data parameter. Reproduce the request using SentFileData and verify that the multipart part contains its from and to values rather than the class-name string.
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
- Mostly clear
- Newbie friendliness
- 35/100