forked from loafle/openapi-generator-original
Support a true "java8" option (#5864)
* Closes #5863 The "dateLibrary" option for java, sadly, sets a mustache value "java8". This change updates this so that "java" in the mustache libraries means what it should mean - use all java8 classes. In this case, there's no need for the third party Base64 library as java8's JDK has this built in. In my view, the "dateLibrary" should be deprecated but that should be a separate PR. * updated samples * fixed tests for new CLI java8 * regenerated samples after master merge * oops - left in an end tag after master merge * rerun checks * rerun checks
This commit is contained in:
committed by
wing328
parent
a64c7d7986
commit
b2efb70410
@@ -45,8 +45,10 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
public static final String FULL_JAVA_UTIL = "fullJavaUtil";
|
||||
public static final String DEFAULT_LIBRARY = "<default>";
|
||||
public static final String DATE_LIBRARY = "dateLibrary";
|
||||
public static final String JAVA8_MODE = "java8";
|
||||
public static final String SUPPORT_JAVA6 = "supportJava6";
|
||||
|
||||
protected boolean java8Mode = false;
|
||||
protected String dateLibrary = "joda";
|
||||
protected String invokerPackage = "io.swagger";
|
||||
protected String groupId = "io.swagger";
|
||||
@@ -148,14 +150,20 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
|
||||
CliOption dateLibrary = new CliOption(DATE_LIBRARY, "Option. Date library to use");
|
||||
Map<String, String> dateOptions = new HashMap<String, String>();
|
||||
dateOptions.put("java8", "Java 8 native");
|
||||
dateOptions.put("java8", "Java 8 native - note: this also sets \"" + JAVA8_MODE + "\" to true");
|
||||
dateOptions.put("java8-localdatetime", "Java 8 using LocalDateTime (for legacy app only)");
|
||||
dateOptions.put("joda", "Joda");
|
||||
dateOptions.put("legacy", "Legacy java.util.Date");
|
||||
dateLibrary.setEnum(dateOptions);
|
||||
|
||||
cliOptions.add(dateLibrary);
|
||||
|
||||
CliOption java8Mode = new CliOption(JAVA8_MODE, "Option. Use Java8 classes instead of third party equivalents");
|
||||
Map<String, String> java8ModeOptions = new HashMap<String, String>();
|
||||
java8ModeOptions.put("true", "Use Java 8 classes such as Base64");
|
||||
java8ModeOptions.put("false", "Various third party libraries as needed");
|
||||
java8Mode.setEnum(java8ModeOptions);
|
||||
cliOptions.add(java8Mode);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -359,10 +367,17 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
importMapping.put("com.fasterxml.jackson.annotation.JsonProperty", "com.fasterxml.jackson.annotation.JsonCreator");
|
||||
|
||||
if(additionalProperties.containsKey(DATE_LIBRARY)) {
|
||||
setDateLibrary(additionalProperties.get("dateLibrary").toString());
|
||||
setDateLibrary(additionalProperties.get(DATE_LIBRARY).toString());
|
||||
additionalProperties.put(dateLibrary, "true");
|
||||
}
|
||||
|
||||
if(additionalProperties.containsKey(JAVA8_MODE)) {
|
||||
setJava8Mode(Boolean.parseBoolean(additionalProperties.get(JAVA8_MODE).toString()));
|
||||
if ( java8Mode ) {
|
||||
additionalProperties.put("java8", "true");
|
||||
}
|
||||
}
|
||||
|
||||
if("joda".equals(dateLibrary)) {
|
||||
additionalProperties.put("joda", "true");
|
||||
typeMapping.put("date", "LocalDate");
|
||||
@@ -1126,6 +1141,10 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
this.dateLibrary = library;
|
||||
}
|
||||
|
||||
public void setJava8Mode(boolean enabled) {
|
||||
this.java8Mode = enabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeQuotationMark(String input) {
|
||||
// remove " to avoid code injection
|
||||
|
||||
Reference in New Issue
Block a user