Add RuntimeException option (#5405)

* add option to change Exception to RuntimeException

* rename propertie
remove space in template
This commit is contained in:
Mario 2017-04-21 16:13:57 +02:00 committed by wing328
parent 122db78b1a
commit f61e0d4024
3 changed files with 27 additions and 16 deletions

View File

@ -27,6 +27,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
public static final String DO_NOT_USE_RX = "doNotUseRx";
public static final String USE_PLAY24_WS = "usePlay24WS";
public static final String PARCELABLE_MODEL = "parcelableModel";
public static final String USE_RUNTIME_EXCEPTION = "useRuntimeException";
public static final String RETROFIT_1 = "retrofit";
public static final String RETROFIT_2 = "retrofit2";
@ -40,6 +41,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
protected boolean useBeanValidation = false;
protected boolean performBeanValidation = false;
protected boolean useGzipFeature = false;
protected boolean useRuntimeException = false;
public JavaClientCodegen() {
super();
@ -58,6 +60,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations"));
cliOptions.add(CliOption.newBoolean(PERFORM_BEANVALIDATION, "Perform BeanValidation"));
cliOptions.add(CliOption.newBoolean(USE_GZIP_FEATURE, "Send gzip-encoded requests"));
cliOptions.add(CliOption.newBoolean(USE_RUNTIME_EXCEPTION, "Use RuntimeException instead of Exception"));
supportedLibraries.put("jersey1", "HTTP client: Jersey client 1.19.1. JSON processing: Jackson 2.7.0. Enable Java6 support using '-DsupportJava6=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.");
supportedLibraries.put("feign", "HTTP client: OpenFeign 9.4.0. JSON processing: Jackson 2.8.7");
@ -128,6 +131,10 @@ public class JavaClientCodegen extends AbstractJavaCodegen
this.setUseGzipFeature(convertPropertyToBooleanAndWriteBack(USE_GZIP_FEATURE));
}
if (additionalProperties.containsKey(USE_RUNTIME_EXCEPTION)) {
this.setUseRuntimeException(convertPropertyToBooleanAndWriteBack(USE_RUNTIME_EXCEPTION));
}
final String invokerFolder = (sourceFolder + '/' + invokerPackage).replace(".", "/");
final String authFolder = (sourceFolder + '/' + invokerPackage + ".auth").replace(".", "/");
@ -413,6 +420,10 @@ public class JavaClientCodegen extends AbstractJavaCodegen
this.useGzipFeature = useGzipFeature;
}
public void setUseRuntimeException(boolean useRuntimeException) {
this.useRuntimeException = useRuntimeException;
}
final private static Pattern JSON_MIME_PATTERN = Pattern.compile("(?i)application\\/json(;.*)?");
final private static Pattern JSON_VENDOR_MIME_PATTERN = Pattern.compile("(?i)application\\/vnd.(.*)+json(;.*)?");

View File

@ -6,7 +6,7 @@ import java.util.Map;
import java.util.List;
{{>generatedAnnotation}}
public class ApiException extends Exception {
public class ApiException extends{{#useRuntimeException}} RuntimeException {{/useRuntimeException}}{{^useRuntimeException}} Exception {{/useRuntimeException}}{
private int code = 0;
private Map<String, List<String>> responseHeaders = null;
private String responseBody = null;

View File

@ -24,7 +24,7 @@ public class JavaClientOptionsProvider extends JavaOptionsProvider {
options.put(JavaClientCodegen.USE_BEANVALIDATION, "false");
options.put(JavaClientCodegen.PERFORM_BEANVALIDATION, PERFORM_BEANVALIDATION);
options.put(JavaClientCodegen.USE_GZIP_FEATURE, "false");
options.put(JavaClientCodegen.USE_RUNTIME_EXCEPTION, "false");
return options;
}