[Go] Prefix enum number with _ (#703)

* prefix enum number with _ in go

* reformat code, use else if
This commit is contained in:
William Cheng 2018-08-02 10:13:01 +08:00 committed by GitHub
parent ab08dd1d26
commit 40024ac72a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 6 deletions

View File

@ -145,7 +145,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
@Override
public String toVarName(String name) {
// replace - with _ e.g. created-at => created_at
name = sanitizeName(name);
@ -267,10 +267,10 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
// the type.
String openAPIType = getSchemaType(p);
String ref = p.get$ref();
if(ref != null && !ref.isEmpty()) {
if (ref != null && !ref.isEmpty()) {
String tryRefV2 = "#/definitions/" + openAPIType;
String tryRefV3 = "#/components/schemas/" + openAPIType;
if(ref.equals(tryRefV2) || ref.equals(tryRefV3)) {
if (ref.equals(tryRefV2) || ref.equals(tryRefV3)) {
return toModelName(openAPIType);
}
}
@ -296,7 +296,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
String ref = p.get$ref();
String type = null;
if(ref != null && !ref.isEmpty()) {
if (ref != null && !ref.isEmpty()) {
type = openAPIType;
} else if (typeMapping.containsKey(openAPIType)) {
type = typeMapping.get(openAPIType);
@ -570,8 +570,10 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
enumName = enumName.replaceFirst("^_", "");
enumName = enumName.replaceFirst("_$", "");
if (isReservedWord(enumName) || enumName.matches("\\d.*")) { // reserved word or starts with number
if (isReservedWord(enumName)) { // reserved word
return escapeReservedWord(enumName);
} else if (enumName.matches("\\d.*")) { // starts with a number
return "_" + enumName;
} else {
return enumName;
}

View File

@ -1 +1 @@
3.1.1-SNAPSHOT
3.2.0-SNAPSHOT