[Ruby] Fix enum expansion in Ruby client (#2081) (#2104)

* use double-quote string for enum value (#2081)

* use enumVars in templates for Ruby client (#2081)

* delete unnecessary line in enum model of Ruby client (#2081)

* update samples of Ruby client (#2081)
This commit is contained in:
Akira Tanimura 2019-02-12 01:32:36 +09:00 committed by William Cheng
parent 5c64b58bae
commit 33a8939bd5
21 changed files with 108 additions and 93 deletions

View File

@ -401,7 +401,7 @@ public class RubyClientCodegen extends AbstractRubyCodegen {
if ("Integer".equals(datatype) || "Float".equals(datatype)) { if ("Integer".equals(datatype) || "Float".equals(datatype)) {
return value; return value;
} else { } else {
return "'" + escapeText(value) + "'"; return "\"" + escapeText(value) + "\"";
} }
} }

View File

@ -52,8 +52,9 @@ module {{moduleName}}
{{#isEnum}} {{#isEnum}}
{{^isContainer}} {{^isContainer}}
# verify enum value # verify enum value
if @api_client.config.client_side_validation && ![{{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}].include?({{{paramName}}}) allowable_values = [{{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}]
fail ArgumentError, "invalid value for '{{{paramName}}}', must be one of {{#allowableValues}}{{#values}}{{{this}}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}" if @api_client.config.client_side_validation && !allowable_values.include?({{{paramName}}})
fail ArgumentError, "invalid value for \"{{{paramName}}}\", must be one of #{allowable_values}"
end end
{{/isContainer}} {{/isContainer}}
{{/isEnum}} {{/isEnum}}
@ -62,13 +63,15 @@ module {{moduleName}}
{{^required}} {{^required}}
{{#isEnum}} {{#isEnum}}
{{#collectionFormat}} {{#collectionFormat}}
if @api_client.config.client_side_validation && opts[:'{{{paramName}}}'] && !opts[:'{{{paramName}}}'].all? { |item| [{{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}].include?(item) } allowable_values = [{{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}]
fail ArgumentError, 'invalid value for "{{{paramName}}}", must include one of {{#allowableValues}}{{#values}}{{{this}}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}' if @api_client.config.client_side_validation && opts[:'{{{paramName}}}'] && !opts[:'{{{paramName}}}'].all? { |item| allowable_values.include?(item) }
fail ArgumentError, "invalid value for \"{{{paramName}}}\", must include one of #{allowable_values}"
end end
{{/collectionFormat}} {{/collectionFormat}}
{{^collectionFormat}} {{^collectionFormat}}
if @api_client.config.client_side_validation && opts[:'{{{paramName}}}'] && ![{{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}].include?(opts[:'{{{paramName}}}']) allowable_values = [{{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}]
fail ArgumentError, 'invalid value for "{{{paramName}}}", must be one of {{#allowableValues}}{{#values}}{{{this}}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}' if @api_client.config.client_side_validation && opts[:'{{{paramName}}}'] && !allowable_values.include?(opts[:'{{{paramName}}}'])
fail ArgumentError, "invalid value for \"{{{paramName}}}\", must be one of #{allowable_values}"
end end
{{/collectionFormat}} {{/collectionFormat}}
{{/isEnum}} {{/isEnum}}

View File

@ -31,7 +31,7 @@ describe '{{classname}}' do
it 'should work' do it 'should work' do
{{#isEnum}} {{#isEnum}}
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
# validator = Petstore::EnumTest::EnumAttributeValidator.new('{{{dataType}}}', [{{#allowableValues}}{{#values}}"{{{this}}}"{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}]) # validator = Petstore::EnumTest::EnumAttributeValidator.new('{{{dataType}}}', [{{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}])
# validator.allowable_values.each do |value| # validator.allowable_values.each do |value|
# expect { @instance.{{name}} = value }.not_to raise_error # expect { @instance.{{name}} = value }.not_to raise_error
# end # end

View File

@ -1,7 +1,7 @@
class {{classname}} class {{classname}}{{#allowableValues}}{{#enumVars}}
{{#allowableValues}}{{#enumVars}} {{{name}}} = {{{value}}}.freeze{{/enumVars}}
{{{name}}} = {{{value}}}.freeze{{/enumVars}}{{/allowableValues}}
{{/allowableValues}}
# 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

View File

@ -207,7 +207,7 @@
{{/isNullable}} {{/isNullable}}
{{#isEnum}} {{#isEnum}}
{{^isContainer}} {{^isContainer}}
{{{name}}}_validator = EnumAttributeValidator.new('{{{dataType}}}', [{{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}]) {{{name}}}_validator = EnumAttributeValidator.new('{{{dataType}}}', [{{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}])
return false unless {{{name}}}_validator.valid?(@{{{name}}}) return false unless {{{name}}}_validator.valid?(@{{{name}}})
{{/isContainer}} {{/isContainer}}
{{/isEnum}} {{/isEnum}}
@ -280,7 +280,7 @@
# Custom attribute writer method checking allowed values (enum). # Custom attribute writer method checking allowed values (enum).
# @param [Object] {{{name}}} Object to be assigned # @param [Object] {{{name}}} Object to be assigned
def {{{name}}}=({{{name}}}) def {{{name}}}=({{{name}}})
validator = EnumAttributeValidator.new('{{{dataType}}}', [{{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}]) validator = EnumAttributeValidator.new('{{{dataType}}}', [{{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}])
unless validator.valid?({{{name}}}) unless validator.valid?({{{name}}})
fail ArgumentError, "invalid value for \"{{{name}}}\", must be one of #{validator.allowable_values}." fail ArgumentError, "invalid value for \"{{{name}}}\", must be one of #{validator.allowable_values}."
end end

View File

@ -608,29 +608,37 @@ module Petstore
if @api_client.config.debugging if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: FakeApi.test_enum_parameters ...' @api_client.config.logger.debug 'Calling API: FakeApi.test_enum_parameters ...'
end end
if @api_client.config.client_side_validation && opts[:'enum_header_string_array'] && !opts[:'enum_header_string_array'].all? { |item| ['>', '$'].include?(item) } allowable_values = [">", "$"]
fail ArgumentError, 'invalid value for "enum_header_string_array", must include one of >, $' if @api_client.config.client_side_validation && opts[:'enum_header_string_array'] && !opts[:'enum_header_string_array'].all? { |item| allowable_values.include?(item) }
fail ArgumentError, "invalid value for \"enum_header_string_array\", must include one of #{allowable_values}"
end end
if @api_client.config.client_side_validation && opts[:'enum_header_string'] && !['_abc', '-efg', '(xyz)'].include?(opts[:'enum_header_string']) allowable_values = ["_abc", "-efg", "(xyz)"]
fail ArgumentError, 'invalid value for "enum_header_string", must be one of _abc, -efg, (xyz)' if @api_client.config.client_side_validation && opts[:'enum_header_string'] && !allowable_values.include?(opts[:'enum_header_string'])
fail ArgumentError, "invalid value for \"enum_header_string\", must be one of #{allowable_values}"
end end
if @api_client.config.client_side_validation && opts[:'enum_query_string_array'] && !opts[:'enum_query_string_array'].all? { |item| ['>', '$'].include?(item) } allowable_values = [">", "$"]
fail ArgumentError, 'invalid value for "enum_query_string_array", must include one of >, $' if @api_client.config.client_side_validation && opts[:'enum_query_string_array'] && !opts[:'enum_query_string_array'].all? { |item| allowable_values.include?(item) }
fail ArgumentError, "invalid value for \"enum_query_string_array\", must include one of #{allowable_values}"
end end
if @api_client.config.client_side_validation && opts[:'enum_query_string'] && !['_abc', '-efg', '(xyz)'].include?(opts[:'enum_query_string']) allowable_values = ["_abc", "-efg", "(xyz)"]
fail ArgumentError, 'invalid value for "enum_query_string", must be one of _abc, -efg, (xyz)' if @api_client.config.client_side_validation && opts[:'enum_query_string'] && !allowable_values.include?(opts[:'enum_query_string'])
fail ArgumentError, "invalid value for \"enum_query_string\", must be one of #{allowable_values}"
end end
if @api_client.config.client_side_validation && opts[:'enum_query_integer'] && !['1', '-2'].include?(opts[:'enum_query_integer']) allowable_values = [1, -2]
fail ArgumentError, 'invalid value for "enum_query_integer", must be one of 1, -2' if @api_client.config.client_side_validation && opts[:'enum_query_integer'] && !allowable_values.include?(opts[:'enum_query_integer'])
fail ArgumentError, "invalid value for \"enum_query_integer\", must be one of #{allowable_values}"
end end
if @api_client.config.client_side_validation && opts[:'enum_query_double'] && !['1.1', '-1.2'].include?(opts[:'enum_query_double']) allowable_values = [1.1, -1.2]
fail ArgumentError, 'invalid value for "enum_query_double", must be one of 1.1, -1.2' if @api_client.config.client_side_validation && opts[:'enum_query_double'] && !allowable_values.include?(opts[:'enum_query_double'])
fail ArgumentError, "invalid value for \"enum_query_double\", must be one of #{allowable_values}"
end end
if @api_client.config.client_side_validation && opts[:'enum_form_string_array'] && !opts[:'enum_form_string_array'].all? { |item| ['>', '$'].include?(item) } allowable_values = [">", "$"]
fail ArgumentError, 'invalid value for "enum_form_string_array", must include one of >, $' if @api_client.config.client_side_validation && opts[:'enum_form_string_array'] && !opts[:'enum_form_string_array'].all? { |item| allowable_values.include?(item) }
fail ArgumentError, "invalid value for \"enum_form_string_array\", must include one of #{allowable_values}"
end end
if @api_client.config.client_side_validation && opts[:'enum_form_string'] && !['_abc', '-efg', '(xyz)'].include?(opts[:'enum_form_string']) allowable_values = ["_abc", "-efg", "(xyz)"]
fail ArgumentError, 'invalid value for "enum_form_string", must be one of _abc, -efg, (xyz)' if @api_client.config.client_side_validation && opts[:'enum_form_string'] && !allowable_values.include?(opts[:'enum_form_string'])
fail ArgumentError, "invalid value for \"enum_form_string\", must be one of #{allowable_values}"
end end
# resource path # resource path
local_var_path = '/fake' local_var_path = '/fake'

View File

@ -85,7 +85,7 @@ module Petstore
# Check to see if the all the properties in the model are valid # Check to see if the all the properties in the model are valid
# @return true if the model is valid # @return true if the model is valid
def valid? def valid?
just_symbol_validator = EnumAttributeValidator.new('String', ['>=', '$']) just_symbol_validator = EnumAttributeValidator.new('String', [">=", "$"])
return false unless just_symbol_validator.valid?(@just_symbol) return false unless just_symbol_validator.valid?(@just_symbol)
true true
end end
@ -93,7 +93,7 @@ module Petstore
# Custom attribute writer method checking allowed values (enum). # Custom attribute writer method checking allowed values (enum).
# @param [Object] just_symbol Object to be assigned # @param [Object] just_symbol Object to be assigned
def just_symbol=(just_symbol) def just_symbol=(just_symbol)
validator = EnumAttributeValidator.new('String', ['>=', '$']) validator = EnumAttributeValidator.new('String', [">=", "$"])
unless validator.valid?(just_symbol) unless validator.valid?(just_symbol)
fail ArgumentError, "invalid value for \"just_symbol\", must be one of #{validator.allowable_values}." fail ArgumentError, "invalid value for \"just_symbol\", must be one of #{validator.allowable_values}."
end end

View File

@ -14,10 +14,9 @@ require 'date'
module Petstore module Petstore
class EnumClass class EnumClass
ABC = "_abc".freeze
ABC = '_abc'.freeze EFG = "-efg".freeze
EFG = '-efg'.freeze XYZ = "(xyz)".freeze
XYZ = '(xyz)'.freeze
# 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

View File

@ -111,14 +111,14 @@ module Petstore
# Check to see if the all the properties in the model are valid # Check to see if the all the properties in the model are valid
# @return true if the model is valid # @return true if the model is valid
def 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) return false unless enum_string_validator.valid?(@enum_string)
return false if @enum_string_required.nil? return false if @enum_string_required.nil?
enum_string_required_validator = EnumAttributeValidator.new('String', ['UPPER', 'lower', '']) enum_string_required_validator = EnumAttributeValidator.new('String', ["UPPER", "lower", ""])
return false unless enum_string_required_validator.valid?(@enum_string_required) return false unless enum_string_required_validator.valid?(@enum_string_required)
enum_integer_validator = EnumAttributeValidator.new('Integer', ['1', '-1']) enum_integer_validator = EnumAttributeValidator.new('Integer', [1, -1])
return false unless enum_integer_validator.valid?(@enum_integer) return false unless enum_integer_validator.valid?(@enum_integer)
enum_number_validator = EnumAttributeValidator.new('Float', ['1.1', '-1.2']) enum_number_validator = EnumAttributeValidator.new('Float', [1.1, -1.2])
return false unless enum_number_validator.valid?(@enum_number) return false unless enum_number_validator.valid?(@enum_number)
true true
end end
@ -126,7 +126,7 @@ module Petstore
# Custom attribute writer method checking allowed values (enum). # Custom attribute writer method checking allowed values (enum).
# @param [Object] enum_string Object to be assigned # @param [Object] enum_string Object to be assigned
def enum_string=(enum_string) def enum_string=(enum_string)
validator = EnumAttributeValidator.new('String', ['UPPER', 'lower', '']) validator = EnumAttributeValidator.new('String', ["UPPER", "lower", ""])
unless validator.valid?(enum_string) unless validator.valid?(enum_string)
fail ArgumentError, "invalid value for \"enum_string\", must be one of #{validator.allowable_values}." fail ArgumentError, "invalid value for \"enum_string\", must be one of #{validator.allowable_values}."
end end
@ -136,7 +136,7 @@ module Petstore
# Custom attribute writer method checking allowed values (enum). # Custom attribute writer method checking allowed values (enum).
# @param [Object] enum_string_required Object to be assigned # @param [Object] enum_string_required Object to be assigned
def enum_string_required=(enum_string_required) def enum_string_required=(enum_string_required)
validator = EnumAttributeValidator.new('String', ['UPPER', 'lower', '']) validator = EnumAttributeValidator.new('String', ["UPPER", "lower", ""])
unless validator.valid?(enum_string_required) unless validator.valid?(enum_string_required)
fail ArgumentError, "invalid value for \"enum_string_required\", must be one of #{validator.allowable_values}." fail ArgumentError, "invalid value for \"enum_string_required\", must be one of #{validator.allowable_values}."
end end
@ -146,7 +146,7 @@ module Petstore
# Custom attribute writer method checking allowed values (enum). # Custom attribute writer method checking allowed values (enum).
# @param [Object] enum_integer Object to be assigned # @param [Object] enum_integer Object to be assigned
def enum_integer=(enum_integer) def enum_integer=(enum_integer)
validator = EnumAttributeValidator.new('Integer', ['1', '-1']) validator = EnumAttributeValidator.new('Integer', [1, -1])
unless validator.valid?(enum_integer) unless validator.valid?(enum_integer)
fail ArgumentError, "invalid value for \"enum_integer\", must be one of #{validator.allowable_values}." fail ArgumentError, "invalid value for \"enum_integer\", must be one of #{validator.allowable_values}."
end end
@ -156,7 +156,7 @@ module Petstore
# Custom attribute writer method checking allowed values (enum). # Custom attribute writer method checking allowed values (enum).
# @param [Object] enum_number Object to be assigned # @param [Object] enum_number Object to be assigned
def enum_number=(enum_number) def enum_number=(enum_number)
validator = EnumAttributeValidator.new('Float', ['1.1', '-1.2']) validator = EnumAttributeValidator.new('Float', [1.1, -1.2])
unless validator.valid?(enum_number) unless validator.valid?(enum_number)
fail ArgumentError, "invalid value for \"enum_number\", must be one of #{validator.allowable_values}." fail ArgumentError, "invalid value for \"enum_number\", must be one of #{validator.allowable_values}."
end end

View File

@ -118,7 +118,7 @@ module Petstore
# Check to see if the all the properties in the model are valid # Check to see if the all the properties in the model are valid
# @return true if the model is valid # @return true if the model is valid
def valid? def valid?
status_validator = EnumAttributeValidator.new('String', ['placed', 'approved', 'delivered']) status_validator = EnumAttributeValidator.new('String', ["placed", "approved", "delivered"])
return false unless status_validator.valid?(@status) return false unless status_validator.valid?(@status)
true true
end end
@ -126,7 +126,7 @@ module Petstore
# Custom attribute writer method checking allowed values (enum). # Custom attribute writer method checking allowed values (enum).
# @param [Object] status Object to be assigned # @param [Object] status Object to be assigned
def status=(status) def status=(status)
validator = EnumAttributeValidator.new('String', ['placed', 'approved', 'delivered']) validator = EnumAttributeValidator.new('String', ["placed", "approved", "delivered"])
unless validator.valid?(status) unless validator.valid?(status)
fail ArgumentError, "invalid value for \"status\", must be one of #{validator.allowable_values}." fail ArgumentError, "invalid value for \"status\", must be one of #{validator.allowable_values}."
end end

View File

@ -14,10 +14,9 @@ require 'date'
module Petstore module Petstore
class OuterEnum class OuterEnum
PLACED = "placed".freeze
PLACED = 'placed'.freeze APPROVED = "approved".freeze
APPROVED = 'approved'.freeze DELIVERED = "delivered".freeze
DELIVERED = 'delivered'.freeze
# 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

View File

@ -130,7 +130,7 @@ module Petstore
def valid? def valid?
return false if @name.nil? return false if @name.nil?
return false if @photo_urls.nil? return false if @photo_urls.nil?
status_validator = EnumAttributeValidator.new('String', ['available', 'pending', 'sold']) status_validator = EnumAttributeValidator.new('String', ["available", "pending", "sold"])
return false unless status_validator.valid?(@status) return false unless status_validator.valid?(@status)
true true
end end
@ -138,7 +138,7 @@ module Petstore
# Custom attribute writer method checking allowed values (enum). # Custom attribute writer method checking allowed values (enum).
# @param [Object] status Object to be assigned # @param [Object] status Object to be assigned
def status=(status) def status=(status)
validator = EnumAttributeValidator.new('String', ['available', 'pending', 'sold']) validator = EnumAttributeValidator.new('String', ["available", "pending", "sold"])
unless validator.valid?(status) unless validator.valid?(status)
fail ArgumentError, "invalid value for \"status\", must be one of #{validator.allowable_values}." fail ArgumentError, "invalid value for \"status\", must be one of #{validator.allowable_values}."
end end

View File

@ -55,7 +55,7 @@ describe 'EnumTest' do
describe 'test attribute "enum_integer"' do describe 'test attribute "enum_integer"' do
it 'should work' do it 'should work' do
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
# validator = Petstore::EnumTest::EnumAttributeValidator.new('Integer', ["1", "-1"]) # validator = Petstore::EnumTest::EnumAttributeValidator.new('Integer', [1, -1])
# validator.allowable_values.each do |value| # validator.allowable_values.each do |value|
# expect { @instance.enum_integer = value }.not_to raise_error # expect { @instance.enum_integer = value }.not_to raise_error
# end # end
@ -65,7 +65,7 @@ describe 'EnumTest' do
describe 'test attribute "enum_number"' do describe 'test attribute "enum_number"' do
it 'should work' do it 'should work' do
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
# validator = Petstore::EnumTest::EnumAttributeValidator.new('Float', ["1.1", "-1.2"]) # validator = Petstore::EnumTest::EnumAttributeValidator.new('Float', [1.1, -1.2])
# validator.allowable_values.each do |value| # validator.allowable_values.each do |value|
# expect { @instance.enum_number = value }.not_to raise_error # expect { @instance.enum_number = value }.not_to raise_error
# end # end

View File

@ -564,29 +564,37 @@ module Petstore
if @api_client.config.debugging if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: FakeApi.test_enum_parameters ...' @api_client.config.logger.debug 'Calling API: FakeApi.test_enum_parameters ...'
end end
if @api_client.config.client_side_validation && opts[:'enum_header_string_array'] && !opts[:'enum_header_string_array'].all? { |item| ['>', '$'].include?(item) } allowable_values = [">", "$"]
fail ArgumentError, 'invalid value for "enum_header_string_array", must include one of >, $' if @api_client.config.client_side_validation && opts[:'enum_header_string_array'] && !opts[:'enum_header_string_array'].all? { |item| allowable_values.include?(item) }
fail ArgumentError, "invalid value for \"enum_header_string_array\", must include one of #{allowable_values}"
end end
if @api_client.config.client_side_validation && opts[:'enum_header_string'] && !['_abc', '-efg', '(xyz)'].include?(opts[:'enum_header_string']) allowable_values = ["_abc", "-efg", "(xyz)"]
fail ArgumentError, 'invalid value for "enum_header_string", must be one of _abc, -efg, (xyz)' if @api_client.config.client_side_validation && opts[:'enum_header_string'] && !allowable_values.include?(opts[:'enum_header_string'])
fail ArgumentError, "invalid value for \"enum_header_string\", must be one of #{allowable_values}"
end end
if @api_client.config.client_side_validation && opts[:'enum_query_string_array'] && !opts[:'enum_query_string_array'].all? { |item| ['>', '$'].include?(item) } allowable_values = [">", "$"]
fail ArgumentError, 'invalid value for "enum_query_string_array", must include one of >, $' if @api_client.config.client_side_validation && opts[:'enum_query_string_array'] && !opts[:'enum_query_string_array'].all? { |item| allowable_values.include?(item) }
fail ArgumentError, "invalid value for \"enum_query_string_array\", must include one of #{allowable_values}"
end end
if @api_client.config.client_side_validation && opts[:'enum_query_string'] && !['_abc', '-efg', '(xyz)'].include?(opts[:'enum_query_string']) allowable_values = ["_abc", "-efg", "(xyz)"]
fail ArgumentError, 'invalid value for "enum_query_string", must be one of _abc, -efg, (xyz)' if @api_client.config.client_side_validation && opts[:'enum_query_string'] && !allowable_values.include?(opts[:'enum_query_string'])
fail ArgumentError, "invalid value for \"enum_query_string\", must be one of #{allowable_values}"
end end
if @api_client.config.client_side_validation && opts[:'enum_query_integer'] && !['1', '-2'].include?(opts[:'enum_query_integer']) allowable_values = [1, -2]
fail ArgumentError, 'invalid value for "enum_query_integer", must be one of 1, -2' if @api_client.config.client_side_validation && opts[:'enum_query_integer'] && !allowable_values.include?(opts[:'enum_query_integer'])
fail ArgumentError, "invalid value for \"enum_query_integer\", must be one of #{allowable_values}"
end end
if @api_client.config.client_side_validation && opts[:'enum_query_double'] && !['1.1', '-1.2'].include?(opts[:'enum_query_double']) allowable_values = [1.1, -1.2]
fail ArgumentError, 'invalid value for "enum_query_double", must be one of 1.1, -1.2' if @api_client.config.client_side_validation && opts[:'enum_query_double'] && !allowable_values.include?(opts[:'enum_query_double'])
fail ArgumentError, "invalid value for \"enum_query_double\", must be one of #{allowable_values}"
end end
if @api_client.config.client_side_validation && opts[:'enum_form_string_array'] && !opts[:'enum_form_string_array'].all? { |item| ['>', '$'].include?(item) } allowable_values = [">", "$"]
fail ArgumentError, 'invalid value for "enum_form_string_array", must include one of >, $' if @api_client.config.client_side_validation && opts[:'enum_form_string_array'] && !opts[:'enum_form_string_array'].all? { |item| allowable_values.include?(item) }
fail ArgumentError, "invalid value for \"enum_form_string_array\", must include one of #{allowable_values}"
end end
if @api_client.config.client_side_validation && opts[:'enum_form_string'] && !['_abc', '-efg', '(xyz)'].include?(opts[:'enum_form_string']) allowable_values = ["_abc", "-efg", "(xyz)"]
fail ArgumentError, 'invalid value for "enum_form_string", must be one of _abc, -efg, (xyz)' if @api_client.config.client_side_validation && opts[:'enum_form_string'] && !allowable_values.include?(opts[:'enum_form_string'])
fail ArgumentError, "invalid value for \"enum_form_string\", must be one of #{allowable_values}"
end end
# resource path # resource path
local_var_path = '/fake' local_var_path = '/fake'

View File

@ -85,7 +85,7 @@ module Petstore
# Check to see if the all the properties in the model are valid # Check to see if the all the properties in the model are valid
# @return true if the model is valid # @return true if the model is valid
def valid? def valid?
just_symbol_validator = EnumAttributeValidator.new('String', ['>=', '$']) just_symbol_validator = EnumAttributeValidator.new('String', [">=", "$"])
return false unless just_symbol_validator.valid?(@just_symbol) return false unless just_symbol_validator.valid?(@just_symbol)
true true
end end
@ -93,7 +93,7 @@ module Petstore
# Custom attribute writer method checking allowed values (enum). # Custom attribute writer method checking allowed values (enum).
# @param [Object] just_symbol Object to be assigned # @param [Object] just_symbol Object to be assigned
def just_symbol=(just_symbol) def just_symbol=(just_symbol)
validator = EnumAttributeValidator.new('String', ['>=', '$']) validator = EnumAttributeValidator.new('String', [">=", "$"])
unless validator.valid?(just_symbol) unless validator.valid?(just_symbol)
fail ArgumentError, "invalid value for \"just_symbol\", must be one of #{validator.allowable_values}." fail ArgumentError, "invalid value for \"just_symbol\", must be one of #{validator.allowable_values}."
end end

View File

@ -14,10 +14,9 @@ require 'date'
module Petstore module Petstore
class EnumClass class EnumClass
ABC = "_abc".freeze
ABC = '_abc'.freeze EFG = "-efg".freeze
EFG = '-efg'.freeze XYZ = "(xyz)".freeze
XYZ = '(xyz)'.freeze
# 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

View File

@ -111,14 +111,14 @@ module Petstore
# Check to see if the all the properties in the model are valid # Check to see if the all the properties in the model are valid
# @return true if the model is valid # @return true if the model is valid
def 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) return false unless enum_string_validator.valid?(@enum_string)
return false if @enum_string_required.nil? return false if @enum_string_required.nil?
enum_string_required_validator = EnumAttributeValidator.new('String', ['UPPER', 'lower', '']) enum_string_required_validator = EnumAttributeValidator.new('String', ["UPPER", "lower", ""])
return false unless enum_string_required_validator.valid?(@enum_string_required) return false unless enum_string_required_validator.valid?(@enum_string_required)
enum_integer_validator = EnumAttributeValidator.new('Integer', ['1', '-1']) enum_integer_validator = EnumAttributeValidator.new('Integer', [1, -1])
return false unless enum_integer_validator.valid?(@enum_integer) return false unless enum_integer_validator.valid?(@enum_integer)
enum_number_validator = EnumAttributeValidator.new('Float', ['1.1', '-1.2']) enum_number_validator = EnumAttributeValidator.new('Float', [1.1, -1.2])
return false unless enum_number_validator.valid?(@enum_number) return false unless enum_number_validator.valid?(@enum_number)
true true
end end
@ -126,7 +126,7 @@ module Petstore
# Custom attribute writer method checking allowed values (enum). # Custom attribute writer method checking allowed values (enum).
# @param [Object] enum_string Object to be assigned # @param [Object] enum_string Object to be assigned
def enum_string=(enum_string) def enum_string=(enum_string)
validator = EnumAttributeValidator.new('String', ['UPPER', 'lower', '']) validator = EnumAttributeValidator.new('String', ["UPPER", "lower", ""])
unless validator.valid?(enum_string) unless validator.valid?(enum_string)
fail ArgumentError, "invalid value for \"enum_string\", must be one of #{validator.allowable_values}." fail ArgumentError, "invalid value for \"enum_string\", must be one of #{validator.allowable_values}."
end end
@ -136,7 +136,7 @@ module Petstore
# Custom attribute writer method checking allowed values (enum). # Custom attribute writer method checking allowed values (enum).
# @param [Object] enum_string_required Object to be assigned # @param [Object] enum_string_required Object to be assigned
def enum_string_required=(enum_string_required) def enum_string_required=(enum_string_required)
validator = EnumAttributeValidator.new('String', ['UPPER', 'lower', '']) validator = EnumAttributeValidator.new('String', ["UPPER", "lower", ""])
unless validator.valid?(enum_string_required) unless validator.valid?(enum_string_required)
fail ArgumentError, "invalid value for \"enum_string_required\", must be one of #{validator.allowable_values}." fail ArgumentError, "invalid value for \"enum_string_required\", must be one of #{validator.allowable_values}."
end end
@ -146,7 +146,7 @@ module Petstore
# Custom attribute writer method checking allowed values (enum). # Custom attribute writer method checking allowed values (enum).
# @param [Object] enum_integer Object to be assigned # @param [Object] enum_integer Object to be assigned
def enum_integer=(enum_integer) def enum_integer=(enum_integer)
validator = EnumAttributeValidator.new('Integer', ['1', '-1']) validator = EnumAttributeValidator.new('Integer', [1, -1])
unless validator.valid?(enum_integer) unless validator.valid?(enum_integer)
fail ArgumentError, "invalid value for \"enum_integer\", must be one of #{validator.allowable_values}." fail ArgumentError, "invalid value for \"enum_integer\", must be one of #{validator.allowable_values}."
end end
@ -156,7 +156,7 @@ module Petstore
# Custom attribute writer method checking allowed values (enum). # Custom attribute writer method checking allowed values (enum).
# @param [Object] enum_number Object to be assigned # @param [Object] enum_number Object to be assigned
def enum_number=(enum_number) def enum_number=(enum_number)
validator = EnumAttributeValidator.new('Float', ['1.1', '-1.2']) validator = EnumAttributeValidator.new('Float', [1.1, -1.2])
unless validator.valid?(enum_number) unless validator.valid?(enum_number)
fail ArgumentError, "invalid value for \"enum_number\", must be one of #{validator.allowable_values}." fail ArgumentError, "invalid value for \"enum_number\", must be one of #{validator.allowable_values}."
end end

View File

@ -118,7 +118,7 @@ module Petstore
# Check to see if the all the properties in the model are valid # Check to see if the all the properties in the model are valid
# @return true if the model is valid # @return true if the model is valid
def valid? def valid?
status_validator = EnumAttributeValidator.new('String', ['placed', 'approved', 'delivered']) status_validator = EnumAttributeValidator.new('String', ["placed", "approved", "delivered"])
return false unless status_validator.valid?(@status) return false unless status_validator.valid?(@status)
true true
end end
@ -126,7 +126,7 @@ module Petstore
# Custom attribute writer method checking allowed values (enum). # Custom attribute writer method checking allowed values (enum).
# @param [Object] status Object to be assigned # @param [Object] status Object to be assigned
def status=(status) def status=(status)
validator = EnumAttributeValidator.new('String', ['placed', 'approved', 'delivered']) validator = EnumAttributeValidator.new('String', ["placed", "approved", "delivered"])
unless validator.valid?(status) unless validator.valid?(status)
fail ArgumentError, "invalid value for \"status\", must be one of #{validator.allowable_values}." fail ArgumentError, "invalid value for \"status\", must be one of #{validator.allowable_values}."
end end

View File

@ -14,10 +14,9 @@ require 'date'
module Petstore module Petstore
class OuterEnum class OuterEnum
PLACED = "placed".freeze
PLACED = 'placed'.freeze APPROVED = "approved".freeze
APPROVED = 'approved'.freeze DELIVERED = "delivered".freeze
DELIVERED = 'delivered'.freeze
# 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

View File

@ -130,7 +130,7 @@ module Petstore
def valid? def valid?
return false if @name.nil? return false if @name.nil?
return false if @photo_urls.nil? return false if @photo_urls.nil?
status_validator = EnumAttributeValidator.new('String', ['available', 'pending', 'sold']) status_validator = EnumAttributeValidator.new('String', ["available", "pending", "sold"])
return false unless status_validator.valid?(@status) return false unless status_validator.valid?(@status)
true true
end end
@ -138,7 +138,7 @@ module Petstore
# Custom attribute writer method checking allowed values (enum). # Custom attribute writer method checking allowed values (enum).
# @param [Object] status Object to be assigned # @param [Object] status Object to be assigned
def status=(status) def status=(status)
validator = EnumAttributeValidator.new('String', ['available', 'pending', 'sold']) validator = EnumAttributeValidator.new('String', ["available", "pending", "sold"])
unless validator.valid?(status) unless validator.valid?(status)
fail ArgumentError, "invalid value for \"status\", must be one of #{validator.allowable_values}." fail ArgumentError, "invalid value for \"status\", must be one of #{validator.allowable_values}."
end end

View File

@ -55,7 +55,7 @@ describe 'EnumTest' do
describe 'test attribute "enum_integer"' do describe 'test attribute "enum_integer"' do
it 'should work' do it 'should work' do
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
# validator = Petstore::EnumTest::EnumAttributeValidator.new('Integer', ["1", "-1"]) # validator = Petstore::EnumTest::EnumAttributeValidator.new('Integer', [1, -1])
# validator.allowable_values.each do |value| # validator.allowable_values.each do |value|
# expect { @instance.enum_integer = value }.not_to raise_error # expect { @instance.enum_integer = value }.not_to raise_error
# end # end
@ -65,7 +65,7 @@ describe 'EnumTest' do
describe 'test attribute "enum_number"' do describe 'test attribute "enum_number"' do
it 'should work' do it 'should work' do
# assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers # assertion here. ref: https://www.relishapp.com/rspec/rspec-expectations/docs/built-in-matchers
# validator = Petstore::EnumTest::EnumAttributeValidator.new('Float', ["1.1", "-1.2"]) # validator = Petstore::EnumTest::EnumAttributeValidator.new('Float', [1.1, -1.2])
# validator.allowable_values.each do |value| # validator.allowable_values.each do |value|
# expect { @instance.enum_number = value }.not_to raise_error # expect { @instance.enum_number = value }.not_to raise_error
# end # end