OpenAPITools / OpenAPITools/openapi-generator

[BUG] [java-micronaut-server] Binary file to download has a wrong object type

Open
#15,769 2 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • 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?
Description

If the Micronaut endpoint returns a binary file, micronaut uses object types SystemFile or StreamedFile.
But the problem is, if the Openapi definition has format: binary, the generated endpoint returns object CompletedFileUpload. This object is uses to upload file using multipart, but not to download the file.

openapi-generator version

I use the latest version OpenAPI Generator with maven plugin v6.6.0.

OpenAPI declaration file content or url
/download:
  get:
    tags:
      - download
    description: Download file
    operationId: downloadFile
    responses:
      "200":
        description: Response with encrypted ZIP file includes all application log files
        content:
          application/octet-stream:
            schema:
              type: string
              format: binary
Generation Details
@Get(uri="/download")
@Produces(value = {"application/octet-stream"})
public HttpResponse<CompletedFileUpload> downloadFileApi() {
    return downloadFile();
}
Steps to reproduce
  1. Create an endpoint with content type application/octet-stream and schema format binary.
  2. Generate code with java-micronaut-server.
  3. Check the generated controller.
Related issues/PRs

Related ticket to generate OpenAPI definition from the implementation and swagger annotations - https://github.com/micronaut-projects/micronaut-openapi/issues/441

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 by tracing the java-micronaut-server generator's handling of an OpenAPI response with type string and format binary, then inspect the generated downloadFileApi controller shown in the report. Done means binary downloads return a Micronaut download type such as SystemFile or StreamedFile rather than CompletedFileUpload; validate by regenerating the provided endpoint.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.