add enum name mapping feature to go generators (#17289)

This commit is contained in:
William Cheng
2023-12-04 10:52:58 +08:00
committed by GitHub
parent 2967b33ab6
commit b19bc59c6a
6 changed files with 14 additions and 4 deletions

View File

@@ -15,4 +15,6 @@ additionalProperties:
packageName: petstore
disallowAdditionalPropertiesIfNotPresent: false
generateInterfaces: true
enumNameMappings:
delivered: SHIPPED

View File

@@ -750,6 +750,10 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
@Override
public String toEnumVarName(String name, String datatype) {
if (enumNameMapping.containsKey(name)) {
return enumNameMapping.get(name);
}
if (name.length() == 0) {
return "EMPTY";
}
@@ -784,6 +788,10 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
@Override
public String toEnumName(CodegenProperty property) {
if (enumNameMapping.containsKey(property.name)) {
return enumNameMapping.get(property.name);
}
String enumName = underscore(toModelName(property.name)).toUpperCase(Locale.ROOT);
// remove [] for array or map of enum

View File

@@ -7,7 +7,7 @@
* `APPROVED` (value: `"approved"`)
* `DELIVERED` (value: `"delivered"`)
* `SHIPPED` (value: `"delivered"`)
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@@ -7,7 +7,7 @@
* `APPROVED` (value: `"approved"`)
* `DELIVERED` (value: `"delivered"`)
* `SHIPPED` (value: `"delivered"`)
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@@ -22,7 +22,7 @@ type OuterEnum string
const (
OUTERENUM_PLACED OuterEnum = "placed"
OUTERENUM_APPROVED OuterEnum = "approved"
OUTERENUM_DELIVERED OuterEnum = "delivered"
OUTERENUM_SHIPPED OuterEnum = "delivered"
)
// All allowed values of OuterEnum enum

View File

@@ -22,7 +22,7 @@ type OuterEnumDefaultValue string
const (
OUTERENUMDEFAULTVALUE_PLACED OuterEnumDefaultValue = "placed"
OUTERENUMDEFAULTVALUE_APPROVED OuterEnumDefaultValue = "approved"
OUTERENUMDEFAULTVALUE_DELIVERED OuterEnumDefaultValue = "delivered"
OUTERENUMDEFAULTVALUE_SHIPPED OuterEnumDefaultValue = "delivered"
)
// All allowed values of OuterEnumDefaultValue enum