forked from loafle/openapi-generator-original
add enum name mapping support to ruby generators (#17537)
This commit is contained in:
parent
c782526556
commit
5c571b0e1f
@ -15,3 +15,5 @@ nameMappings:
|
||||
parameterNameMappings:
|
||||
_type: underscore_type
|
||||
type_: type_with_underscore
|
||||
enumNameMappings:
|
||||
delivered: SHIPPED
|
||||
|
@ -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("_$", "");
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user