Skip to content

[Ruby] Fix ruby client generator to generate setter methods with not null validation #20672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,21 @@
}
end

# Returns all the JSON keys this model knows about{{#parent}}, including the ones defined in its parent(s){{/parent}}
def self.acceptable_attributes
# Returns attribute mapping this model knows about{{#parent}}, including the ones defined in its parent(s){{/parent}}
def self.acceptable_attribute_map
{{^parent}}
attribute_map.values
attribute_map
{{/parent}}
{{#parent}}
attribute_map.values.concat(superclass.acceptable_attributes)
superclass.acceptable_attribute_map.merge(attribute_map)
{{/parent}}
end

# Returns all the JSON keys this model knows about{{#parent}}, including the ones defined in its parent(s){{/parent}}
def self.acceptable_attributes
acceptable_attribute_map.values
end

# Attribute type mapping.
def self.openapi_types
{
Expand Down Expand Up @@ -115,9 +120,10 @@
end

# check to see if the attribute exists and convert string to symbol for hash key
acceptable_attribute_map = self.class.acceptable_attribute_map
attributes = attributes.each_with_object({}) { |(k, v), h|
if (!self.class.attribute_map.key?(k.to_sym))
fail ArgumentError, "`#{k}` is not a valid attribute in `{{{moduleName}}}::{{{classname}}}`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
if (!acceptable_attribute_map.key?(k.to_sym))
fail ArgumentError, "`#{k}` is not a valid attribute in `{{{moduleName}}}::{{{classname}}}`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
end
h[k.to_sym] = v
}
Expand Down Expand Up @@ -350,6 +356,22 @@
@{{{name}}} = {{{name}}}
end

{{/hasValidation}}
{{^hasValidation}}
{{^isNullable}}
{{#required}}
# Custom attribute writer method with validation
# @param [Object] {{{name}}} Value to be assigned
def {{{name}}}=({{{name}}})
if {{{name}}}.nil?
fail ArgumentError, '{{{name}}} cannot be nil'
end

@{{{name}}} = {{{name}}}
end

{{/required}}
{{/isNullable}}
{{/hasValidation}}
{{/isEnum}}
{{/vars}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ def self.attribute_map
}
end

# Returns attribute mapping this model knows about
def self.acceptable_attribute_map
attribute_map
end

# Returns all the JSON keys this model knows about
def self.acceptable_attributes
attribute_map.values
acceptable_attribute_map.values
end

# Attribute type mapping.
Expand All @@ -54,9 +59,10 @@ def initialize(attributes = {})
end

# check to see if the attribute exists and convert string to symbol for hash key
acceptable_attribute_map = self.class.acceptable_attribute_map
attributes = attributes.each_with_object({}) { |(k, v), h|
if (!self.class.attribute_map.key?(k.to_sym))
fail ArgumentError, "`#{k}` is not a valid attribute in `OpenapiClient::Bird`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
if (!acceptable_attribute_map.key?(k.to_sym))
fail ArgumentError, "`#{k}` is not a valid attribute in `OpenapiClient::Bird`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
end
h[k.to_sym] = v
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ def self.attribute_map
}
end

# Returns attribute mapping this model knows about
def self.acceptable_attribute_map
attribute_map
end

# Returns all the JSON keys this model knows about
def self.acceptable_attributes
attribute_map.values
acceptable_attribute_map.values
end

# Attribute type mapping.
Expand All @@ -54,9 +59,10 @@ def initialize(attributes = {})
end

# check to see if the attribute exists and convert string to symbol for hash key
acceptable_attribute_map = self.class.acceptable_attribute_map
attributes = attributes.each_with_object({}) { |(k, v), h|
if (!self.class.attribute_map.key?(k.to_sym))
fail ArgumentError, "`#{k}` is not a valid attribute in `OpenapiClient::Category`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
if (!acceptable_attribute_map.key?(k.to_sym))
fail ArgumentError, "`#{k}` is not a valid attribute in `OpenapiClient::Category`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
end
h[k.to_sym] = v
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,14 @@ def self.attribute_map
}
end

# Returns attribute mapping this model knows about, including the ones defined in its parent(s)
def self.acceptable_attribute_map
superclass.acceptable_attribute_map.merge(attribute_map)
end

# Returns all the JSON keys this model knows about, including the ones defined in its parent(s)
def self.acceptable_attributes
attribute_map.values.concat(superclass.acceptable_attributes)
acceptable_attribute_map.values
end

# Attribute type mapping.
Expand Down Expand Up @@ -90,9 +95,10 @@ def initialize(attributes = {})
end

# check to see if the attribute exists and convert string to symbol for hash key
acceptable_attribute_map = self.class.acceptable_attribute_map
attributes = attributes.each_with_object({}) { |(k, v), h|
if (!self.class.attribute_map.key?(k.to_sym))
fail ArgumentError, "`#{k}` is not a valid attribute in `OpenapiClient::DataQuery`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
if (!acceptable_attribute_map.key?(k.to_sym))
fail ArgumentError, "`#{k}` is not a valid attribute in `OpenapiClient::DataQuery`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
end
h[k.to_sym] = v
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,14 @@ def self.attribute_map
}
end

# Returns attribute mapping this model knows about
def self.acceptable_attribute_map
attribute_map
end

# Returns all the JSON keys this model knows about
def self.acceptable_attributes
attribute_map.values
acceptable_attribute_map.values
end

# Attribute type mapping.
Expand Down Expand Up @@ -104,9 +109,10 @@ def initialize(attributes = {})
end

# check to see if the attribute exists and convert string to symbol for hash key
acceptable_attribute_map = self.class.acceptable_attribute_map
attributes = attributes.each_with_object({}) { |(k, v), h|
if (!self.class.attribute_map.key?(k.to_sym))
fail ArgumentError, "`#{k}` is not a valid attribute in `OpenapiClient::DefaultValue`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
if (!acceptable_attribute_map.key?(k.to_sym))
fail ArgumentError, "`#{k}` is not a valid attribute in `OpenapiClient::DefaultValue`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
end
h[k.to_sym] = v
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@ def self.attribute_map
}
end

# Returns attribute mapping this model knows about
def self.acceptable_attribute_map
attribute_map
end

# Returns all the JSON keys this model knows about
def self.acceptable_attributes
attribute_map.values
acceptable_attribute_map.values
end

# Attribute type mapping.
Expand All @@ -58,9 +63,10 @@ def initialize(attributes = {})
end

# check to see if the attribute exists and convert string to symbol for hash key
acceptable_attribute_map = self.class.acceptable_attribute_map
attributes = attributes.each_with_object({}) { |(k, v), h|
if (!self.class.attribute_map.key?(k.to_sym))
fail ArgumentError, "`#{k}` is not a valid attribute in `OpenapiClient::NumberPropertiesOnly`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
if (!acceptable_attribute_map.key?(k.to_sym))
fail ArgumentError, "`#{k}` is not a valid attribute in `OpenapiClient::NumberPropertiesOnly`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
end
h[k.to_sym] = v
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,14 @@ def self.attribute_map
}
end

# Returns attribute mapping this model knows about
def self.acceptable_attribute_map
attribute_map
end

# Returns all the JSON keys this model knows about
def self.acceptable_attributes
attribute_map.values
acceptable_attribute_map.values
end

# Attribute type mapping.
Expand Down Expand Up @@ -93,9 +98,10 @@ def initialize(attributes = {})
end

# check to see if the attribute exists and convert string to symbol for hash key
acceptable_attribute_map = self.class.acceptable_attribute_map
attributes = attributes.each_with_object({}) { |(k, v), h|
if (!self.class.attribute_map.key?(k.to_sym))
fail ArgumentError, "`#{k}` is not a valid attribute in `OpenapiClient::Pet`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
if (!acceptable_attribute_map.key?(k.to_sym))
fail ArgumentError, "`#{k}` is not a valid attribute in `OpenapiClient::Pet`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
end
h[k.to_sym] = v
}
Expand Down Expand Up @@ -160,6 +166,26 @@ def valid?
true
end

# Custom attribute writer method with validation
# @param [Object] name Value to be assigned
def name=(name)
if name.nil?
fail ArgumentError, 'name cannot be nil'
end

@name = name
end

# Custom attribute writer method with validation
# @param [Object] photo_urls Value to be assigned
def photo_urls=(photo_urls)
if photo_urls.nil?
fail ArgumentError, 'photo_urls cannot be nil'
end

@photo_urls = photo_urls
end

# Custom attribute writer method checking allowed values (enum).
# @param [Object] status Object to be assigned
def status=(status)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,14 @@ def self.attribute_map
}
end

# Returns attribute mapping this model knows about
def self.acceptable_attribute_map
attribute_map
end

# Returns all the JSON keys this model knows about
def self.acceptable_attributes
attribute_map.values
acceptable_attribute_map.values
end

# Attribute type mapping.
Expand All @@ -77,9 +82,10 @@ def initialize(attributes = {})
end

# check to see if the attribute exists and convert string to symbol for hash key
acceptable_attribute_map = self.class.acceptable_attribute_map
attributes = attributes.each_with_object({}) { |(k, v), h|
if (!self.class.attribute_map.key?(k.to_sym))
fail ArgumentError, "`#{k}` is not a valid attribute in `OpenapiClient::Query`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
if (!acceptable_attribute_map.key?(k.to_sym))
fail ArgumentError, "`#{k}` is not a valid attribute in `OpenapiClient::Query`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
end
h[k.to_sym] = v
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ def self.attribute_map
}
end

# Returns attribute mapping this model knows about
def self.acceptable_attribute_map
attribute_map
end

# Returns all the JSON keys this model knows about
def self.acceptable_attributes
attribute_map.values
acceptable_attribute_map.values
end

# Attribute type mapping.
Expand All @@ -54,9 +59,10 @@ def initialize(attributes = {})
end

# check to see if the attribute exists and convert string to symbol for hash key
acceptable_attribute_map = self.class.acceptable_attribute_map
attributes = attributes.each_with_object({}) { |(k, v), h|
if (!self.class.attribute_map.key?(k.to_sym))
fail ArgumentError, "`#{k}` is not a valid attribute in `OpenapiClient::Tag`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
if (!acceptable_attribute_map.key?(k.to_sym))
fail ArgumentError, "`#{k}` is not a valid attribute in `OpenapiClient::Tag`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
end
h[k.to_sym] = v
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ def self.attribute_map
}
end

# Returns attribute mapping this model knows about
def self.acceptable_attribute_map
attribute_map
end

# Returns all the JSON keys this model knows about
def self.acceptable_attributes
attribute_map.values
acceptable_attribute_map.values
end

# Attribute type mapping.
Expand All @@ -50,9 +55,10 @@ def initialize(attributes = {})
end

# check to see if the attribute exists and convert string to symbol for hash key
acceptable_attribute_map = self.class.acceptable_attribute_map
attributes = attributes.each_with_object({}) { |(k, v), h|
if (!self.class.attribute_map.key?(k.to_sym))
fail ArgumentError, "`#{k}` is not a valid attribute in `OpenapiClient::TestFormObjectMultipartRequestMarker`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
if (!acceptable_attribute_map.key?(k.to_sym))
fail ArgumentError, "`#{k}` is not a valid attribute in `OpenapiClient::TestFormObjectMultipartRequestMarker`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
end
h[k.to_sym] = v
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@ def self.attribute_map
}
end

# Returns attribute mapping this model knows about
def self.acceptable_attribute_map
attribute_map
end

# Returns all the JSON keys this model knows about
def self.acceptable_attributes
attribute_map.values
acceptable_attribute_map.values
end

# Attribute type mapping.
Expand Down Expand Up @@ -70,9 +75,10 @@ def initialize(attributes = {})
end

# check to see if the attribute exists and convert string to symbol for hash key
acceptable_attribute_map = self.class.acceptable_attribute_map
attributes = attributes.each_with_object({}) { |(k, v), h|
if (!self.class.attribute_map.key?(k.to_sym))
fail ArgumentError, "`#{k}` is not a valid attribute in `OpenapiClient::TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
if (!acceptable_attribute_map.key?(k.to_sym))
fail ArgumentError, "`#{k}` is not a valid attribute in `OpenapiClient::TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
end
h[k.to_sym] = v
}
Expand Down
Loading
Loading