OpenAPITools / OpenAPITools/openapi-generator
[BUG] Regression Java Native Template no longer able to process binary responses.
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Hello in the java native template using the most recent version of the openapi generator (7.11.0) we can no longer process binary files.
In an endpoint the generator creates the following code:
String responseBody = new String(localVarResponse.body().readAllBytes());
localVarResponse.body().close();
return new ApiResponse<File>(
localVarResponse.statusCode(),
localVarResponse.headers().map(),
responseBody.isBlank()? null: memberVarObjectMapper.readValue(responseBody, new TypeReference<File>() {})
);
As one can see the body is passed unconditionally into the String constructor. This was not the case previously.
In the previous version (7.10.0) the generator generated the following code
return new ApiResponse<File>(
localVarResponse.statusCode(),
localVarResponse.headers().map(),
localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference<File>() {}) // closes the InputStream
);
File being java.io.File, which is the correct type for binary data.
memberVarObjectMapper is set to a custom implementation of Object mapper via the generated setter that can handle java.io.File.
Unfortunately my files are not valid utf-8 (they are binary files like .zip's or images) and turning them into a utf-8 string destroys the data.
Also I used to be able to download very large files (100GB+) using the body inputstream. calling readAllBytes() on a 100GB+ file is deadly (OOM guaranteed)
Would it be possible to roll back this change please?
I don't really see any benefit to the new "template" other than that it destroys our ability to customize reading the response body.
Not everyone calls just "JSON" endpoints.
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 locating the Java native template that generates the response-handling code shown, and compare its output between OpenAPI Generator 7.10.0 and 7.11.0. Verify handling of java.io.File responses with binary and very large bodies; done means generated clients preserve binary data without eagerly reading the entire response into memory.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100