OpenAPITools / OpenAPITools/openapi-generator

[BUG][java-helidon-server] Missing try-catch block for sending a file

Open
#21,868 0 comments 0 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

Description

When generating a service using useAbstractClass and se, when the result type is a file

      responses:
        200:
          content:
            "text/csv":
              schema:
                type: string
                format: binary

Then the code generated in the base service class doesn't have a try-catch around the transferTo call

            void send(ServerResponse _serverResponse) {
                _serverResponse.status(Status.OK_200);
                if (response != null) { 
                   _serverResponse.contentLength(response.transferTo(_serverResponse.outputStream()));
                }                _serverResponse.send();
            }

This causes a compiler error

unreported exception java.io.IOException; must be caught or declared to be thrown

openapi-generator version

7.15.0

OpenAPI declaration file content or url
paths:
  "/download":
    post:
      responses:
        200:
          content:
            "text/csv":
              schema:
                type: string
                format: binary
Generation Details

Using Maven plugin,

      <plugin>
        <groupId>org.openapitools</groupId>
        <artifactId>openapi-generator-maven-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>generate</goal>
            </goals>
            <configuration>
              <generatorName>java-helidon-server</generatorName>
              <generateModels>false</generateModels>
              <configOptions>
                <fullProject>false</fullProject>
                <library>se</library>
                <useAbstractClass>true</useAbstractClass>
              </configOptions>
            </configuration>
          </execution>
        </executions>
      </plugin>
Suggest a fix

Seems to just require wrapping the line in the tremplate in a try-catch

https://github.com/OpenAPITools/openapi-generator/blob/20d5126b17a4995814c268567bf4672fb8ae64eb/modules/openapi-generator/src/main/resources/java-helidon/server/libraries/se/partsUtils.mustache#L86

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 at modules/openapi-generator/src/main/resources/java-helidon/server/libraries/se/partsUtils.mustache around line 86 and reproduce the generation with the Maven configuration in the issue. Verify the generated abstract service for a binary file response compiles successfully, including the transferTo call.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.