forked from loafle/openapi-generator-original
[Ruby] Change constants lookup methods in enum class (#13285)
* [Ruby] Add missing block ends * [Ruby] Change constants lookup methods in enum class * Update ruby samples
This commit is contained in:
parent
d75b7b6194
commit
1f9f94066a
@ -2,6 +2,10 @@
|
|||||||
{{{name}}} = {{{value}}}.freeze{{/enumVars}}
|
{{{name}}} = {{{value}}}.freeze{{/enumVars}}
|
||||||
|
|
||||||
{{/allowableValues}}
|
{{/allowableValues}}
|
||||||
|
def self.all_vars
|
||||||
|
@all_vars ||= [{{#allowableValues}}{{#enumVars}}{{{name}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}].freeze
|
||||||
|
end
|
||||||
|
|
||||||
# Builds the enum from string
|
# Builds the enum from string
|
||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
@ -13,8 +17,7 @@
|
|||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
def build_from_hash(value)
|
def build_from_hash(value)
|
||||||
constantValues = {{classname}}.constants.select { |c| {{classname}}::const_get(c) == value }
|
return value if {{classname}}.all_vars.include?(value)
|
||||||
raise "Invalid ENUM value #{value} for class #{{{classname}}}" if constantValues.empty?
|
raise "Invalid ENUM value #{value} for class #{{{classname}}}"
|
||||||
value
|
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -60,6 +60,7 @@ require '{{{gemName}}}'
|
|||||||
# }
|
# }
|
||||||
{{/-last}}
|
{{/-last}}
|
||||||
{{/mappedModels}}
|
{{/mappedModels}}
|
||||||
|
```
|
||||||
{{/discriminator}}
|
{{/discriminator}}
|
||||||
|
|
||||||
### build
|
### build
|
||||||
|
@ -19,6 +19,10 @@ module Petstore
|
|||||||
EFG = "-efg".freeze
|
EFG = "-efg".freeze
|
||||||
XYZ = "(xyz)".freeze
|
XYZ = "(xyz)".freeze
|
||||||
|
|
||||||
|
def self.all_vars
|
||||||
|
@all_vars ||= [ABC, EFG, XYZ].freeze
|
||||||
|
end
|
||||||
|
|
||||||
# Builds the enum from string
|
# Builds the enum from string
|
||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
@ -30,9 +34,8 @@ module Petstore
|
|||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
def build_from_hash(value)
|
def build_from_hash(value)
|
||||||
constantValues = EnumClass.constants.select { |c| EnumClass::const_get(c) == value }
|
return value if EnumClass.all_vars.include?(value)
|
||||||
raise "Invalid ENUM value #{value} for class #EnumClass" if constantValues.empty?
|
raise "Invalid ENUM value #{value} for class #EnumClass"
|
||||||
value
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -19,6 +19,10 @@ module Petstore
|
|||||||
APPROVED = "approved".freeze
|
APPROVED = "approved".freeze
|
||||||
DELIVERED = "delivered".freeze
|
DELIVERED = "delivered".freeze
|
||||||
|
|
||||||
|
def self.all_vars
|
||||||
|
@all_vars ||= [PLACED, APPROVED, DELIVERED].freeze
|
||||||
|
end
|
||||||
|
|
||||||
# Builds the enum from string
|
# Builds the enum from string
|
||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
@ -30,9 +34,8 @@ module Petstore
|
|||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
def build_from_hash(value)
|
def build_from_hash(value)
|
||||||
constantValues = OuterEnum.constants.select { |c| OuterEnum::const_get(c) == value }
|
return value if OuterEnum.all_vars.include?(value)
|
||||||
raise "Invalid ENUM value #{value} for class #OuterEnum" if constantValues.empty?
|
raise "Invalid ENUM value #{value} for class #OuterEnum"
|
||||||
value
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -19,6 +19,10 @@ module Petstore
|
|||||||
APPROVED = "approved".freeze
|
APPROVED = "approved".freeze
|
||||||
DELIVERED = "delivered".freeze
|
DELIVERED = "delivered".freeze
|
||||||
|
|
||||||
|
def self.all_vars
|
||||||
|
@all_vars ||= [PLACED, APPROVED, DELIVERED].freeze
|
||||||
|
end
|
||||||
|
|
||||||
# Builds the enum from string
|
# Builds the enum from string
|
||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
@ -30,9 +34,8 @@ module Petstore
|
|||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
def build_from_hash(value)
|
def build_from_hash(value)
|
||||||
constantValues = OuterEnumDefaultValue.constants.select { |c| OuterEnumDefaultValue::const_get(c) == value }
|
return value if OuterEnumDefaultValue.all_vars.include?(value)
|
||||||
raise "Invalid ENUM value #{value} for class #OuterEnumDefaultValue" if constantValues.empty?
|
raise "Invalid ENUM value #{value} for class #OuterEnumDefaultValue"
|
||||||
value
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -19,6 +19,10 @@ module Petstore
|
|||||||
N1 = 1.freeze
|
N1 = 1.freeze
|
||||||
N2 = 2.freeze
|
N2 = 2.freeze
|
||||||
|
|
||||||
|
def self.all_vars
|
||||||
|
@all_vars ||= [N0, N1, N2].freeze
|
||||||
|
end
|
||||||
|
|
||||||
# Builds the enum from string
|
# Builds the enum from string
|
||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
@ -30,9 +34,8 @@ module Petstore
|
|||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
def build_from_hash(value)
|
def build_from_hash(value)
|
||||||
constantValues = OuterEnumInteger.constants.select { |c| OuterEnumInteger::const_get(c) == value }
|
return value if OuterEnumInteger.all_vars.include?(value)
|
||||||
raise "Invalid ENUM value #{value} for class #OuterEnumInteger" if constantValues.empty?
|
raise "Invalid ENUM value #{value} for class #OuterEnumInteger"
|
||||||
value
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -19,6 +19,10 @@ module Petstore
|
|||||||
N1 = 1.freeze
|
N1 = 1.freeze
|
||||||
N2 = 2.freeze
|
N2 = 2.freeze
|
||||||
|
|
||||||
|
def self.all_vars
|
||||||
|
@all_vars ||= [N0, N1, N2].freeze
|
||||||
|
end
|
||||||
|
|
||||||
# Builds the enum from string
|
# Builds the enum from string
|
||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
@ -30,9 +34,8 @@ module Petstore
|
|||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
def build_from_hash(value)
|
def build_from_hash(value)
|
||||||
constantValues = OuterEnumIntegerDefaultValue.constants.select { |c| OuterEnumIntegerDefaultValue::const_get(c) == value }
|
return value if OuterEnumIntegerDefaultValue.all_vars.include?(value)
|
||||||
raise "Invalid ENUM value #{value} for class #OuterEnumIntegerDefaultValue" if constantValues.empty?
|
raise "Invalid ENUM value #{value} for class #OuterEnumIntegerDefaultValue"
|
||||||
value
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -18,6 +18,10 @@ module Petstore
|
|||||||
ADMIN = "admin".freeze
|
ADMIN = "admin".freeze
|
||||||
USER = "user".freeze
|
USER = "user".freeze
|
||||||
|
|
||||||
|
def self.all_vars
|
||||||
|
@all_vars ||= [ADMIN, USER].freeze
|
||||||
|
end
|
||||||
|
|
||||||
# Builds the enum from string
|
# Builds the enum from string
|
||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
@ -29,9 +33,8 @@ module Petstore
|
|||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
def build_from_hash(value)
|
def build_from_hash(value)
|
||||||
constantValues = SingleRefType.constants.select { |c| SingleRefType::const_get(c) == value }
|
return value if SingleRefType.all_vars.include?(value)
|
||||||
raise "Invalid ENUM value #{value} for class #SingleRefType" if constantValues.empty?
|
raise "Invalid ENUM value #{value} for class #SingleRefType"
|
||||||
value
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -19,6 +19,10 @@ module Petstore
|
|||||||
EFG = "-efg".freeze
|
EFG = "-efg".freeze
|
||||||
XYZ = "(xyz)".freeze
|
XYZ = "(xyz)".freeze
|
||||||
|
|
||||||
|
def self.all_vars
|
||||||
|
@all_vars ||= [ABC, EFG, XYZ].freeze
|
||||||
|
end
|
||||||
|
|
||||||
# Builds the enum from string
|
# Builds the enum from string
|
||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
@ -30,9 +34,8 @@ module Petstore
|
|||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
def build_from_hash(value)
|
def build_from_hash(value)
|
||||||
constantValues = EnumClass.constants.select { |c| EnumClass::const_get(c) == value }
|
return value if EnumClass.all_vars.include?(value)
|
||||||
raise "Invalid ENUM value #{value} for class #EnumClass" if constantValues.empty?
|
raise "Invalid ENUM value #{value} for class #EnumClass"
|
||||||
value
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -19,6 +19,10 @@ module Petstore
|
|||||||
APPROVED = "approved".freeze
|
APPROVED = "approved".freeze
|
||||||
DELIVERED = "delivered".freeze
|
DELIVERED = "delivered".freeze
|
||||||
|
|
||||||
|
def self.all_vars
|
||||||
|
@all_vars ||= [PLACED, APPROVED, DELIVERED].freeze
|
||||||
|
end
|
||||||
|
|
||||||
# Builds the enum from string
|
# Builds the enum from string
|
||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
@ -30,9 +34,8 @@ module Petstore
|
|||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
def build_from_hash(value)
|
def build_from_hash(value)
|
||||||
constantValues = OuterEnum.constants.select { |c| OuterEnum::const_get(c) == value }
|
return value if OuterEnum.all_vars.include?(value)
|
||||||
raise "Invalid ENUM value #{value} for class #OuterEnum" if constantValues.empty?
|
raise "Invalid ENUM value #{value} for class #OuterEnum"
|
||||||
value
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -19,6 +19,10 @@ module Petstore
|
|||||||
APPROVED = "approved".freeze
|
APPROVED = "approved".freeze
|
||||||
DELIVERED = "delivered".freeze
|
DELIVERED = "delivered".freeze
|
||||||
|
|
||||||
|
def self.all_vars
|
||||||
|
@all_vars ||= [PLACED, APPROVED, DELIVERED].freeze
|
||||||
|
end
|
||||||
|
|
||||||
# Builds the enum from string
|
# Builds the enum from string
|
||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
@ -30,9 +34,8 @@ module Petstore
|
|||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
def build_from_hash(value)
|
def build_from_hash(value)
|
||||||
constantValues = OuterEnumDefaultValue.constants.select { |c| OuterEnumDefaultValue::const_get(c) == value }
|
return value if OuterEnumDefaultValue.all_vars.include?(value)
|
||||||
raise "Invalid ENUM value #{value} for class #OuterEnumDefaultValue" if constantValues.empty?
|
raise "Invalid ENUM value #{value} for class #OuterEnumDefaultValue"
|
||||||
value
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -19,6 +19,10 @@ module Petstore
|
|||||||
N1 = 1.freeze
|
N1 = 1.freeze
|
||||||
N2 = 2.freeze
|
N2 = 2.freeze
|
||||||
|
|
||||||
|
def self.all_vars
|
||||||
|
@all_vars ||= [N0, N1, N2].freeze
|
||||||
|
end
|
||||||
|
|
||||||
# Builds the enum from string
|
# Builds the enum from string
|
||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
@ -30,9 +34,8 @@ module Petstore
|
|||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
def build_from_hash(value)
|
def build_from_hash(value)
|
||||||
constantValues = OuterEnumInteger.constants.select { |c| OuterEnumInteger::const_get(c) == value }
|
return value if OuterEnumInteger.all_vars.include?(value)
|
||||||
raise "Invalid ENUM value #{value} for class #OuterEnumInteger" if constantValues.empty?
|
raise "Invalid ENUM value #{value} for class #OuterEnumInteger"
|
||||||
value
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -19,6 +19,10 @@ module Petstore
|
|||||||
N1 = 1.freeze
|
N1 = 1.freeze
|
||||||
N2 = 2.freeze
|
N2 = 2.freeze
|
||||||
|
|
||||||
|
def self.all_vars
|
||||||
|
@all_vars ||= [N0, N1, N2].freeze
|
||||||
|
end
|
||||||
|
|
||||||
# Builds the enum from string
|
# Builds the enum from string
|
||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
@ -30,9 +34,8 @@ module Petstore
|
|||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
def build_from_hash(value)
|
def build_from_hash(value)
|
||||||
constantValues = OuterEnumIntegerDefaultValue.constants.select { |c| OuterEnumIntegerDefaultValue::const_get(c) == value }
|
return value if OuterEnumIntegerDefaultValue.all_vars.include?(value)
|
||||||
raise "Invalid ENUM value #{value} for class #OuterEnumIntegerDefaultValue" if constantValues.empty?
|
raise "Invalid ENUM value #{value} for class #OuterEnumIntegerDefaultValue"
|
||||||
value
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -18,6 +18,10 @@ module Petstore
|
|||||||
ADMIN = "admin".freeze
|
ADMIN = "admin".freeze
|
||||||
USER = "user".freeze
|
USER = "user".freeze
|
||||||
|
|
||||||
|
def self.all_vars
|
||||||
|
@all_vars ||= [ADMIN, USER].freeze
|
||||||
|
end
|
||||||
|
|
||||||
# Builds the enum from string
|
# Builds the enum from string
|
||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
@ -29,9 +33,8 @@ module Petstore
|
|||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
def build_from_hash(value)
|
def build_from_hash(value)
|
||||||
constantValues = SingleRefType.constants.select { |c| SingleRefType::const_get(c) == value }
|
return value if SingleRefType.all_vars.include?(value)
|
||||||
raise "Invalid ENUM value #{value} for class #SingleRefType" if constantValues.empty?
|
raise "Invalid ENUM value #{value} for class #SingleRefType"
|
||||||
value
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -19,6 +19,10 @@ module Petstore
|
|||||||
EFG = "-efg".freeze
|
EFG = "-efg".freeze
|
||||||
XYZ = "(xyz)".freeze
|
XYZ = "(xyz)".freeze
|
||||||
|
|
||||||
|
def self.all_vars
|
||||||
|
@all_vars ||= [ABC, EFG, XYZ].freeze
|
||||||
|
end
|
||||||
|
|
||||||
# Builds the enum from string
|
# Builds the enum from string
|
||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
@ -30,9 +34,8 @@ module Petstore
|
|||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
def build_from_hash(value)
|
def build_from_hash(value)
|
||||||
constantValues = EnumClass.constants.select { |c| EnumClass::const_get(c) == value }
|
return value if EnumClass.all_vars.include?(value)
|
||||||
raise "Invalid ENUM value #{value} for class #EnumClass" if constantValues.empty?
|
raise "Invalid ENUM value #{value} for class #EnumClass"
|
||||||
value
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -19,6 +19,10 @@ module Petstore
|
|||||||
APPROVED = "approved".freeze
|
APPROVED = "approved".freeze
|
||||||
DELIVERED = "delivered".freeze
|
DELIVERED = "delivered".freeze
|
||||||
|
|
||||||
|
def self.all_vars
|
||||||
|
@all_vars ||= [PLACED, APPROVED, DELIVERED].freeze
|
||||||
|
end
|
||||||
|
|
||||||
# Builds the enum from string
|
# Builds the enum from string
|
||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
@ -30,9 +34,8 @@ module Petstore
|
|||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
def build_from_hash(value)
|
def build_from_hash(value)
|
||||||
constantValues = OuterEnum.constants.select { |c| OuterEnum::const_get(c) == value }
|
return value if OuterEnum.all_vars.include?(value)
|
||||||
raise "Invalid ENUM value #{value} for class #OuterEnum" if constantValues.empty?
|
raise "Invalid ENUM value #{value} for class #OuterEnum"
|
||||||
value
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -19,6 +19,10 @@ module Petstore
|
|||||||
APPROVED = "approved".freeze
|
APPROVED = "approved".freeze
|
||||||
DELIVERED = "delivered".freeze
|
DELIVERED = "delivered".freeze
|
||||||
|
|
||||||
|
def self.all_vars
|
||||||
|
@all_vars ||= [PLACED, APPROVED, DELIVERED].freeze
|
||||||
|
end
|
||||||
|
|
||||||
# Builds the enum from string
|
# Builds the enum from string
|
||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
@ -30,9 +34,8 @@ module Petstore
|
|||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
def build_from_hash(value)
|
def build_from_hash(value)
|
||||||
constantValues = OuterEnumDefaultValue.constants.select { |c| OuterEnumDefaultValue::const_get(c) == value }
|
return value if OuterEnumDefaultValue.all_vars.include?(value)
|
||||||
raise "Invalid ENUM value #{value} for class #OuterEnumDefaultValue" if constantValues.empty?
|
raise "Invalid ENUM value #{value} for class #OuterEnumDefaultValue"
|
||||||
value
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -19,6 +19,10 @@ module Petstore
|
|||||||
N1 = 1.freeze
|
N1 = 1.freeze
|
||||||
N2 = 2.freeze
|
N2 = 2.freeze
|
||||||
|
|
||||||
|
def self.all_vars
|
||||||
|
@all_vars ||= [N0, N1, N2].freeze
|
||||||
|
end
|
||||||
|
|
||||||
# Builds the enum from string
|
# Builds the enum from string
|
||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
@ -30,9 +34,8 @@ module Petstore
|
|||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
def build_from_hash(value)
|
def build_from_hash(value)
|
||||||
constantValues = OuterEnumInteger.constants.select { |c| OuterEnumInteger::const_get(c) == value }
|
return value if OuterEnumInteger.all_vars.include?(value)
|
||||||
raise "Invalid ENUM value #{value} for class #OuterEnumInteger" if constantValues.empty?
|
raise "Invalid ENUM value #{value} for class #OuterEnumInteger"
|
||||||
value
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -19,6 +19,10 @@ module Petstore
|
|||||||
N1 = 1.freeze
|
N1 = 1.freeze
|
||||||
N2 = 2.freeze
|
N2 = 2.freeze
|
||||||
|
|
||||||
|
def self.all_vars
|
||||||
|
@all_vars ||= [N0, N1, N2].freeze
|
||||||
|
end
|
||||||
|
|
||||||
# Builds the enum from string
|
# Builds the enum from string
|
||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
@ -30,9 +34,8 @@ module Petstore
|
|||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
def build_from_hash(value)
|
def build_from_hash(value)
|
||||||
constantValues = OuterEnumIntegerDefaultValue.constants.select { |c| OuterEnumIntegerDefaultValue::const_get(c) == value }
|
return value if OuterEnumIntegerDefaultValue.all_vars.include?(value)
|
||||||
raise "Invalid ENUM value #{value} for class #OuterEnumIntegerDefaultValue" if constantValues.empty?
|
raise "Invalid ENUM value #{value} for class #OuterEnumIntegerDefaultValue"
|
||||||
value
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -18,6 +18,10 @@ module Petstore
|
|||||||
ADMIN = "admin".freeze
|
ADMIN = "admin".freeze
|
||||||
USER = "user".freeze
|
USER = "user".freeze
|
||||||
|
|
||||||
|
def self.all_vars
|
||||||
|
@all_vars ||= [ADMIN, USER].freeze
|
||||||
|
end
|
||||||
|
|
||||||
# Builds the enum from string
|
# Builds the enum from string
|
||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
@ -29,9 +33,8 @@ module Petstore
|
|||||||
# @param [String] The enum value in the form of the string
|
# @param [String] The enum value in the form of the string
|
||||||
# @return [String] The enum value
|
# @return [String] The enum value
|
||||||
def build_from_hash(value)
|
def build_from_hash(value)
|
||||||
constantValues = SingleRefType.constants.select { |c| SingleRefType::const_get(c) == value }
|
return value if SingleRefType.all_vars.include?(value)
|
||||||
raise "Invalid ENUM value #{value} for class #SingleRefType" if constantValues.empty?
|
raise "Invalid ENUM value #{value} for class #SingleRefType"
|
||||||
value
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user