mirror of
https://github.com/jlengrand/openapi-generator.git
synced 2026-03-10 08:31:23 +00:00
add enum name mapping feature to go generators (#17289)
This commit is contained in:
@@ -15,4 +15,6 @@ additionalProperties:
|
||||
packageName: petstore
|
||||
disallowAdditionalPropertiesIfNotPresent: false
|
||||
generateInterfaces: true
|
||||
enumNameMappings:
|
||||
delivered: SHIPPED
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user