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:
|
parameterNameMappings:
|
||||||
_type: underscore_type
|
_type: underscore_type
|
||||||
type_: type_with_underscore
|
type_: type_with_underscore
|
||||||
|
enumNameMappings:
|
||||||
|
delivered: SHIPPED
|
||||||
|
@ -508,6 +508,10 @@ public class RubyClientCodegen extends AbstractRubyCodegen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toEnumVarName(String name, String datatype) {
|
public String toEnumVarName(String name, String datatype) {
|
||||||
|
if (enumNameMapping.containsKey(name)) {
|
||||||
|
return enumNameMapping.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
if (name.length() == 0) {
|
if (name.length() == 0) {
|
||||||
return "EMPTY";
|
return "EMPTY";
|
||||||
}
|
}
|
||||||
@ -535,6 +539,10 @@ public class RubyClientCodegen extends AbstractRubyCodegen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toEnumName(CodegenProperty property) {
|
public String toEnumName(CodegenProperty property) {
|
||||||
|
if (enumNameMapping.containsKey(property.name)) {
|
||||||
|
return enumNameMapping.get(property.name);
|
||||||
|
}
|
||||||
|
|
||||||
String enumName = underscore(toModelName(property.name)).toUpperCase(Locale.ROOT);
|
String enumName = underscore(toModelName(property.name)).toUpperCase(Locale.ROOT);
|
||||||
enumName = enumName.replaceFirst("^_", "");
|
enumName = enumName.replaceFirst("^_", "");
|
||||||
enumName = enumName.replaceFirst("_$", "");
|
enumName = enumName.replaceFirst("_$", "");
|
||||||
|
@ -17,10 +17,10 @@ module Petstore
|
|||||||
class OuterEnum
|
class OuterEnum
|
||||||
PLACED = "placed".freeze
|
PLACED = "placed".freeze
|
||||||
APPROVED = "approved".freeze
|
APPROVED = "approved".freeze
|
||||||
DELIVERED = "delivered".freeze
|
SHIPPED = "delivered".freeze
|
||||||
|
|
||||||
def self.all_vars
|
def self.all_vars
|
||||||
@all_vars ||= [PLACED, APPROVED, DELIVERED].freeze
|
@all_vars ||= [PLACED, APPROVED, SHIPPED].freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
# Builds the enum from string
|
# Builds the enum from string
|
||||||
|
@ -17,10 +17,10 @@ module Petstore
|
|||||||
class OuterEnumDefaultValue
|
class OuterEnumDefaultValue
|
||||||
PLACED = "placed".freeze
|
PLACED = "placed".freeze
|
||||||
APPROVED = "approved".freeze
|
APPROVED = "approved".freeze
|
||||||
DELIVERED = "delivered".freeze
|
SHIPPED = "delivered".freeze
|
||||||
|
|
||||||
def self.all_vars
|
def self.all_vars
|
||||||
@all_vars ||= [PLACED, APPROVED, DELIVERED].freeze
|
@all_vars ||= [PLACED, APPROVED, SHIPPED].freeze
|
||||||
end
|
end
|
||||||
|
|
||||||
# Builds the enum from string
|
# Builds the enum from string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user