Merge pull request #1993 from jaz-ah/issue-1992

[Swift] fix issue 1992 - ensure that our variable names don't match the names…
This commit is contained in:
wing328 2016-02-10 13:45:53 +08:00
commit 62e3bf2543

View File

@ -189,7 +189,7 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig {
@Override @Override
public String escapeReservedWord(String name) { public String escapeReservedWord(String name) {
return "Swagger" + name; // add an underscore to the name return "_" + name; // add an underscore to the name
} }
@Override @Override
@ -264,7 +264,11 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig {
codegenProperty.allowableValues.put("values", swiftEnums); codegenProperty.allowableValues.put("values", swiftEnums);
codegenProperty.datatypeWithEnum = codegenProperty.datatypeWithEnum =
StringUtils.left(codegenProperty.datatypeWithEnum, codegenProperty.datatypeWithEnum.length() - "Enum".length()); StringUtils.left(codegenProperty.datatypeWithEnum, codegenProperty.datatypeWithEnum.length() - "Enum".length());
if (reservedWords.contains(codegenProperty.datatypeWithEnum)) { // 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
if (reservedWords.contains(codegenProperty.datatypeWithEnum) ||
name.equals(codegenProperty.datatypeWithEnum)) {
codegenProperty.datatypeWithEnum = escapeReservedWord(codegenProperty.datatypeWithEnum); codegenProperty.datatypeWithEnum = escapeReservedWord(codegenProperty.datatypeWithEnum);
} }
} }