swagger-api / swagger-api/swagger-codegen
[JavaSpring] Bug generating ApiException.java with useRuntimeException flag
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
ApiException.java generation does not take in account useRuntimeException flag.
Swagger-codegen version
Checked on 2.3.1 and 3.0.1
Swagger declaration file content or url
Embedded swagger code generator files are affected.
Command line used for generation
<build>
<plugins>
<plugin>
<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>default</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<language>spring</language>
<inputSpec>${project.basedir}/src/main/resources/api.yaml</inputSpec>
<apiPackage>com.my.api</apiPackage>
<modelPackage>com.my.model</modelPackage>
<ignoreFileOverride>${project.basedir}/src/main/resources/codegen-ignore</ignoreFileOverride>
<configOptions>
<useRuntimeException>true</useRuntimeException>
<recursiveBeanValidation>false</recursiveBeanValidation>
<useBeanValidation>false</useBeanValidation>
<performBeanValidation>false</performBeanValidation>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Steps to reproduce
Regular mvn clean generate-sources
Expected result:
public class ApiException extends RuntimeException {...}
Actual result:
public class ApiException extends Exception {...}
Related issues/PRs
Changes done for Java in https://github.com/swagger-api/swagger-codegen/issues/4376
Suggest a fix/enhancement
diff --git a/modules/swagger-codegen/src/main/resources/JavaSpring/apiException.mustache b/modules/swagger-codegen/src/main/resources/JavaSpring/apiException.mustache
index f61611477..c752b15c1 100644
--- a/modules/swagger-codegen/src/main/resources/JavaSpring/apiException.mustache
+++ b/modules/swagger-codegen/src/main/resources/JavaSpring/apiException.mustache
@@ -1,7 +1,7 @@
package {{apiPackage}};
{{>generatedAnnotation}}
-public class ApiException extends Exception{
+public class ApiException extends{{#useRuntimeException}} RuntimeException {{/useRuntimeException}}{{^useRuntimeException}} Exception {{/useRuntimeException}} {
private int code;
public ApiException (int code, String msg) {
super(msg);
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 with modules/swagger-codegen/src/main/resources/JavaSpring/apiException.mustache and run the reported mvn clean generate-sources command. Verify that generated ApiException.java respects the useRuntimeException flag, extending RuntimeException when it is true and Exception otherwise.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 50/100