add enum name mapping support to ruby generators (#17537)

This commit is contained in:
William Cheng 2024-01-05 15:00:52 +08:00 committed by GitHub
parent c782526556
commit 5c571b0e1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 4 deletions

View File

@ -15,3 +15,5 @@ nameMappings:
parameterNameMappings:
_type: underscore_type
type_: type_with_underscore
enumNameMappings:
delivered: SHIPPED

View File

@ -508,6 +508,10 @@ public class RubyClientCodegen extends AbstractRubyCodegen {
@Override
public String toEnumVarName(String name, String datatype) {
if (enumNameMapping.containsKey(name)) {
return enumNameMapping.get(name);
}
if (name.length() == 0) {
return "EMPTY";
}
@ -535,6 +539,10 @@ public class RubyClientCodegen extends AbstractRubyCodegen {
@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);
enumName = enumName.replaceFirst("^_", "");
enumName = enumName.replaceFirst("_$", "");

View File

@ -17,10 +17,10 @@ module Petstore
class OuterEnum
PLACED = "placed".freeze
APPROVED = "approved".freeze
DELIVERED = "delivered".freeze
SHIPPED = "delivered".freeze
def self.all_vars
@all_vars ||= [PLACED, APPROVED, DELIVERED].freeze
@all_vars ||= [PLACED, APPROVED, SHIPPED].freeze
end
# Builds the enum from string

View File

@ -17,10 +17,10 @@ module Petstore
class OuterEnumDefaultValue
PLACED = "placed".freeze
APPROVED = "approved".freeze
DELIVERED = "delivered".freeze
SHIPPED = "delivered".freeze
def self.all_vars
@all_vars ||= [PLACED, APPROVED, DELIVERED].freeze
@all_vars ||= [PLACED, APPROVED, SHIPPED].freeze
end
# Builds the enum from string