forked from loafle/openapi-generator-original
[Java] Replace "useNullForUnknownEnumValue" option with the nullable attribute (#3455)
* add nullable support to enum * update test spec with nullable enum * update samples * update samples
This commit is contained in:
parent
fabe021fb0
commit
8253c28d6e
@ -27,7 +27,7 @@ fi
|
|||||||
|
|
||||||
# if you've executed sbt assembly previously it will use that instead.
|
# if you've executed sbt assembly previously it will use that instead.
|
||||||
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
|
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||||
ags="generate --artifact-id petstore-java-client-jersey1 -t modules/openapi-generator/src/main/resources/Java -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -o samples/client/petstore/java/jersey1 --additional-properties hideGenerationTimestamp=true --library=jersey1 --additional-properties useNullForUnknownEnumValue=true $@"
|
ags="generate --artifact-id petstore-java-client-jersey1 -t modules/openapi-generator/src/main/resources/Java -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -o samples/client/petstore/java/jersey1 --additional-properties hideGenerationTimestamp=true --library=jersey1 $@"
|
||||||
|
|
||||||
echo "Removing files and folders under samples/client/petstore/java/jersey1/src/main"
|
echo "Removing files and folders under samples/client/petstore/java/jersey1/src/main"
|
||||||
rm -rf samples/client/petstore/java/jersey1/src/main
|
rm -rf samples/client/petstore/java/jersey1/src/main
|
||||||
|
@ -1,7 +1,4 @@
|
|||||||
{
|
{
|
||||||
"library": "jersey2",
|
"library": "jersey2",
|
||||||
"artifactId": "petstore-jersey2",
|
"artifactId": "petstore-jersey2"
|
||||||
"additionalProperties" : {
|
|
||||||
"useNullForUnknownEnumValue" : true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ public class CodegenModel {
|
|||||||
public Set<String> allMandatory = new TreeSet<String>(); // with parent's required properties
|
public Set<String> allMandatory = new TreeSet<String>(); // with parent's required properties
|
||||||
|
|
||||||
public Set<String> imports = new TreeSet<String>();
|
public Set<String> imports = new TreeSet<String>();
|
||||||
public boolean hasVars, emptyVars, hasMoreModels, hasEnums, isEnum, hasRequired, hasOptional, isArrayModel, hasChildren, isMapModel;
|
public boolean hasVars, emptyVars, hasMoreModels, hasEnums, isEnum, isNullable, hasRequired, hasOptional, isArrayModel, hasChildren, isMapModel;
|
||||||
public boolean hasOnlyReadOnly = true; // true if all properties are read-only
|
public boolean hasOnlyReadOnly = true; // true if all properties are read-only
|
||||||
public ExternalDocumentation externalDocumentation;
|
public ExternalDocumentation externalDocumentation;
|
||||||
|
|
||||||
@ -118,6 +118,7 @@ public class CodegenModel {
|
|||||||
.append("hasMoreModels", hasMoreModels)
|
.append("hasMoreModels", hasMoreModels)
|
||||||
.append("hasEnums", hasEnums)
|
.append("hasEnums", hasEnums)
|
||||||
.append("isEnum", isEnum)
|
.append("isEnum", isEnum)
|
||||||
|
.append("isNullable", isEnum)
|
||||||
.append("hasRequired", hasRequired)
|
.append("hasRequired", hasRequired)
|
||||||
.append("hasOptional", hasOptional)
|
.append("hasOptional", hasOptional)
|
||||||
.append("isArrayModel", isArrayModel)
|
.append("isArrayModel", isArrayModel)
|
||||||
|
@ -1884,19 +1884,16 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
if (ModelUtils.isMapSchema(schema)) {
|
if (ModelUtils.isMapSchema(schema)) {
|
||||||
addAdditionPropertiesToCodeGenModel(m, schema);
|
addAdditionPropertiesToCodeGenModel(m, schema);
|
||||||
m.isMapModel = true;
|
m.isMapModel = true;
|
||||||
}
|
} else if (ModelUtils.isIntegerSchema(schema)) { // integer type
|
||||||
else if (ModelUtils.isIntegerSchema(schema)) { // integer type
|
|
||||||
m.isNumeric = Boolean.TRUE;
|
m.isNumeric = Boolean.TRUE;
|
||||||
if (ModelUtils.isLongSchema(schema)) { // int64/long format
|
if (ModelUtils.isLongSchema(schema)) { // int64/long format
|
||||||
m.isLong = Boolean.TRUE;
|
m.isLong = Boolean.TRUE;
|
||||||
} else { // int32 format
|
} else { // int32 format
|
||||||
m.isInteger = Boolean.TRUE;
|
m.isInteger = Boolean.TRUE;
|
||||||
}
|
}
|
||||||
}
|
} else if (ModelUtils.isStringSchema(schema)) {
|
||||||
else if (ModelUtils.isStringSchema(schema)) {
|
|
||||||
m.isString = Boolean.TRUE;
|
m.isString = Boolean.TRUE;
|
||||||
}
|
} else if (ModelUtils.isNumberSchema(schema)) {
|
||||||
else if (ModelUtils.isNumberSchema(schema)) {
|
|
||||||
m.isNumeric = Boolean.TRUE;
|
m.isNumeric = Boolean.TRUE;
|
||||||
if (ModelUtils.isFloatSchema(schema)) { // float
|
if (ModelUtils.isFloatSchema(schema)) { // float
|
||||||
m.isFloat = Boolean.TRUE;
|
m.isFloat = Boolean.TRUE;
|
||||||
@ -1907,6 +1904,10 @@ public class DefaultCodegen implements CodegenConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Boolean.TRUE.equals(schema.getNullable())) {
|
||||||
|
m.isNullable = Boolean.TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
// passing null to allProperties and allRequired as there's no parent
|
// passing null to allProperties and allRequired as there's no parent
|
||||||
addVars(m, unaliasPropertySchema(schema.getProperties()), schema.getRequired(), null, null);
|
addVars(m, unaliasPropertySchema(schema.getProperties()), schema.getRequired(), null, null);
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,6 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
|||||||
public static final String SUPPORT_JAVA6 = "supportJava6";
|
public static final String SUPPORT_JAVA6 = "supportJava6";
|
||||||
public static final String DISABLE_HTML_ESCAPING = "disableHtmlEscaping";
|
public static final String DISABLE_HTML_ESCAPING = "disableHtmlEscaping";
|
||||||
public static final String BOOLEAN_GETTER_PREFIX = "booleanGetterPrefix";
|
public static final String BOOLEAN_GETTER_PREFIX = "booleanGetterPrefix";
|
||||||
public static final String USE_NULL_FOR_UNKNOWN_ENUM_VALUE = "useNullForUnknownEnumValue";
|
|
||||||
|
|
||||||
protected String dateLibrary = "threetenbp";
|
protected String dateLibrary = "threetenbp";
|
||||||
protected boolean supportAsync = false;
|
protected boolean supportAsync = false;
|
||||||
@ -86,7 +85,6 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
|||||||
protected boolean supportJava6 = false;
|
protected boolean supportJava6 = false;
|
||||||
protected boolean disableHtmlEscaping = false;
|
protected boolean disableHtmlEscaping = false;
|
||||||
protected String booleanGetterPrefix = "get";
|
protected String booleanGetterPrefix = "get";
|
||||||
protected boolean useNullForUnknownEnumValue = false;
|
|
||||||
protected String parentGroupId = "";
|
protected String parentGroupId = "";
|
||||||
protected String parentArtifactId = "";
|
protected String parentArtifactId = "";
|
||||||
protected String parentVersion = "";
|
protected String parentVersion = "";
|
||||||
@ -220,10 +218,6 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
|||||||
this.setBooleanGetterPrefix(additionalProperties.get(BOOLEAN_GETTER_PREFIX).toString());
|
this.setBooleanGetterPrefix(additionalProperties.get(BOOLEAN_GETTER_PREFIX).toString());
|
||||||
}
|
}
|
||||||
additionalProperties.put(BOOLEAN_GETTER_PREFIX, booleanGetterPrefix);
|
additionalProperties.put(BOOLEAN_GETTER_PREFIX, booleanGetterPrefix);
|
||||||
if (additionalProperties.containsKey(USE_NULL_FOR_UNKNOWN_ENUM_VALUE)) {
|
|
||||||
this.setUseNullForUnknownEnumValue(Boolean.valueOf(additionalProperties.get(USE_NULL_FOR_UNKNOWN_ENUM_VALUE).toString()));
|
|
||||||
}
|
|
||||||
additionalProperties.put(USE_NULL_FOR_UNKNOWN_ENUM_VALUE, useNullForUnknownEnumValue);
|
|
||||||
|
|
||||||
if (additionalProperties.containsKey(CodegenConstants.INVOKER_PACKAGE)) {
|
if (additionalProperties.containsKey(CodegenConstants.INVOKER_PACKAGE)) {
|
||||||
this.setInvokerPackage((String) additionalProperties.get(CodegenConstants.INVOKER_PACKAGE));
|
this.setInvokerPackage((String) additionalProperties.get(CodegenConstants.INVOKER_PACKAGE));
|
||||||
@ -1405,10 +1399,6 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
|||||||
this.booleanGetterPrefix = booleanGetterPrefix;
|
this.booleanGetterPrefix = booleanGetterPrefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUseNullForUnknownEnumValue(boolean useNullForUnknownEnumValue) {
|
|
||||||
this.useNullForUnknownEnumValue = useNullForUnknownEnumValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String escapeQuotationMark(String input) {
|
public String escapeQuotationMark(String input) {
|
||||||
// remove " to avoid code injection
|
// remove " to avoid code injection
|
||||||
|
@ -53,7 +53,7 @@ public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/useNullForUnknownEnumValue}}
|
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/isNullable}}
|
||||||
}
|
}
|
||||||
{{#gson}}
|
{{#gson}}
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/useNullForUnknownEnumValue}}
|
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/isNullable}}
|
||||||
}
|
}
|
||||||
{{#gson}}
|
{{#gson}}
|
||||||
|
|
||||||
|
@ -39,6 +39,6 @@
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + text + "'");{{/useNullForUnknownEnumValue}}
|
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}throw new IllegalArgumentException("Unexpected value '" + text + "'");{{/isNullable}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,6 @@ public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + text + "'");{{/useNullForUnknownEnumValue}}
|
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}throw new IllegalArgumentException("Unexpected value '" + text + "'");{{/isNullable}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,6 @@ public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/useNullForUnknownEnumValue}}
|
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/isNullable}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,6 @@ public enum {{datatypeWithEnum}} {
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/useNullForUnknownEnumValue}}
|
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/isNullable}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/useNullForUnknownEnumValue}}
|
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/isNullable}}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,6 @@ public enum {{datatypeWithEnum}} {
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/useNullForUnknownEnumValue}}
|
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/isNullable}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/useNullForUnknownEnumValue}}
|
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/isNullable}}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -49,6 +49,6 @@
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/useNullForUnknownEnumValue}}
|
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/isNullable}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,6 @@ public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/useNullForUnknownEnumValue}}
|
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/isNullable}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/useNullForUnknownEnumValue}}
|
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/isNullable}}
|
||||||
}
|
}
|
||||||
{{/jackson}}
|
{{/jackson}}
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,6 @@ public enum {{datatypeWithEnum}} {
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/useNullForUnknownEnumValue}}
|
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/isNullable}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,6 @@ public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/useNullForUnknownEnumValue}}
|
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/isNullable}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,6 @@
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/useNullForUnknownEnumValue}}
|
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/isNullable}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,6 @@ public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/useNullForUnknownEnumValue}}
|
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/isNullable}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,6 @@
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/useNullForUnknownEnumValue}}
|
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/isNullable}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,6 @@ public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/useNullForUnknownEnumValue}}
|
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/isNullable}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,6 @@ public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/useNullForUnknownEnumValue}}
|
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/isNullable}}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -39,6 +39,6 @@
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + text + "'");{{/useNullForUnknownEnumValue}}
|
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}throw new IllegalArgumentException("Unexpected value '" + text + "'");{{/isNullable}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,6 @@ public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + text + "'");{{/useNullForUnknownEnumValue}}
|
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}throw new IllegalArgumentException("Unexpected value '" + text + "'");{{/isNullable}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,6 @@
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + text + "'");{{/useNullForUnknownEnumValue}}
|
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}throw new IllegalArgumentException("Unexpected value '" + text + "'");{{/isNullable}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,6 @@ public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + text + "'");{{/useNullForUnknownEnumValue}}
|
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}throw new IllegalArgumentException("Unexpected value '" + text + "'");{{/isNullable}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,6 +37,6 @@ if (String.valueOf(b.value).equals(text)) {
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{#useNullForUnknownEnumValue}}return null;{{/useNullForUnknownEnumValue}}{{^useNullForUnknownEnumValue}}throw new IllegalArgumentException("Unexpected value '" + text + "'");{{/useNullForUnknownEnumValue}}
|
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}throw new IllegalArgumentException("Unexpected value '" + text + "'");{{/isNullable}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,6 @@ public class AbstractJavaCodegenTest {
|
|||||||
Assert.assertEquals(codegen.getInvokerPackage(), "org.openapitools");
|
Assert.assertEquals(codegen.getInvokerPackage(), "org.openapitools");
|
||||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "org.openapitools");
|
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "org.openapitools");
|
||||||
Assert.assertEquals(codegen.additionalProperties().get(AbstractJavaCodegen.BOOLEAN_GETTER_PREFIX), "get");
|
Assert.assertEquals(codegen.additionalProperties().get(AbstractJavaCodegen.BOOLEAN_GETTER_PREFIX), "get");
|
||||||
Assert.assertEquals(codegen.additionalProperties().get(AbstractJavaCodegen.USE_NULL_FOR_UNKNOWN_ENUM_VALUE), Boolean.FALSE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -140,7 +139,6 @@ public class AbstractJavaCodegenTest {
|
|||||||
codegen.setApiPackage("xyz.yyyyy.zzzzzzz.api");
|
codegen.setApiPackage("xyz.yyyyy.zzzzzzz.api");
|
||||||
codegen.setInvokerPackage("xyz.yyyyy.zzzzzzz.invoker");
|
codegen.setInvokerPackage("xyz.yyyyy.zzzzzzz.invoker");
|
||||||
codegen.setBooleanGetterPrefix("is");
|
codegen.setBooleanGetterPrefix("is");
|
||||||
codegen.setUseNullForUnknownEnumValue(true);
|
|
||||||
codegen.processOpts();
|
codegen.processOpts();
|
||||||
|
|
||||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.TRUE);
|
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.TRUE);
|
||||||
@ -152,7 +150,6 @@ public class AbstractJavaCodegenTest {
|
|||||||
Assert.assertEquals(codegen.getInvokerPackage(), "xyz.yyyyy.zzzzzzz.invoker");
|
Assert.assertEquals(codegen.getInvokerPackage(), "xyz.yyyyy.zzzzzzz.invoker");
|
||||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "xyz.yyyyy.zzzzzzz.invoker");
|
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "xyz.yyyyy.zzzzzzz.invoker");
|
||||||
Assert.assertEquals(codegen.additionalProperties().get(AbstractJavaCodegen.BOOLEAN_GETTER_PREFIX), "is");
|
Assert.assertEquals(codegen.additionalProperties().get(AbstractJavaCodegen.BOOLEAN_GETTER_PREFIX), "is");
|
||||||
Assert.assertEquals(codegen.additionalProperties().get(AbstractJavaCodegen.USE_NULL_FOR_UNKNOWN_ENUM_VALUE), Boolean.TRUE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -163,7 +160,6 @@ public class AbstractJavaCodegenTest {
|
|||||||
codegen.additionalProperties().put(CodegenConstants.API_PACKAGE, "xyz.yyyyy.api.oooooo");
|
codegen.additionalProperties().put(CodegenConstants.API_PACKAGE, "xyz.yyyyy.api.oooooo");
|
||||||
codegen.additionalProperties().put(CodegenConstants.INVOKER_PACKAGE, "xyz.yyyyy.invoker.oooooo");
|
codegen.additionalProperties().put(CodegenConstants.INVOKER_PACKAGE, "xyz.yyyyy.invoker.oooooo");
|
||||||
codegen.additionalProperties().put(AbstractJavaCodegen.BOOLEAN_GETTER_PREFIX, "getBoolean");
|
codegen.additionalProperties().put(AbstractJavaCodegen.BOOLEAN_GETTER_PREFIX, "getBoolean");
|
||||||
codegen.additionalProperties().put(AbstractJavaCodegen.USE_NULL_FOR_UNKNOWN_ENUM_VALUE, "true");
|
|
||||||
codegen.processOpts();
|
codegen.processOpts();
|
||||||
|
|
||||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.FALSE);
|
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.FALSE);
|
||||||
@ -175,7 +171,6 @@ public class AbstractJavaCodegenTest {
|
|||||||
Assert.assertEquals(codegen.getInvokerPackage(), "xyz.yyyyy.invoker.oooooo");
|
Assert.assertEquals(codegen.getInvokerPackage(), "xyz.yyyyy.invoker.oooooo");
|
||||||
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "xyz.yyyyy.invoker.oooooo");
|
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "xyz.yyyyy.invoker.oooooo");
|
||||||
Assert.assertEquals(codegen.additionalProperties().get(AbstractJavaCodegen.BOOLEAN_GETTER_PREFIX), "getBoolean");
|
Assert.assertEquals(codegen.additionalProperties().get(AbstractJavaCodegen.BOOLEAN_GETTER_PREFIX), "getBoolean");
|
||||||
Assert.assertEquals(codegen.additionalProperties().get(AbstractJavaCodegen.USE_NULL_FOR_UNKNOWN_ENUM_VALUE), Boolean.TRUE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -133,11 +133,6 @@ public class JavaJAXRSCXFExtServerCodegenTest extends JavaJaxrsBaseTest {
|
|||||||
return useMultipartFeature;
|
return useMultipartFeature;
|
||||||
}
|
}
|
||||||
|
|
||||||
// AbstractJavaCodegen.USE_NULL_FOR_UNKNOWN_ENUM_VALUE
|
|
||||||
public boolean isUseNullForUnknownEnumValue() {
|
|
||||||
return useNullForUnknownEnumValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// SpringFeatures.USE_SPRING_ANNOTATION_CONFIG
|
// SpringFeatures.USE_SPRING_ANNOTATION_CONFIG
|
||||||
public boolean isUseSpringAnnotationConfig() {
|
public boolean isUseSpringAnnotationConfig() {
|
||||||
return useSpringAnnotationConfig;
|
return useSpringAnnotationConfig;
|
||||||
@ -253,7 +248,6 @@ public class JavaJAXRSCXFExtServerCodegenTest extends JavaJaxrsBaseTest {
|
|||||||
additionalProperties.put(AbstractJavaCodegen.JAVA8_MODE, "true");
|
additionalProperties.put(AbstractJavaCodegen.JAVA8_MODE, "true");
|
||||||
additionalProperties.put(AbstractJavaCodegen.SUPPORT_ASYNC, "true");
|
additionalProperties.put(AbstractJavaCodegen.SUPPORT_ASYNC, "true");
|
||||||
additionalProperties.put(AbstractJavaCodegen.SUPPORT_JAVA6, "false");
|
additionalProperties.put(AbstractJavaCodegen.SUPPORT_JAVA6, "false");
|
||||||
additionalProperties.put(AbstractJavaCodegen.USE_NULL_FOR_UNKNOWN_ENUM_VALUE, "true");
|
|
||||||
additionalProperties.put(AbstractJavaCodegen.WITH_XML, "true");
|
additionalProperties.put(AbstractJavaCodegen.WITH_XML, "true");
|
||||||
// Options processed by AbstractJavaJAXRSServerCodegen
|
// Options processed by AbstractJavaJAXRSServerCodegen
|
||||||
additionalProperties.put(CodegenConstants.IMPL_FOLDER, "myimpl");
|
additionalProperties.put(CodegenConstants.IMPL_FOLDER, "myimpl");
|
||||||
@ -328,7 +322,6 @@ public class JavaJAXRSCXFExtServerCodegenTest extends JavaJaxrsBaseTest {
|
|||||||
assertEquals(testerCodegen.isFullJavaUtil(), true);
|
assertEquals(testerCodegen.isFullJavaUtil(), true);
|
||||||
assertEquals(testerCodegen.isJava8Mode(), true);
|
assertEquals(testerCodegen.isJava8Mode(), true);
|
||||||
assertEquals(testerCodegen.isSupportAsync(), true);
|
assertEquals(testerCodegen.isSupportAsync(), true);
|
||||||
assertEquals(testerCodegen.isUseNullForUnknownEnumValue(), true);
|
|
||||||
assertEquals(testerCodegen.isWithXml(), true);
|
assertEquals(testerCodegen.isWithXml(), true);
|
||||||
// Options processed by AbstractJavaJAXRSServerCodegen
|
// Options processed by AbstractJavaJAXRSServerCodegen
|
||||||
assertEquals(testerCodegen.getImplFolder(), "myimpl");
|
assertEquals(testerCodegen.getImplFolder(), "myimpl");
|
||||||
@ -581,7 +574,6 @@ public class JavaJAXRSCXFExtServerCodegenTest extends JavaJaxrsBaseTest {
|
|||||||
assertNull(additionalProperties.get(AbstractJavaCodegen.JAVA8_MODE));
|
assertNull(additionalProperties.get(AbstractJavaCodegen.JAVA8_MODE));
|
||||||
assertNull(additionalProperties.get(AbstractJavaCodegen.SUPPORT_ASYNC));
|
assertNull(additionalProperties.get(AbstractJavaCodegen.SUPPORT_ASYNC));
|
||||||
assertEquals(additionalProperties.get(AbstractJavaCodegen.SUPPORT_JAVA6), Boolean.FALSE);
|
assertEquals(additionalProperties.get(AbstractJavaCodegen.SUPPORT_JAVA6), Boolean.FALSE);
|
||||||
assertEquals(additionalProperties.get(AbstractJavaCodegen.USE_NULL_FOR_UNKNOWN_ENUM_VALUE), false);
|
|
||||||
assertEquals(additionalProperties.get(AbstractJavaCodegen.WITH_XML), false);
|
assertEquals(additionalProperties.get(AbstractJavaCodegen.WITH_XML), false);
|
||||||
// Options processed by AbstractJavaJAXRSServerCodegen
|
// Options processed by AbstractJavaJAXRSServerCodegen
|
||||||
assertNull(additionalProperties.get(CodegenConstants.IMPL_FOLDER));
|
assertNull(additionalProperties.get(CodegenConstants.IMPL_FOLDER));
|
||||||
|
@ -1580,6 +1580,7 @@ components:
|
|||||||
- fish
|
- fish
|
||||||
- crab
|
- crab
|
||||||
OuterEnum:
|
OuterEnum:
|
||||||
|
nullable: true
|
||||||
type: string
|
type: string
|
||||||
enum:
|
enum:
|
||||||
- placed
|
- placed
|
||||||
|
@ -59,7 +59,7 @@ public class EnumArrays {
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
throw new IllegalArgumentException("Unexpected value '" + value + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ public class EnumArrays {
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
throw new IllegalArgumentException("Unexpected value '" + value + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ public enum EnumClass {
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
throw new IllegalArgumentException("Unexpected value '" + value + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ public class EnumTest {
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
throw new IllegalArgumentException("Unexpected value '" + value + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ public class EnumTest {
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
throw new IllegalArgumentException("Unexpected value '" + value + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ public class EnumTest {
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
throw new IllegalArgumentException("Unexpected value '" + value + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,7 +176,7 @@ public class EnumTest {
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
throw new IllegalArgumentException("Unexpected value '" + value + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ public class MapTest {
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
throw new IllegalArgumentException("Unexpected value '" + value + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ public class Order {
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
throw new IllegalArgumentException("Unexpected value '" + value + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ public enum OuterEnum {
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
throw new IllegalArgumentException("Unexpected value '" + value + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ public class Pet {
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
throw new IllegalArgumentException("Unexpected value '" + value + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +72,6 @@ class EnumTest(object):
|
|||||||
self.enum_integer = enum_integer
|
self.enum_integer = enum_integer
|
||||||
if enum_number is not None:
|
if enum_number is not None:
|
||||||
self.enum_number = enum_number
|
self.enum_number = enum_number
|
||||||
if outer_enum is not None:
|
|
||||||
self.outer_enum = outer_enum
|
self.outer_enum = outer_enum
|
||||||
if outer_enum_integer is not None:
|
if outer_enum_integer is not None:
|
||||||
self.outer_enum_integer = outer_enum_integer
|
self.outer_enum_integer = outer_enum_integer
|
||||||
|
@ -55,7 +55,7 @@ public enum OuterEnum {
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException("Unexpected value '" + value + "'");
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user