mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-07 02:55:19 +00:00
[Go] Prefix enum number with _ (#703)
* prefix enum number with _ in go * reformat code, use else if
This commit is contained in:
parent
ab08dd1d26
commit
40024ac72a
@ -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;
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
3.1.1-SNAPSHOT
|
||||
3.2.0-SNAPSHOT
|
Loading…
Reference in New Issue
Block a user