-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
412 additions
and
830 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -335,8 +335,10 @@ public CodegenProperty fromProperty(String name, Property p) { | |
swiftEnums.add(map); | ||
} | ||
codegenProperty.allowableValues.put("values", swiftEnums); | ||
codegenProperty.datatypeWithEnum = | ||
StringUtils.left(codegenProperty.datatypeWithEnum, codegenProperty.datatypeWithEnum.length() - "Enum".length()); | ||
codegenProperty.datatypeWithEnum = toEnumName(codegenProperty); | ||
//codegenProperty.datatypeWithEnum = | ||
// StringUtils.left(codegenProperty.datatypeWithEnum, codegenProperty.datatypeWithEnum.length() - "Enum".length()); | ||
|
||
// Ensure that the enum type doesn't match a reserved word or | ||
// the variable name doesn't match the generated enum type or the | ||
// Swift compiler will generate an error | ||
|
@@ -483,4 +485,59 @@ public void setUnwrapRequired(boolean unwrapRequired) { | |
public void setResponseAs(String[] responseAs) { | ||
this.responseAs = responseAs; | ||
} | ||
|
||
@Override | ||
public String toEnumValue(String value, String datatype) { | ||
if ("int".equals(datatype) || "double".equals(datatype) || "float".equals(datatype)) { | ||
return value; | ||
} else { | ||
return "\'" + escapeText(value) + "\'"; | ||
} | ||
} | ||
|
||
@Override | ||
public String toEnumDefaultValue(String value, String datatype) { | ||
return datatype + "_" + value; | ||
} | ||
|
||
@Override | ||
public String toEnumVarName(String name, String datatype) { | ||
// number | ||
if ("int".equals(datatype) || "double".equals(datatype) || "float".equals(datatype)) { | ||
String varName = new String(name); | ||
varName = varName.replaceAll("-", "MINUS_"); | ||
varName = varName.replaceAll("\\+", "PLUS_"); | ||
varName = varName.replaceAll("\\.", "_DOT_"); | ||
return varName; | ||
} | ||
|
||
// string | ||
String enumName = sanitizeName(underscore(name).toUpperCase()); | ||
enumName = enumName.replaceFirst("^_", ""); | ||
enumName = enumName.replaceFirst("_$", ""); | ||
|
||
if (enumName.matches("\\d.*")) { // starts with number | ||
return "_" + enumName; | ||
} else { | ||
return enumName; | ||
} | ||
} | ||
|
||
@Override | ||
public String toEnumName(CodegenProperty property) { | ||
String enumName = underscore(toModelName(property.name)).toUpperCase(); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
wing328
Author
Contributor
|
||
|
||
if (enumName.matches("\\d.*")) { // starts with number | ||
return "_" + enumName; | ||
} else { | ||
return enumName; | ||
} | ||
} | ||
|
||
@Override | ||
public Map<String, Object> postProcessModels(Map<String, Object> objs) { | ||
// process enum in models | ||
return postProcessModelsEnum(objs); | ||
} | ||
|
||
} |
Oops, something went wrong.
Typically Swift Enum names are first letter upper case and then lower case. See: https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Enumerations.html#//apple_ref/doc/uid/TP40014097-CH12-ID146
That was the case before this commit and is not anymore the case. I'm not sure why? Shouldn't we backtrack on this?