OpenAPITools / OpenAPITools/openapi-generator
[BUG][java-helidon-server] Missing try-catch block for sending a file
Nobody has claimed this yet.
- 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
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 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