forked from loafle/openapi-generator-original
Support the empty string as an enumeration value (#4450)
When a string enumeration has the empty string as one of its available values, the generated code for many languages is invalid because the empty string can not be used as an identifier. As with numbers and symbols, provide a mapping to an English name which can be used as a replacement. In this case, "empty" for the empty string/empty value. Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
This commit is contained in:
@@ -100,7 +100,7 @@ module Petstore
|
||||
# Check to see if the all the properties in the model are valid
|
||||
# @return true if the model is valid
|
||||
def valid?
|
||||
enum_string_validator = EnumAttributeValidator.new('String', ["UPPER", "lower"])
|
||||
enum_string_validator = EnumAttributeValidator.new('String', ["UPPER", "lower", ""])
|
||||
return false unless enum_string_validator.valid?(@enum_string)
|
||||
enum_integer_validator = EnumAttributeValidator.new('Integer', ["1", "-1"])
|
||||
return false unless enum_integer_validator.valid?(@enum_integer)
|
||||
@@ -112,7 +112,7 @@ module Petstore
|
||||
# Custom attribute writer method checking allowed values (enum).
|
||||
# @param [Object] enum_string Object to be assigned
|
||||
def enum_string=(enum_string)
|
||||
validator = EnumAttributeValidator.new('String', ["UPPER", "lower"])
|
||||
validator = EnumAttributeValidator.new('String', ["UPPER", "lower", ""])
|
||||
unless validator.valid?(enum_string)
|
||||
fail ArgumentError, "invalid value for 'enum_string', must be one of #{validator.allowable_values}."
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user