Skip to content

Commit b19bc59

Browse files
authored
add enum name mapping feature to go generators (#17289)
1 parent 2967b33 commit b19bc59

File tree

6 files changed

+14
-4
lines changed

6 files changed

+14
-4
lines changed

bin/configs/go-petstore.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ additionalProperties:
1515
packageName: petstore
1616
disallowAdditionalPropertiesIfNotPresent: false
1717
generateInterfaces: true
18+
enumNameMappings:
19+
delivered: SHIPPED
1820

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractGoCodegen.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,10 @@ public String toEnumDefaultValue(String value, String datatype) {
750750

751751
@Override
752752
public String toEnumVarName(String name, String datatype) {
753+
if (enumNameMapping.containsKey(name)) {
754+
return enumNameMapping.get(name);
755+
}
756+
753757
if (name.length() == 0) {
754758
return "EMPTY";
755759
}
@@ -784,6 +788,10 @@ public String toEnumVarName(String name, String datatype) {
784788

785789
@Override
786790
public String toEnumName(CodegenProperty property) {
791+
if (enumNameMapping.containsKey(property.name)) {
792+
return enumNameMapping.get(property.name);
793+
}
794+
787795
String enumName = underscore(toModelName(property.name)).toUpperCase(Locale.ROOT);
788796

789797
// remove [] for array or map of enum

samples/openapi3/client/petstore/go/go-petstore/docs/OuterEnum.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
* `APPROVED` (value: `"approved"`)
99

10-
* `DELIVERED` (value: `"delivered"`)
10+
* `SHIPPED` (value: `"delivered"`)
1111

1212

1313
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

samples/openapi3/client/petstore/go/go-petstore/docs/OuterEnumDefaultValue.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
* `APPROVED` (value: `"approved"`)
99

10-
* `DELIVERED` (value: `"delivered"`)
10+
* `SHIPPED` (value: `"delivered"`)
1111

1212

1313
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

samples/openapi3/client/petstore/go/go-petstore/model_outer_enum.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/openapi3/client/petstore/go/go-petstore/model_outer_enum_default_value.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)