Skip to content

Commit

Permalink
add enum name mapping feature to C# generators (#17194)
Browse files Browse the repository at this point in the history
  • Loading branch information
wing328 authored Nov 27, 2023
1 parent a117dd5 commit ac68765
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 6 deletions.
2 changes: 2 additions & 0 deletions bin/configs/csharp-restsharp-net7.0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ additionalProperties:
useOneOfDiscriminatorLookup: true
targetFramework: net7.0
equatable: true
enumNameMappings:
delivered: Shipped
Original file line number Diff line number Diff line change
Expand Up @@ -1663,6 +1663,10 @@ public String toEnumValue(String value, String datatype) {

@Override
public String toEnumVarName(String name, String datatype) {
if (enumNameMapping.containsKey(name)) {
return enumNameMapping.get(name);
}

if (name.length() == 0) {
return adjustNamingStyle("Empty");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,10 @@ public boolean getUseOneOfDiscriminatorLookup() {

@Override
public String toEnumVarName(String value, String datatype) {
if (enumNameMapping.containsKey(value)) {
return enumNameMapping.get(value);
}

if (value.length() == 0) {
return "Empty";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ public enum StatusEnum
Approved = 2,

/// <summary>
/// Enum Delivered for value: delivered
/// Enum Shipped for value: delivered
/// </summary>
[EnumMember(Value = "delivered")]
Delivered = 3
Shipped = 3
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ public enum OuterEnum
Approved = 2,

/// <summary>
/// Enum Delivered for value: delivered
/// Enum Shipped for value: delivered
/// </summary>
[EnumMember(Value = "delivered")]
Delivered = 3
Shipped = 3
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ public enum OuterEnumDefaultValue
Approved = 2,

/// <summary>
/// Enum Delivered for value: delivered
/// Enum Shipped for value: delivered
/// </summary>
[EnumMember(Value = "delivered")]
Delivered = 3
Shipped = 3
}

}

0 comments on commit ac68765

Please sign in to comment.