OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Java Native] client incorrect generation of `application/octet-stream`
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- [x]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 a native Java client using application/octet-stream it incorrectly tries to decode it to JSON using ObjectMapper.
openapi-generator version
7.2.0
OpenAPI declaration file content or url
"/datasetrw/snapshot/{snapshotId}/file/raw": {
"get": {
"operationId": "getFileRaw",
"parameters": [
{
"description": "snapshot ID",
"in": "path",
"name": "snapshotId",
"required": true,
"schema": {
"pattern": "^[0-9a-f]{24}$",
"type": "string"
}
},
{
"description": "path of file to get raw content for",
"in": "query",
"name": "path",
"required": true,
"schema": {
"type": "string"
}
},
{
"description": "whether endpoint is used for download",
"in": "query",
"name": "download",
"required": false,
"schema": {
"nullable": true,
"type": "boolean"
}
}
],
"responses": {
"200": {
"content": {
"application/octet-stream": {
"schema": {
"format": "binary",
"type": "string"
}
}
},
"description": "success"
},
"400": {
"$ref": "#/components/responses/BadRequest"
},
"401": {
"$ref": "#/components/responses/Unauthorized"
},
"403": {
"$ref": "#/components/responses/Forbidden"
},
"500": {
"$ref": "#/components/responses/InternalError"
}
},
"summary": "Get snapshot file raw content at specified path",
"tags": [
"DatasetRw"
]
}
},
Generation Details
It then generates this Java code trying to convert it to java.io.File...
public ApiResponse<File> getFileRawWithHttpInfo(String snapshotId, String path, Boolean download) throws ApiException {
HttpRequest.Builder localVarRequestBuilder = getFileRawRequestBuilder(snapshotId, path, download);
try {
HttpResponse<InputStream> localVarResponse = memberVarHttpClient.send(
localVarRequestBuilder.build(),
HttpResponse.BodyHandlers.ofInputStream());
if (memberVarResponseInterceptor != null) {
memberVarResponseInterceptor.accept(localVarResponse);
}
try {
if (localVarResponse.statusCode()/ 100 != 2) {
throw getApiException("getFileRaw", localVarResponse);
}
return new ApiResponse<File>(
localVarResponse.statusCode(),
localVarResponse.headers().map(),
localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference<File>() {}) // closes the InputStream
);
} finally {
}
} catch (IOException e) {
throw new ApiException(e);
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new ApiException(e);
}
}
You can see this line is incorrect.
localVarResponse.body() == null ? null : memberVarObjectMapper.readValue(localVarResponse.body(), new TypeReference<File>() {}) // closes the InputStream
Its using the JSON Mapper to try and convert to a File.
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
Use the provided OpenAPI declaration to reproduce native Java client generation, then inspect the generated getFileRawWithHttpInfo method and trace the Java Native response-generation path that produces it. Done means an application/octet-stream response is handled as binary data rather than passed to ObjectMapper for File conversion, with the generated output demonstrating the corrected behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100