forked from loafle/openapi-generator-original
add enumName to store the enum prefix
This commit is contained in:
@@ -46,6 +46,8 @@ public class CodegenProperty implements Cloneable {
|
||||
public Boolean hasValidation; // true if pattern, maximum, etc are set (only used in the mustache template)
|
||||
public Boolean isInherited;
|
||||
public String nameInCamelCase; // property name in camel case
|
||||
// enum name based on the property name, usually use as a prefix (e.g. VAR_NAME) for enum name (e.g. VAR_NAME_VALUE1)
|
||||
public String enumName;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@@ -111,6 +113,7 @@ public class CodegenProperty implements Cloneable {
|
||||
result = prime * result + ((isListContainer == null) ? 0 : isListContainer.hashCode());
|
||||
result = prime * result + Objects.hashCode(isInherited);
|
||||
result = prime * result + Objects.hashCode(nameInCamelCase);
|
||||
result = prime * result + Objects.hashCode(enumName);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -271,6 +274,9 @@ public class CodegenProperty implements Cloneable {
|
||||
if (!Objects.equals(this.nameInCamelCase, other.nameInCamelCase)) {
|
||||
return false;
|
||||
}
|
||||
if (!Objects.equals(this.enumName, other.enumName)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1559,6 +1559,7 @@ public class DefaultCodegen {
|
||||
// this can cause issues for clients which don't support enums
|
||||
if (property.isEnum) {
|
||||
property.datatypeWithEnum = toEnumName(property);
|
||||
property.enumName = toEnumName(property);
|
||||
} else {
|
||||
property.datatypeWithEnum = property.datatype;
|
||||
}
|
||||
@@ -1688,6 +1689,10 @@ public class DefaultCodegen {
|
||||
// set both datatype and datetypeWithEnum as only the inner type is enum
|
||||
property.datatypeWithEnum = property.datatypeWithEnum.replace(baseItem.baseType, toEnumName(baseItem));
|
||||
|
||||
// naming the enum with respect to the language enum naming convention
|
||||
// e.g. remove [], {} from array/map of enum
|
||||
property.enumName = toEnumName(property);
|
||||
|
||||
// set default value for variable with inner enum
|
||||
if (property.defaultValue != null) {
|
||||
property.defaultValue = property.defaultValue.replace(property.items.baseType, toEnumName(property.items));
|
||||
@@ -1707,6 +1712,10 @@ public class DefaultCodegen {
|
||||
// set both datatype and datetypeWithEnum as only the inner type is enum
|
||||
property.datatypeWithEnum = property.datatypeWithEnum.replace(", " + baseItem.baseType, ", " + toEnumName(baseItem));
|
||||
|
||||
// naming the enum with respect to the language enum naming convention
|
||||
// e.g. remove [], {} from array/map of enum
|
||||
property.enumName = toEnumName(property);
|
||||
|
||||
// set default value for variable with inner enum
|
||||
if (property.defaultValue != null) {
|
||||
property.defaultValue = property.defaultValue.replace(", " + property.items.baseType, ", " + toEnumName(property.items));
|
||||
|
||||
@@ -645,6 +645,9 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public String toEnumName(CodegenProperty property) {
|
||||
String enumName = underscore(toModelName(property.name)).toUpperCase();
|
||||
|
||||
// remove [] for array or map of enum
|
||||
enumName = enumName.replace("[]", "");
|
||||
|
||||
if (enumName.matches("\\d.*")) { // starts with number
|
||||
return "_" + enumName;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user