forked from loafle/openapi-generator-original
Add RuntimeException option (#5405)
* add option to change Exception to RuntimeException * rename propertie remove space in template
This commit is contained in:
parent
122db78b1a
commit
f61e0d4024
@ -27,6 +27,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
|||||||
public static final String DO_NOT_USE_RX = "doNotUseRx";
|
public static final String DO_NOT_USE_RX = "doNotUseRx";
|
||||||
public static final String USE_PLAY24_WS = "usePlay24WS";
|
public static final String USE_PLAY24_WS = "usePlay24WS";
|
||||||
public static final String PARCELABLE_MODEL = "parcelableModel";
|
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_1 = "retrofit";
|
||||||
public static final String RETROFIT_2 = "retrofit2";
|
public static final String RETROFIT_2 = "retrofit2";
|
||||||
@ -40,6 +41,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
|||||||
protected boolean useBeanValidation = false;
|
protected boolean useBeanValidation = false;
|
||||||
protected boolean performBeanValidation = false;
|
protected boolean performBeanValidation = false;
|
||||||
protected boolean useGzipFeature = false;
|
protected boolean useGzipFeature = false;
|
||||||
|
protected boolean useRuntimeException = false;
|
||||||
|
|
||||||
public JavaClientCodegen() {
|
public JavaClientCodegen() {
|
||||||
super();
|
super();
|
||||||
@ -58,6 +60,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
|||||||
cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations"));
|
cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations"));
|
||||||
cliOptions.add(CliOption.newBoolean(PERFORM_BEANVALIDATION, "Perform BeanValidation"));
|
cliOptions.add(CliOption.newBoolean(PERFORM_BEANVALIDATION, "Perform BeanValidation"));
|
||||||
cliOptions.add(CliOption.newBoolean(USE_GZIP_FEATURE, "Send gzip-encoded requests"));
|
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("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");
|
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));
|
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 invokerFolder = (sourceFolder + '/' + invokerPackage).replace(".", "/");
|
||||||
final String authFolder = (sourceFolder + '/' + invokerPackage + ".auth").replace(".", "/");
|
final String authFolder = (sourceFolder + '/' + invokerPackage + ".auth").replace(".", "/");
|
||||||
|
|
||||||
@ -289,22 +296,22 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prioritizes consumes mime-type list by moving json-vendor and json mime-types up front, but
|
* Prioritizes consumes mime-type list by moving json-vendor and json mime-types up front, but
|
||||||
* otherwise preserves original consumes definition order.
|
* otherwise preserves original consumes definition order.
|
||||||
* [application/vnd...+json,... application/json, ..as is..]
|
* [application/vnd...+json,... application/json, ..as is..]
|
||||||
*
|
*
|
||||||
* @param consumes consumes mime-type list
|
* @param consumes consumes mime-type list
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
static List<Map<String, String>> prioritizeContentTypes(List<Map<String, String>> consumes) {
|
static List<Map<String, String>> prioritizeContentTypes(List<Map<String, String>> consumes) {
|
||||||
if ( consumes.size() <= 1 )
|
if ( consumes.size() <= 1 )
|
||||||
return consumes;
|
return consumes;
|
||||||
|
|
||||||
List<Map<String, String>> prioritizedContentTypes = new ArrayList<>(consumes.size());
|
List<Map<String, String>> prioritizedContentTypes = new ArrayList<>(consumes.size());
|
||||||
|
|
||||||
List<Map<String, String>> jsonVendorMimeTypes = new ArrayList<>(consumes.size());
|
List<Map<String, String>> jsonVendorMimeTypes = new ArrayList<>(consumes.size());
|
||||||
List<Map<String, String>> jsonMimeTypes = new ArrayList<>(consumes.size());
|
List<Map<String, String>> jsonMimeTypes = new ArrayList<>(consumes.size());
|
||||||
|
|
||||||
for ( Map<String, String> consume : consumes) {
|
for ( Map<String, String> consume : consumes) {
|
||||||
if ( isJsonVendorMimeType(consume.get(MEDIA_TYPE))) {
|
if ( isJsonVendorMimeType(consume.get(MEDIA_TYPE))) {
|
||||||
jsonVendorMimeTypes.add(consume);
|
jsonVendorMimeTypes.add(consume);
|
||||||
@ -314,18 +321,18 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
prioritizedContentTypes.add(consume);
|
prioritizedContentTypes.add(consume);
|
||||||
|
|
||||||
consume.put("hasMore", "true");
|
consume.put("hasMore", "true");
|
||||||
}
|
}
|
||||||
|
|
||||||
prioritizedContentTypes.addAll(0, jsonMimeTypes);
|
prioritizedContentTypes.addAll(0, jsonMimeTypes);
|
||||||
prioritizedContentTypes.addAll(0, jsonVendorMimeTypes);
|
prioritizedContentTypes.addAll(0, jsonVendorMimeTypes);
|
||||||
|
|
||||||
prioritizedContentTypes.get(prioritizedContentTypes.size()-1).put("hasMore", null);
|
prioritizedContentTypes.get(prioritizedContentTypes.size()-1).put("hasMore", null);
|
||||||
|
|
||||||
return prioritizedContentTypes;
|
return prioritizedContentTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isMultipartType(List<Map<String, String>> consumes) {
|
private static boolean isMultipartType(List<Map<String, String>> consumes) {
|
||||||
Map<String, String> firstType = consumes.get(0);
|
Map<String, String> firstType = consumes.get(0);
|
||||||
if (firstType != null) {
|
if (firstType != null) {
|
||||||
@ -413,8 +420,12 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
|||||||
this.useGzipFeature = useGzipFeature;
|
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_MIME_PATTERN = Pattern.compile("(?i)application\\/json(;.*)?");
|
||||||
final private static Pattern JSON_VENDOR_MIME_PATTERN = Pattern.compile("(?i)application\\/vnd.(.*)+json(;.*)?");
|
final private static Pattern JSON_VENDOR_MIME_PATTERN = Pattern.compile("(?i)application\\/vnd.(.*)+json(;.*)?");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the given MIME is a JSON MIME.
|
* Check if the given MIME is a JSON MIME.
|
||||||
|
@ -6,7 +6,7 @@ import java.util.Map;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
{{>generatedAnnotation}}
|
{{>generatedAnnotation}}
|
||||||
public class ApiException extends Exception {
|
public class ApiException extends{{#useRuntimeException}} RuntimeException {{/useRuntimeException}}{{^useRuntimeException}} Exception {{/useRuntimeException}}{
|
||||||
private int code = 0;
|
private int code = 0;
|
||||||
private Map<String, List<String>> responseHeaders = null;
|
private Map<String, List<String>> responseHeaders = null;
|
||||||
private String responseBody = null;
|
private String responseBody = null;
|
||||||
|
@ -24,7 +24,7 @@ public class JavaClientOptionsProvider extends JavaOptionsProvider {
|
|||||||
options.put(JavaClientCodegen.USE_BEANVALIDATION, "false");
|
options.put(JavaClientCodegen.USE_BEANVALIDATION, "false");
|
||||||
options.put(JavaClientCodegen.PERFORM_BEANVALIDATION, PERFORM_BEANVALIDATION);
|
options.put(JavaClientCodegen.PERFORM_BEANVALIDATION, PERFORM_BEANVALIDATION);
|
||||||
options.put(JavaClientCodegen.USE_GZIP_FEATURE, "false");
|
options.put(JavaClientCodegen.USE_GZIP_FEATURE, "false");
|
||||||
|
options.put(JavaClientCodegen.USE_RUNTIME_EXCEPTION, "false");
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user