diff --git a/modules/openapi-generator/src/main/resources/ruby-client/base_object.mustache b/modules/openapi-generator/src/main/resources/ruby-client/base_object.mustache index d752c497c42c..f25a512b5a7a 100644 --- a/modules/openapi-generator/src/main/resources/ruby-client/base_object.mustache +++ b/modules/openapi-generator/src/main/resources/ruby-client/base_object.mustache @@ -3,22 +3,30 @@ # @return [Object] Returns the model itself def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) - {{#parent}} - super(attributes) - {{/parent}} attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -27,11 +35,24 @@ # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash - hash = {{^parent}}{}{{/parent}}{{#parent}}super{{/parent}} - self.class.attribute_map.each_pair do |attr, param| + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end + hash = {} + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/modules/openapi-generator/src/main/resources/ruby-client/model.mustache b/modules/openapi-generator/src/main/resources/ruby-client/model.mustache index 723dba82ffd4..fe71e76ca394 100644 --- a/modules/openapi-generator/src/main/resources/ruby-client/model.mustache +++ b/modules/openapi-generator/src/main/resources/ruby-client/model.mustache @@ -4,6 +4,7 @@ =end require 'date' +require 'set' require 'time' module {{moduleName}} diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/ruby/RubyClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/ruby/RubyClientCodegenTest.java index ed256377bc80..9ab274fd3eda 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/ruby/RubyClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/ruby/RubyClientCodegenTest.java @@ -762,4 +762,50 @@ public void testQueryParamJsonSerializationSetsQueryIsJsonMimeType() { assertTrue(op.queryParams.stream().allMatch(p -> p.queryIsJsonMimeType), "All content:application/json query params should have queryIsJsonMimeType=true"); } + + @Test(description = "an allOf child's build_from_hash maps the attributes inherited from its parents") + public void testBuildFromHashMapsInheritedAttributes() throws Exception { + final File output = Files.createTempDirectory("test").toFile(); + output.deleteOnExit(); + + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/allOf_composition_discriminator.yaml"); + CodegenConfig codegenConfig = new RubyClientCodegen(); + codegenConfig.setOutputDir(output.getAbsolutePath()); + + ClientOptInput clientOptInput = new ClientOptInput().openAPI(openAPI).config(codegenConfig); + new DefaultGenerator().opts(clientOptInput).generate(); + + // Lizard < Reptile < Pet: the walk has to collect openapi_types and + // attribute_map from the whole ancestry, not just the child's own + java.nio.file.Path lizard = new File(output, "lib/openapi_client/models/lizard.rb").toPath(); + TestUtils.assertFileContains(lizard, + "types = openapi_types\n" + + " map = attribute_map\n" + + " klass = superclass\n" + + " while klass.respond_to?(:openapi_types)\n" + + " types = klass.openapi_types.merge(types)\n" + + " map = klass.attribute_map.merge(map)\n" + + " klass = klass.superclass\n" + + " end"); + // the discarded-result super call is gone: openapi_types/attribute_map + // dispatch on the child class in the parent's frame too, so it never + // contributed the parent's attributes - it only built a second instance + TestUtils.assertFileNotContains(lizard, "super(attributes)\n attributes = attributes.transform_keys(&:to_sym)"); + // to_hash walks the same ancestry: attribute_map/openapi_nullable dispatch on the + // child in every ancestor frame, so the old super chain only repeated the child's + // own attributes and a round-tripped model lost its inherited fields + TestUtils.assertFileContains(lizard, + "map = self.class.attribute_map\n" + + " nullable = self.class.openapi_nullable\n" + + " klass = self.class.superclass\n" + + " while klass.respond_to?(:openapi_types)\n" + + " # an ancestor's nullability only applies to attributes no nearer class redeclares\n" + + " nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys)\n" + + " map = klass.attribute_map.merge(map)\n" + + " klass = klass.superclass\n" + + " end"); + // the walk evaluates openapi_nullable eagerly, so Set must be loaded on rubies + // where it is not yet a builtin autoload + TestUtils.assertFileContains(lizard, "require 'set'"); + } } diff --git a/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/bird.rb b/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/bird.rb index 791ff7830e90..8cda283934e8 100644 --- a/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/bird.rb +++ b/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/bird.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module OpenapiClient @@ -118,18 +119,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -138,11 +150,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/category.rb b/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/category.rb index 2ae2f25e7bb6..28f1164e3cc3 100644 --- a/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/category.rb +++ b/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/category.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module OpenapiClient @@ -118,18 +119,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -138,11 +150,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/data_query.rb b/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/data_query.rb index 1a31b4d3e83f..62f7dfffd244 100644 --- a/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/data_query.rb +++ b/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/data_query.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module OpenapiClient @@ -161,20 +162,30 @@ def hash # @return [Object] Returns the model itself def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) - super(attributes) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -183,11 +194,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash - hash = super - self.class.attribute_map.each_pair do |attr, param| + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end + hash = {} + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/default_value.rb b/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/default_value.rb index 9dbb442bb860..fcdc5d3f1025 100644 --- a/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/default_value.rb +++ b/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/default_value.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module OpenapiClient @@ -212,18 +213,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -232,11 +244,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/number_properties_only.rb b/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/number_properties_only.rb index 46b63c582964..3994598e1e81 100644 --- a/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/number_properties_only.rb +++ b/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/number_properties_only.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module OpenapiClient @@ -155,18 +156,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -175,11 +187,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/pet.rb b/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/pet.rb index d1a334676d56..1e42b815e93d 100644 --- a/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/pet.rb +++ b/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/pet.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module OpenapiClient @@ -227,18 +228,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -247,11 +259,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/query.rb b/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/query.rb index 7598d312f1dd..501661567c64 100644 --- a/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/query.rb +++ b/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/query.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module OpenapiClient @@ -143,18 +144,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -163,11 +175,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/string_enum_ref.rb b/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/string_enum_ref.rb index 0777b5e07042..4a9ae3054ded 100644 --- a/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/string_enum_ref.rb +++ b/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/string_enum_ref.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module OpenapiClient diff --git a/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/tag.rb b/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/tag.rb index d087eafa1516..d3b27cae66ef 100644 --- a/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/tag.rb +++ b/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/tag.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module OpenapiClient @@ -118,18 +119,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -138,11 +150,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/test_form_object_multipart_request_marker.rb b/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/test_form_object_multipart_request_marker.rb index 1b00e10e7dc3..2bc861a89940 100644 --- a/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/test_form_object_multipart_request_marker.rb +++ b/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/test_form_object_multipart_request_marker.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module OpenapiClient @@ -109,18 +110,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -129,11 +141,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.rb b/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.rb index 02afae09bce2..58afc507821d 100644 --- a/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.rb +++ b/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module OpenapiClient @@ -144,18 +145,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -164,11 +176,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/test_query_style_form_explode_true_array_string_query_object_parameter.rb b/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/test_query_style_form_explode_true_array_string_query_object_parameter.rb index fa9520a4f16c..0845d0de0469 100644 --- a/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/test_query_style_form_explode_true_array_string_query_object_parameter.rb +++ b/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/test_query_style_form_explode_true_array_string_query_object_parameter.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module OpenapiClient @@ -111,18 +112,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -131,11 +143,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/bird.rb b/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/bird.rb index 791ff7830e90..8cda283934e8 100644 --- a/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/bird.rb +++ b/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/bird.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module OpenapiClient @@ -118,18 +119,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -138,11 +150,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/category.rb b/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/category.rb index 2ae2f25e7bb6..28f1164e3cc3 100644 --- a/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/category.rb +++ b/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/category.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module OpenapiClient @@ -118,18 +119,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -138,11 +150,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/data_query.rb b/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/data_query.rb index 1a31b4d3e83f..62f7dfffd244 100644 --- a/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/data_query.rb +++ b/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/data_query.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module OpenapiClient @@ -161,20 +162,30 @@ def hash # @return [Object] Returns the model itself def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) - super(attributes) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -183,11 +194,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash - hash = super - self.class.attribute_map.each_pair do |attr, param| + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end + hash = {} + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/default_value.rb b/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/default_value.rb index 9dbb442bb860..fcdc5d3f1025 100644 --- a/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/default_value.rb +++ b/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/default_value.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module OpenapiClient @@ -212,18 +213,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -232,11 +244,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/number_properties_only.rb b/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/number_properties_only.rb index 46b63c582964..3994598e1e81 100644 --- a/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/number_properties_only.rb +++ b/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/number_properties_only.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module OpenapiClient @@ -155,18 +156,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -175,11 +187,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/pet.rb b/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/pet.rb index d1a334676d56..1e42b815e93d 100644 --- a/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/pet.rb +++ b/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/pet.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module OpenapiClient @@ -227,18 +228,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -247,11 +259,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/query.rb b/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/query.rb index 7598d312f1dd..501661567c64 100644 --- a/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/query.rb +++ b/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/query.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module OpenapiClient @@ -143,18 +144,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -163,11 +175,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/string_enum_ref.rb b/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/string_enum_ref.rb index 0777b5e07042..4a9ae3054ded 100644 --- a/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/string_enum_ref.rb +++ b/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/string_enum_ref.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module OpenapiClient diff --git a/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/tag.rb b/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/tag.rb index d087eafa1516..d3b27cae66ef 100644 --- a/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/tag.rb +++ b/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/tag.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module OpenapiClient @@ -118,18 +119,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -138,11 +150,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/test_form_object_multipart_request_marker.rb b/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/test_form_object_multipart_request_marker.rb index 1b00e10e7dc3..2bc861a89940 100644 --- a/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/test_form_object_multipart_request_marker.rb +++ b/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/test_form_object_multipart_request_marker.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module OpenapiClient @@ -109,18 +110,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -129,11 +141,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.rb b/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.rb index 02afae09bce2..58afc507821d 100644 --- a/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.rb +++ b/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module OpenapiClient @@ -144,18 +145,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -164,11 +176,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/test_query_style_form_explode_true_array_string_query_object_parameter.rb b/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/test_query_style_form_explode_true_array_string_query_object_parameter.rb index fa9520a4f16c..0845d0de0469 100644 --- a/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/test_query_style_form_explode_true_array_string_query_object_parameter.rb +++ b/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/test_query_style_form_explode_true_array_string_query_object_parameter.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module OpenapiClient @@ -111,18 +112,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -131,11 +143,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/bird.rb b/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/bird.rb index 791ff7830e90..8cda283934e8 100644 --- a/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/bird.rb +++ b/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/bird.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module OpenapiClient @@ -118,18 +119,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -138,11 +150,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/category.rb b/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/category.rb index 2ae2f25e7bb6..28f1164e3cc3 100644 --- a/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/category.rb +++ b/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/category.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module OpenapiClient @@ -118,18 +119,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -138,11 +150,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/data_query.rb b/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/data_query.rb index 1a31b4d3e83f..62f7dfffd244 100644 --- a/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/data_query.rb +++ b/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/data_query.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module OpenapiClient @@ -161,20 +162,30 @@ def hash # @return [Object] Returns the model itself def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) - super(attributes) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -183,11 +194,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash - hash = super - self.class.attribute_map.each_pair do |attr, param| + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end + hash = {} + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/default_value.rb b/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/default_value.rb index 9dbb442bb860..fcdc5d3f1025 100644 --- a/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/default_value.rb +++ b/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/default_value.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module OpenapiClient @@ -212,18 +213,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -232,11 +244,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/number_properties_only.rb b/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/number_properties_only.rb index 46b63c582964..3994598e1e81 100644 --- a/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/number_properties_only.rb +++ b/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/number_properties_only.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module OpenapiClient @@ -155,18 +156,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -175,11 +187,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/pet.rb b/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/pet.rb index d1a334676d56..1e42b815e93d 100644 --- a/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/pet.rb +++ b/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/pet.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module OpenapiClient @@ -227,18 +228,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -247,11 +259,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/query.rb b/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/query.rb index 7598d312f1dd..501661567c64 100644 --- a/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/query.rb +++ b/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/query.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module OpenapiClient @@ -143,18 +144,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -163,11 +175,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/string_enum_ref.rb b/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/string_enum_ref.rb index 0777b5e07042..4a9ae3054ded 100644 --- a/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/string_enum_ref.rb +++ b/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/string_enum_ref.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module OpenapiClient diff --git a/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/tag.rb b/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/tag.rb index d087eafa1516..d3b27cae66ef 100644 --- a/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/tag.rb +++ b/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/tag.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module OpenapiClient @@ -118,18 +119,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -138,11 +150,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/test_form_object_multipart_request_marker.rb b/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/test_form_object_multipart_request_marker.rb index 1b00e10e7dc3..2bc861a89940 100644 --- a/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/test_form_object_multipart_request_marker.rb +++ b/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/test_form_object_multipart_request_marker.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module OpenapiClient @@ -109,18 +110,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -129,11 +141,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.rb b/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.rb index 02afae09bce2..58afc507821d 100644 --- a/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.rb +++ b/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/test_query_style_deep_object_explode_true_object_all_of_query_object_parameter.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module OpenapiClient @@ -144,18 +145,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -164,11 +176,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/test_query_style_form_explode_true_array_string_query_object_parameter.rb b/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/test_query_style_form_explode_true_array_string_query_object_parameter.rb index fa9520a4f16c..0845d0de0469 100644 --- a/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/test_query_style_form_explode_true_array_string_query_object_parameter.rb +++ b/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/test_query_style_form_explode_true_array_string_query_object_parameter.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module OpenapiClient @@ -111,18 +112,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -131,11 +143,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/additional_properties_class.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/additional_properties_class.rb index 9b823593d156..318e5b5bd6e4 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/additional_properties_class.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/additional_properties_class.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -122,18 +123,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -142,11 +154,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/all_of_with_single_ref.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/all_of_with_single_ref.rb index 600c974fa1e5..c9cf74e48eb9 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/all_of_with_single_ref.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/all_of_with_single_ref.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -140,18 +141,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -160,11 +172,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/animal.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/animal.rb index 21d89bccb837..f16064590127 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/animal.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/animal.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -142,18 +143,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -162,11 +174,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/api_response.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/api_response.rb index bbbaf9358be2..2b8f6f3da716 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/api_response.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/api_response.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -127,18 +128,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -147,11 +159,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/array_of_array_of_number_only.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/array_of_array_of_number_only.rb index e20b1728d130..61ec9a339f8a 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/array_of_array_of_number_only.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/array_of_array_of_number_only.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -111,18 +112,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -131,11 +143,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/array_of_number_only.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/array_of_number_only.rb index 63890ff64424..25936c36112d 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/array_of_number_only.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/array_of_number_only.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -111,18 +112,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -131,11 +143,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/array_test.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/array_test.rb index c74060151e07..4250f94d5602 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/array_test.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/array_test.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -161,18 +162,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -181,11 +193,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/capitalization.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/capitalization.rb index e0bbeb211eb3..980b6d4f6fdf 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/capitalization.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/capitalization.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -155,18 +156,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -175,11 +187,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/cat.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/cat.rb index a84dc5038bef..ccf06cb566c7 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/cat.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/cat.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -118,20 +119,30 @@ def hash # @return [Object] Returns the model itself def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) - super(attributes) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -140,11 +151,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash - hash = super - self.class.attribute_map.each_pair do |attr, param| + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end + hash = {} + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/category.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/category.rb index 2f2b7f1a5785..1e13601082aa 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/category.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/category.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -135,18 +136,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -155,11 +167,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/child_with_nullable.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/child_with_nullable.rb index a7c86c864e6e..43b774c168d7 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/child_with_nullable.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/child_with_nullable.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -140,20 +141,30 @@ def hash # @return [Object] Returns the model itself def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) - super(attributes) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -162,11 +173,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash - hash = super - self.class.attribute_map.each_pair do |attr, param| + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end + hash = {} + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/class_model.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/class_model.rb index fafd11df773a..368596110da9 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/class_model.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/class_model.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -110,18 +111,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -130,11 +142,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/client.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/client.rb index a349b7251d7b..2c8707232d25 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/client.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/client.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -109,18 +110,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -129,11 +141,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/deprecated_object.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/deprecated_object.rb index 9f1ee6720cab..b5cfe6462091 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/deprecated_object.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/deprecated_object.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -109,18 +110,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -129,11 +141,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/dog.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/dog.rb index 522e1a72f47e..2acab0f70063 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/dog.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/dog.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -118,20 +119,30 @@ def hash # @return [Object] Returns the model itself def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) - super(attributes) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -140,11 +151,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash - hash = super - self.class.attribute_map.each_pair do |attr, param| + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end + hash = {} + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/enum_arrays.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/enum_arrays.rb index 1f7c48bf859b..0dc6e78adaf5 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/enum_arrays.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/enum_arrays.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -154,18 +155,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -174,11 +186,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/enum_class.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/enum_class.rb index 54bffd17d38c..a62e4022056d 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/enum_class.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/enum_class.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/enum_test.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/enum_test.rb index 5159875cb89b..b9bd10e9f232 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/enum_test.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/enum_test.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -254,18 +255,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -274,11 +286,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/fake_big_decimal_map200_response.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/fake_big_decimal_map200_response.rb index 6d5e47b59656..2b15275e0af8 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/fake_big_decimal_map200_response.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/fake_big_decimal_map200_response.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -120,18 +121,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -140,11 +152,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/file.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/file.rb index 219237eb3c07..e16db98d6d8e 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/file.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/file.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -111,18 +112,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -131,11 +143,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/file_schema_test_class.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/file_schema_test_class.rb index 8fdab5a25e86..b8c3a85378e7 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/file_schema_test_class.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/file_schema_test_class.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -120,18 +121,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -140,11 +152,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/foo.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/foo.rb index ceb5b7497955..4912ef30b029 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/foo.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/foo.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -111,18 +112,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -131,11 +143,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/foo_get_default_response.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/foo_get_default_response.rb index 42538a14e2cb..9994654f38d4 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/foo_get_default_response.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/foo_get_default_response.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -109,18 +110,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -129,11 +141,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/format_test.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/format_test.rb index 03a4e130a8f9..b22f471e3367 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/format_test.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/format_test.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -525,18 +526,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -545,11 +557,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/has_only_read_only.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/has_only_read_only.rb index cc584c09e54f..e12981d112e4 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/has_only_read_only.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/has_only_read_only.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -118,18 +119,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -138,11 +150,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/health_check_result.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/health_check_result.rb index a66e1b71331d..5ee62c4fc45e 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/health_check_result.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/health_check_result.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -111,18 +112,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -131,11 +143,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/list.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/list.rb index 2dc658065278..ffbc3b957a30 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/list.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/list.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -109,18 +110,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -129,11 +141,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/map_test.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/map_test.rb index 78c5472f24ae..acb0dc9c82d4 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/map_test.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/map_test.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -166,18 +167,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -186,11 +198,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/mixed_properties_and_additional_properties_class.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/mixed_properties_and_additional_properties_class.rb index bf1d3768951b..36969d7426cb 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/mixed_properties_and_additional_properties_class.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/mixed_properties_and_additional_properties_class.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -129,18 +130,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -149,11 +161,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/model200_response.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/model200_response.rb index 9cff83ced2c9..72b7d2292c99 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/model200_response.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/model200_response.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -119,18 +120,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -139,11 +151,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/model_return.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/model_return.rb index d520a45c2040..61b38f1c7145 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/model_return.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/model_return.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -110,18 +111,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -130,11 +142,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/name.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/name.rb index 45b01b5746d3..be828a1f316f 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/name.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/name.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -154,18 +155,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -174,11 +186,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/nullable_class.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/nullable_class.rb index f81fb17f118a..09c9ce983a33 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/nullable_class.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/nullable_class.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -230,18 +231,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -250,11 +262,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/number_only.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/number_only.rb index 9bf457dfd188..f16ccf580bb9 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/number_only.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/number_only.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -109,18 +110,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -129,11 +141,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/object_with_deprecated_fields.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/object_with_deprecated_fields.rb index dceda346bd70..5b49ba4d887a 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/object_with_deprecated_fields.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/object_with_deprecated_fields.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -138,18 +139,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -158,11 +170,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/order.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/order.rb index f7e7b4eb9117..e780b4a33e07 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/order.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/order.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -191,18 +192,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -211,11 +223,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/outer_composite.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/outer_composite.rb index 2245e8512600..3fa7f5c7f2d7 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/outer_composite.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/outer_composite.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -127,18 +128,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -147,11 +159,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/outer_enum.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/outer_enum.rb index acd2130a7b3f..553a17fc7baa 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/outer_enum.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/outer_enum.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/outer_enum_default_value.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/outer_enum_default_value.rb index 0dd059474528..22218ed7dc56 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/outer_enum_default_value.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/outer_enum_default_value.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/outer_enum_integer.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/outer_enum_integer.rb index d3288d09b952..272c02c4b297 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/outer_enum_integer.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/outer_enum_integer.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/outer_enum_integer_default_value.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/outer_enum_integer_default_value.rb index 147293ad274c..ba0177c87428 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/outer_enum_integer_default_value.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/outer_enum_integer_default_value.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/outer_object_with_enum_property.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/outer_object_with_enum_property.rb index 8ffad20f8d89..4aff91a0894b 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/outer_object_with_enum_property.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/outer_object_with_enum_property.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -148,18 +149,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -168,11 +180,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/parent_with_nullable.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/parent_with_nullable.rb index dde93af94488..3c0654c4a6eb 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/parent_with_nullable.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/parent_with_nullable.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -158,18 +159,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -178,11 +190,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/pet.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/pet.rb index e3594a1fb052..c6157317e624 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/pet.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/pet.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -227,18 +228,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -247,11 +259,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/read_only_first.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/read_only_first.rb index c2121474ebb7..b3453085466d 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/read_only_first.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/read_only_first.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -118,18 +119,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -138,11 +150,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/single_ref_type.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/single_ref_type.rb index 3f09a14e0cbb..935576e416a8 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/single_ref_type.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/single_ref_type.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/special_model_name.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/special_model_name.rb index 9569fbfd13dd..956b8d95ca63 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/special_model_name.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/special_model_name.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -109,18 +110,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -129,11 +141,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/tag.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/tag.rb index 6d6f57468181..dac93098e66f 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/tag.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/tag.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -118,18 +119,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -138,11 +150,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/test_inline_freeform_additional_properties_request.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/test_inline_freeform_additional_properties_request.rb index dc481c119d22..857d0a9ebd3c 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/test_inline_freeform_additional_properties_request.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/test_inline_freeform_additional_properties_request.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -109,18 +110,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -129,11 +141,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-autoload/lib/petstore/models/user.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/user.rb index 9b06f2ff6d7a..a4e13e3f82dd 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/user.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/user.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -173,18 +174,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -193,11 +205,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/Gemfile.lock b/samples/client/petstore/ruby-faraday/Gemfile.lock index 081638f0e42a..89c35709fe4f 100644 --- a/samples/client/petstore/ruby-faraday/Gemfile.lock +++ b/samples/client/petstore/ruby-faraday/Gemfile.lock @@ -15,8 +15,8 @@ GEM diff-lcs (1.5.1) faraday (2.9.0) faraday-net_http (>= 2.0, < 3.2) - faraday-multipart (1.0.4) - multipart-post (~> 2) + faraday-multipart (1.2.0) + multipart-post (~> 2.0) faraday-net_http (3.1.0) net-http jaro_winkler (1.5.6) diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/additional_properties_class.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/additional_properties_class.rb index 9b823593d156..318e5b5bd6e4 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/additional_properties_class.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/additional_properties_class.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -122,18 +123,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -142,11 +154,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/all_of_with_single_ref.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/all_of_with_single_ref.rb index 600c974fa1e5..c9cf74e48eb9 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/all_of_with_single_ref.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/all_of_with_single_ref.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -140,18 +141,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -160,11 +172,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/animal.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/animal.rb index 21d89bccb837..f16064590127 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/animal.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/animal.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -142,18 +143,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -162,11 +174,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/api_response.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/api_response.rb index bbbaf9358be2..2b8f6f3da716 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/api_response.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/api_response.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -127,18 +128,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -147,11 +159,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/array_of_array_of_number_only.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/array_of_array_of_number_only.rb index e20b1728d130..61ec9a339f8a 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/array_of_array_of_number_only.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/array_of_array_of_number_only.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -111,18 +112,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -131,11 +143,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/array_of_number_only.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/array_of_number_only.rb index 63890ff64424..25936c36112d 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/array_of_number_only.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/array_of_number_only.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -111,18 +112,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -131,11 +143,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/array_test.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/array_test.rb index c74060151e07..4250f94d5602 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/array_test.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/array_test.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -161,18 +162,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -181,11 +193,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/capitalization.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/capitalization.rb index e0bbeb211eb3..980b6d4f6fdf 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/capitalization.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/capitalization.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -155,18 +156,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -175,11 +187,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/cat.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/cat.rb index a84dc5038bef..ccf06cb566c7 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/cat.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/cat.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -118,20 +119,30 @@ def hash # @return [Object] Returns the model itself def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) - super(attributes) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -140,11 +151,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash - hash = super - self.class.attribute_map.each_pair do |attr, param| + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end + hash = {} + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/category.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/category.rb index 2f2b7f1a5785..1e13601082aa 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/category.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/category.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -135,18 +136,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -155,11 +167,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/class_model.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/class_model.rb index fafd11df773a..368596110da9 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/class_model.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/class_model.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -110,18 +111,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -130,11 +142,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/client.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/client.rb index a349b7251d7b..2c8707232d25 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/client.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/client.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -109,18 +110,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -129,11 +141,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/cow.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/cow.rb index b100c2538a23..5ed3c0951421 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/cow.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/cow.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/deprecated_object.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/deprecated_object.rb index 9f1ee6720cab..b5cfe6462091 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/deprecated_object.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/deprecated_object.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -109,18 +110,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -129,11 +141,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/dog.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/dog.rb index 522e1a72f47e..2acab0f70063 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/dog.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/dog.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -118,20 +119,30 @@ def hash # @return [Object] Returns the model itself def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) - super(attributes) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -140,11 +151,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash - hash = super - self.class.attribute_map.each_pair do |attr, param| + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end + hash = {} + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/enum_arrays.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/enum_arrays.rb index 1f7c48bf859b..0dc6e78adaf5 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/enum_arrays.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/enum_arrays.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -154,18 +155,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -174,11 +186,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/enum_class.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/enum_class.rb index 54bffd17d38c..a62e4022056d 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/enum_class.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/enum_class.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/enum_test.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/enum_test.rb index 5159875cb89b..b9bd10e9f232 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/enum_test.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/enum_test.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -254,18 +255,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -274,11 +286,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/fake_big_decimal_map200_response.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/fake_big_decimal_map200_response.rb index 6d5e47b59656..2b15275e0af8 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/fake_big_decimal_map200_response.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/fake_big_decimal_map200_response.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -120,18 +121,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -140,11 +152,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/file.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/file.rb index 219237eb3c07..e16db98d6d8e 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/file.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/file.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -111,18 +112,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -131,11 +143,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/file_schema_test_class.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/file_schema_test_class.rb index 8fdab5a25e86..b8c3a85378e7 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/file_schema_test_class.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/file_schema_test_class.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -120,18 +121,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -140,11 +152,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/foo.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/foo.rb index ceb5b7497955..4912ef30b029 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/foo.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/foo.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -111,18 +112,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -131,11 +143,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/foo_get_default_response.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/foo_get_default_response.rb index 42538a14e2cb..9994654f38d4 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/foo_get_default_response.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/foo_get_default_response.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -109,18 +110,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -129,11 +141,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/format_test.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/format_test.rb index 03a4e130a8f9..b22f471e3367 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/format_test.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/format_test.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -525,18 +526,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -545,11 +557,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/has_only_read_only.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/has_only_read_only.rb index cc584c09e54f..e12981d112e4 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/has_only_read_only.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/has_only_read_only.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -118,18 +119,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -138,11 +150,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/health_check_result.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/health_check_result.rb index a66e1b71331d..5ee62c4fc45e 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/health_check_result.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/health_check_result.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -111,18 +112,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -131,11 +143,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/list.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/list.rb index 2dc658065278..ffbc3b957a30 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/list.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/list.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -109,18 +110,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -129,11 +141,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/mammal.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/mammal.rb index 91c5a53ffdcd..9150806f1c9f 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/mammal.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/mammal.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/mammal_anyof.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/mammal_anyof.rb index 36e88a462640..1e1b125ad925 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/mammal_anyof.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/mammal_anyof.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/mammal_without_discriminator.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/mammal_without_discriminator.rb index 11556be23523..200f1d743785 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/mammal_without_discriminator.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/mammal_without_discriminator.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/map_test.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/map_test.rb index 78c5472f24ae..acb0dc9c82d4 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/map_test.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/map_test.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -166,18 +167,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -186,11 +198,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/mixed_properties_and_additional_properties_class.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/mixed_properties_and_additional_properties_class.rb index bf1d3768951b..36969d7426cb 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/mixed_properties_and_additional_properties_class.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/mixed_properties_and_additional_properties_class.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -129,18 +130,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -149,11 +161,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/model200_response.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/model200_response.rb index 9cff83ced2c9..72b7d2292c99 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/model200_response.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/model200_response.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -119,18 +120,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -139,11 +151,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/model_return.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/model_return.rb index d520a45c2040..61b38f1c7145 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/model_return.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/model_return.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -110,18 +111,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -130,11 +142,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/name.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/name.rb index 45b01b5746d3..be828a1f316f 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/name.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/name.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -154,18 +155,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -174,11 +186,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/nullable_class.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/nullable_class.rb index f81fb17f118a..09c9ce983a33 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/nullable_class.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/nullable_class.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -230,18 +231,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -250,11 +262,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/number_only.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/number_only.rb index 9bf457dfd188..f16ccf580bb9 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/number_only.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/number_only.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -109,18 +110,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -129,11 +141,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/object_with_deprecated_fields.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/object_with_deprecated_fields.rb index dceda346bd70..5b49ba4d887a 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/object_with_deprecated_fields.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/object_with_deprecated_fields.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -138,18 +139,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -158,11 +170,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/one_of_primitive_types.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/one_of_primitive_types.rb index 68d2585262a4..e15b48634c65 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/one_of_primitive_types.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/one_of_primitive_types.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/order.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/order.rb index f7e7b4eb9117..e780b4a33e07 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/order.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/order.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -191,18 +192,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -211,11 +223,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/outer_composite.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/outer_composite.rb index 2245e8512600..3fa7f5c7f2d7 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/outer_composite.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/outer_composite.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -127,18 +128,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -147,11 +159,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/outer_enum.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/outer_enum.rb index acd2130a7b3f..553a17fc7baa 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/outer_enum.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/outer_enum.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/outer_enum_default_value.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/outer_enum_default_value.rb index 0dd059474528..22218ed7dc56 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/outer_enum_default_value.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/outer_enum_default_value.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/outer_enum_integer.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/outer_enum_integer.rb index c39ede502d25..e01f8df22f36 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/outer_enum_integer.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/outer_enum_integer.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/outer_enum_integer_default_value.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/outer_enum_integer_default_value.rb index 147293ad274c..ba0177c87428 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/outer_enum_integer_default_value.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/outer_enum_integer_default_value.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/outer_object_with_enum_property.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/outer_object_with_enum_property.rb index 8ffad20f8d89..4aff91a0894b 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/outer_object_with_enum_property.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/outer_object_with_enum_property.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -148,18 +149,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -168,11 +180,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/pet.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/pet.rb index e3594a1fb052..c6157317e624 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/pet.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/pet.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -227,18 +228,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -247,11 +259,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/property_name_mapping.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/property_name_mapping.rb index 8328edb9227a..3456b9510d0f 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/property_name_mapping.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/property_name_mapping.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -136,18 +137,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -156,11 +168,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/read_only_first.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/read_only_first.rb index c2121474ebb7..b3453085466d 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/read_only_first.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/read_only_first.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -118,18 +119,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -138,11 +150,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/single_ref_type.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/single_ref_type.rb index 3f09a14e0cbb..935576e416a8 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/single_ref_type.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/single_ref_type.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/special_model_name.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/special_model_name.rb index 9569fbfd13dd..956b8d95ca63 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/special_model_name.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/special_model_name.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -109,18 +110,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -129,11 +141,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/tag.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/tag.rb index 6d6f57468181..dac93098e66f 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/tag.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/tag.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -118,18 +119,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -138,11 +150,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/test_inline_freeform_additional_properties_request.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/test_inline_freeform_additional_properties_request.rb index dc481c119d22..857d0a9ebd3c 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/test_inline_freeform_additional_properties_request.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/test_inline_freeform_additional_properties_request.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -109,18 +110,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -129,11 +141,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/user.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/user.rb index 9b06f2ff6d7a..a4e13e3f82dd 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/user.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/user.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -173,18 +174,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -193,11 +205,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/whale.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/whale.rb index 23249be434e4..b2de797c8a39 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/whale.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/whale.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -144,18 +145,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -164,11 +176,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/lib/petstore/models/zebra.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/zebra.rb index 10e910f409f7..6d766c38164b 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/zebra.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/zebra.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -169,18 +170,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -189,11 +201,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-faraday/spec/custom/base_object_spec.rb b/samples/client/petstore/ruby-faraday/spec/custom/base_object_spec.rb index a046c5bd4e11..de5c1890f244 100644 --- a/samples/client/petstore/ruby-faraday/spec/custom/base_object_spec.rb +++ b/samples/client/petstore/ruby-faraday/spec/custom/base_object_spec.rb @@ -166,4 +166,51 @@ def initialize(attributes = {}) expect(obj.to_hash).to eq(expect_data) end end + + describe 'attributes inherited from an allOf parent' do + it 'build_from_hash maps the parent attributes too' do + cat = Petstore::Cat.build_from_hash({ 'className' => 'Cat', 'color' => 'black', 'declawed' => true }) + + expect(cat).to be_instance_of(Petstore::Cat) + expect(cat.class_name).to eq('Cat') + expect(cat.color).to eq('black') + expect(cat.declawed).to eq(true) + end + + it 'to_hash serializes the parent attributes too' do + cat = Petstore::Cat.build_from_hash({ 'className' => 'Cat', 'color' => 'black', 'declawed' => true }) + + expect(cat.to_hash).to eq({ className: 'Cat', color: 'black', declawed: true }) + end + + it 'a child redeclaring an attribute as non-nullable wins over the ancestor nullability' do + parent = Class.new(Petstore::Animal) do + def self.attribute_map + { :flag => :flag } + end + + def self.openapi_types + { :flag => :'String' } + end + + def self.openapi_nullable + Set.new([:flag]) + end + attr_accessor :flag + end + child = Class.new(parent) do + def self.openapi_nullable + Set.new([]) + end + end + + nullable_instance = parent.allocate + nullable_instance.instance_variable_set(:@flag, nil) + expect(nullable_instance.to_hash).to eq({ flag: nil }) + + non_nullable_instance = child.allocate + non_nullable_instance.instance_variable_set(:@flag, nil) + expect(non_nullable_instance.to_hash).not_to have_key(:flag) + end + end end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/additional_properties_class.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/additional_properties_class.rb index 9b823593d156..318e5b5bd6e4 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/additional_properties_class.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/additional_properties_class.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -122,18 +123,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -142,11 +154,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/all_of_with_single_ref.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/all_of_with_single_ref.rb index 600c974fa1e5..c9cf74e48eb9 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/all_of_with_single_ref.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/all_of_with_single_ref.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -140,18 +141,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -160,11 +172,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/animal.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/animal.rb index 21d89bccb837..f16064590127 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/animal.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/animal.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -142,18 +143,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -162,11 +174,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/api_response.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/api_response.rb index bbbaf9358be2..2b8f6f3da716 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/api_response.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/api_response.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -127,18 +128,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -147,11 +159,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/array_of_array_of_number_only.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/array_of_array_of_number_only.rb index e20b1728d130..61ec9a339f8a 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/array_of_array_of_number_only.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/array_of_array_of_number_only.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -111,18 +112,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -131,11 +143,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/array_of_number_only.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/array_of_number_only.rb index 63890ff64424..25936c36112d 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/array_of_number_only.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/array_of_number_only.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -111,18 +112,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -131,11 +143,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/array_test.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/array_test.rb index c74060151e07..4250f94d5602 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/array_test.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/array_test.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -161,18 +162,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -181,11 +193,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/capitalization.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/capitalization.rb index e0bbeb211eb3..980b6d4f6fdf 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/capitalization.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/capitalization.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -155,18 +156,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -175,11 +187,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/cat.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/cat.rb index a84dc5038bef..ccf06cb566c7 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/cat.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/cat.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -118,20 +119,30 @@ def hash # @return [Object] Returns the model itself def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) - super(attributes) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -140,11 +151,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash - hash = super - self.class.attribute_map.each_pair do |attr, param| + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end + hash = {} + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/category.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/category.rb index 2f2b7f1a5785..1e13601082aa 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/category.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/category.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -135,18 +136,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -155,11 +167,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/class_model.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/class_model.rb index fafd11df773a..368596110da9 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/class_model.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/class_model.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -110,18 +111,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -130,11 +142,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/client.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/client.rb index a349b7251d7b..2c8707232d25 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/client.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/client.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -109,18 +110,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -129,11 +141,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/cow.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/cow.rb index b100c2538a23..5ed3c0951421 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/cow.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/cow.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/deprecated_object.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/deprecated_object.rb index 9f1ee6720cab..b5cfe6462091 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/deprecated_object.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/deprecated_object.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -109,18 +110,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -129,11 +141,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/dog.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/dog.rb index 522e1a72f47e..2acab0f70063 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/dog.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/dog.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -118,20 +119,30 @@ def hash # @return [Object] Returns the model itself def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) - super(attributes) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -140,11 +151,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash - hash = super - self.class.attribute_map.each_pair do |attr, param| + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end + hash = {} + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/enum_arrays.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/enum_arrays.rb index 1f7c48bf859b..0dc6e78adaf5 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/enum_arrays.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/enum_arrays.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -154,18 +155,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -174,11 +186,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/enum_class.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/enum_class.rb index 54bffd17d38c..a62e4022056d 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/enum_class.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/enum_class.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/enum_test.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/enum_test.rb index 5159875cb89b..b9bd10e9f232 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/enum_test.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/enum_test.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -254,18 +255,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -274,11 +286,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/fake_big_decimal_map200_response.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/fake_big_decimal_map200_response.rb index 6d5e47b59656..2b15275e0af8 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/fake_big_decimal_map200_response.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/fake_big_decimal_map200_response.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -120,18 +121,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -140,11 +152,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/file.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/file.rb index 219237eb3c07..e16db98d6d8e 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/file.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/file.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -111,18 +112,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -131,11 +143,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/file_schema_test_class.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/file_schema_test_class.rb index 8fdab5a25e86..b8c3a85378e7 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/file_schema_test_class.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/file_schema_test_class.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -120,18 +121,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -140,11 +152,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/foo.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/foo.rb index ceb5b7497955..4912ef30b029 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/foo.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/foo.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -111,18 +112,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -131,11 +143,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/foo_get_default_response.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/foo_get_default_response.rb index 42538a14e2cb..9994654f38d4 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/foo_get_default_response.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/foo_get_default_response.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -109,18 +110,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -129,11 +141,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/format_test.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/format_test.rb index 03a4e130a8f9..b22f471e3367 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/format_test.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/format_test.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -525,18 +526,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -545,11 +557,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/has_only_read_only.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/has_only_read_only.rb index cc584c09e54f..e12981d112e4 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/has_only_read_only.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/has_only_read_only.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -118,18 +119,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -138,11 +150,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/health_check_result.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/health_check_result.rb index a66e1b71331d..5ee62c4fc45e 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/health_check_result.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/health_check_result.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -111,18 +112,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -131,11 +143,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/list.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/list.rb index 2dc658065278..ffbc3b957a30 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/list.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/list.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -109,18 +110,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -129,11 +141,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/mammal.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/mammal.rb index 91c5a53ffdcd..9150806f1c9f 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/mammal.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/mammal.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/mammal_anyof.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/mammal_anyof.rb index 36e88a462640..1e1b125ad925 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/mammal_anyof.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/mammal_anyof.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/mammal_without_discriminator.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/mammal_without_discriminator.rb index 11556be23523..200f1d743785 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/mammal_without_discriminator.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/mammal_without_discriminator.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/map_test.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/map_test.rb index 78c5472f24ae..acb0dc9c82d4 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/map_test.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/map_test.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -166,18 +167,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -186,11 +198,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/mixed_properties_and_additional_properties_class.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/mixed_properties_and_additional_properties_class.rb index bf1d3768951b..36969d7426cb 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/mixed_properties_and_additional_properties_class.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/mixed_properties_and_additional_properties_class.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -129,18 +130,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -149,11 +161,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/model200_response.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/model200_response.rb index 9cff83ced2c9..72b7d2292c99 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/model200_response.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/model200_response.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -119,18 +120,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -139,11 +151,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/model_return.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/model_return.rb index d520a45c2040..61b38f1c7145 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/model_return.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/model_return.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -110,18 +111,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -130,11 +142,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/name.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/name.rb index 45b01b5746d3..be828a1f316f 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/name.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/name.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -154,18 +155,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -174,11 +186,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/nullable_class.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/nullable_class.rb index f81fb17f118a..09c9ce983a33 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/nullable_class.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/nullable_class.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -230,18 +231,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -250,11 +262,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/number_only.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/number_only.rb index 9bf457dfd188..f16ccf580bb9 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/number_only.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/number_only.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -109,18 +110,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -129,11 +141,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/object_with_deprecated_fields.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/object_with_deprecated_fields.rb index dceda346bd70..5b49ba4d887a 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/object_with_deprecated_fields.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/object_with_deprecated_fields.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -138,18 +139,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -158,11 +170,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/one_of_primitive_types.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/one_of_primitive_types.rb index 68d2585262a4..e15b48634c65 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/one_of_primitive_types.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/one_of_primitive_types.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/order.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/order.rb index f7e7b4eb9117..e780b4a33e07 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/order.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/order.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -191,18 +192,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -211,11 +223,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/outer_composite.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/outer_composite.rb index 2245e8512600..3fa7f5c7f2d7 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/outer_composite.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/outer_composite.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -127,18 +128,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -147,11 +159,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/outer_enum.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/outer_enum.rb index acd2130a7b3f..553a17fc7baa 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/outer_enum.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/outer_enum.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/outer_enum_default_value.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/outer_enum_default_value.rb index 0dd059474528..22218ed7dc56 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/outer_enum_default_value.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/outer_enum_default_value.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/outer_enum_integer.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/outer_enum_integer.rb index c39ede502d25..e01f8df22f36 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/outer_enum_integer.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/outer_enum_integer.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/outer_enum_integer_default_value.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/outer_enum_integer_default_value.rb index 147293ad274c..ba0177c87428 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/outer_enum_integer_default_value.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/outer_enum_integer_default_value.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/outer_object_with_enum_property.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/outer_object_with_enum_property.rb index 8ffad20f8d89..4aff91a0894b 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/outer_object_with_enum_property.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/outer_object_with_enum_property.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -148,18 +149,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -168,11 +180,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/pet.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/pet.rb index e3594a1fb052..c6157317e624 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/pet.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/pet.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -227,18 +228,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -247,11 +259,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/property_name_mapping.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/property_name_mapping.rb index 8328edb9227a..3456b9510d0f 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/property_name_mapping.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/property_name_mapping.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -136,18 +137,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -156,11 +168,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/read_only_first.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/read_only_first.rb index c2121474ebb7..b3453085466d 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/read_only_first.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/read_only_first.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -118,18 +119,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -138,11 +150,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/single_ref_type.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/single_ref_type.rb index 3f09a14e0cbb..935576e416a8 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/single_ref_type.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/single_ref_type.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/special_model_name.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/special_model_name.rb index 9569fbfd13dd..956b8d95ca63 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/special_model_name.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/special_model_name.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -109,18 +110,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -129,11 +141,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/tag.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/tag.rb index 6d6f57468181..dac93098e66f 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/tag.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/tag.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -118,18 +119,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -138,11 +150,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/test_inline_freeform_additional_properties_request.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/test_inline_freeform_additional_properties_request.rb index dc481c119d22..857d0a9ebd3c 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/test_inline_freeform_additional_properties_request.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/test_inline_freeform_additional_properties_request.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -109,18 +110,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -129,11 +141,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/user.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/user.rb index 9b06f2ff6d7a..a4e13e3f82dd 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/user.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/user.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -173,18 +174,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -193,11 +205,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/whale.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/whale.rb index 23249be434e4..b2de797c8a39 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/whale.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/whale.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -144,18 +145,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -164,11 +176,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/zebra.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/zebra.rb index 10e910f409f7..6d766c38164b 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/zebra.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/zebra.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -169,18 +170,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -189,11 +201,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby-httpx/spec/custom/base_object_spec.rb b/samples/client/petstore/ruby-httpx/spec/custom/base_object_spec.rb index a046c5bd4e11..de5c1890f244 100644 --- a/samples/client/petstore/ruby-httpx/spec/custom/base_object_spec.rb +++ b/samples/client/petstore/ruby-httpx/spec/custom/base_object_spec.rb @@ -166,4 +166,51 @@ def initialize(attributes = {}) expect(obj.to_hash).to eq(expect_data) end end + + describe 'attributes inherited from an allOf parent' do + it 'build_from_hash maps the parent attributes too' do + cat = Petstore::Cat.build_from_hash({ 'className' => 'Cat', 'color' => 'black', 'declawed' => true }) + + expect(cat).to be_instance_of(Petstore::Cat) + expect(cat.class_name).to eq('Cat') + expect(cat.color).to eq('black') + expect(cat.declawed).to eq(true) + end + + it 'to_hash serializes the parent attributes too' do + cat = Petstore::Cat.build_from_hash({ 'className' => 'Cat', 'color' => 'black', 'declawed' => true }) + + expect(cat.to_hash).to eq({ className: 'Cat', color: 'black', declawed: true }) + end + + it 'a child redeclaring an attribute as non-nullable wins over the ancestor nullability' do + parent = Class.new(Petstore::Animal) do + def self.attribute_map + { :flag => :flag } + end + + def self.openapi_types + { :flag => :'String' } + end + + def self.openapi_nullable + Set.new([:flag]) + end + attr_accessor :flag + end + child = Class.new(parent) do + def self.openapi_nullable + Set.new([]) + end + end + + nullable_instance = parent.allocate + nullable_instance.instance_variable_set(:@flag, nil) + expect(nullable_instance.to_hash).to eq({ flag: nil }) + + non_nullable_instance = child.allocate + non_nullable_instance.instance_variable_set(:@flag, nil) + expect(non_nullable_instance.to_hash).not_to have_key(:flag) + end + end end diff --git a/samples/client/petstore/ruby/lib/petstore/models/additional_properties_class.rb b/samples/client/petstore/ruby/lib/petstore/models/additional_properties_class.rb index 9b823593d156..318e5b5bd6e4 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/additional_properties_class.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/additional_properties_class.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -122,18 +123,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -142,11 +154,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/all_of_with_single_ref.rb b/samples/client/petstore/ruby/lib/petstore/models/all_of_with_single_ref.rb index 600c974fa1e5..c9cf74e48eb9 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/all_of_with_single_ref.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/all_of_with_single_ref.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -140,18 +141,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -160,11 +172,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/animal.rb b/samples/client/petstore/ruby/lib/petstore/models/animal.rb index 21d89bccb837..f16064590127 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/animal.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/animal.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -142,18 +143,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -162,11 +174,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/api_response.rb b/samples/client/petstore/ruby/lib/petstore/models/api_response.rb index bbbaf9358be2..2b8f6f3da716 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/api_response.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/api_response.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -127,18 +128,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -147,11 +159,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/array_of_array_of_number_only.rb b/samples/client/petstore/ruby/lib/petstore/models/array_of_array_of_number_only.rb index e20b1728d130..61ec9a339f8a 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/array_of_array_of_number_only.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/array_of_array_of_number_only.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -111,18 +112,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -131,11 +143,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/array_of_number_only.rb b/samples/client/petstore/ruby/lib/petstore/models/array_of_number_only.rb index 63890ff64424..25936c36112d 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/array_of_number_only.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/array_of_number_only.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -111,18 +112,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -131,11 +143,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/array_test.rb b/samples/client/petstore/ruby/lib/petstore/models/array_test.rb index c74060151e07..4250f94d5602 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/array_test.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/array_test.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -161,18 +162,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -181,11 +193,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/capitalization.rb b/samples/client/petstore/ruby/lib/petstore/models/capitalization.rb index e0bbeb211eb3..980b6d4f6fdf 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/capitalization.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/capitalization.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -155,18 +156,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -175,11 +187,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/cat.rb b/samples/client/petstore/ruby/lib/petstore/models/cat.rb index a84dc5038bef..ccf06cb566c7 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/cat.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/cat.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -118,20 +119,30 @@ def hash # @return [Object] Returns the model itself def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) - super(attributes) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -140,11 +151,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash - hash = super - self.class.attribute_map.each_pair do |attr, param| + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end + hash = {} + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/category.rb b/samples/client/petstore/ruby/lib/petstore/models/category.rb index 2f2b7f1a5785..1e13601082aa 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/category.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/category.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -135,18 +136,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -155,11 +167,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/class_model.rb b/samples/client/petstore/ruby/lib/petstore/models/class_model.rb index fafd11df773a..368596110da9 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/class_model.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/class_model.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -110,18 +111,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -130,11 +142,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/client.rb b/samples/client/petstore/ruby/lib/petstore/models/client.rb index a349b7251d7b..2c8707232d25 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/client.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/client.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -109,18 +110,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -129,11 +141,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/cow.rb b/samples/client/petstore/ruby/lib/petstore/models/cow.rb index b100c2538a23..5ed3c0951421 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/cow.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/cow.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby/lib/petstore/models/deprecated_object.rb b/samples/client/petstore/ruby/lib/petstore/models/deprecated_object.rb index 9f1ee6720cab..b5cfe6462091 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/deprecated_object.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/deprecated_object.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -109,18 +110,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -129,11 +141,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/dog.rb b/samples/client/petstore/ruby/lib/petstore/models/dog.rb index 522e1a72f47e..2acab0f70063 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/dog.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/dog.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -118,20 +119,30 @@ def hash # @return [Object] Returns the model itself def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) - super(attributes) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -140,11 +151,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash - hash = super - self.class.attribute_map.each_pair do |attr, param| + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end + hash = {} + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/enum_arrays.rb b/samples/client/petstore/ruby/lib/petstore/models/enum_arrays.rb index 1f7c48bf859b..0dc6e78adaf5 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/enum_arrays.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/enum_arrays.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -154,18 +155,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -174,11 +186,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/enum_class.rb b/samples/client/petstore/ruby/lib/petstore/models/enum_class.rb index 54bffd17d38c..a62e4022056d 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/enum_class.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/enum_class.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby/lib/petstore/models/enum_test.rb b/samples/client/petstore/ruby/lib/petstore/models/enum_test.rb index 5159875cb89b..b9bd10e9f232 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/enum_test.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/enum_test.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -254,18 +255,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -274,11 +286,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/fake_big_decimal_map200_response.rb b/samples/client/petstore/ruby/lib/petstore/models/fake_big_decimal_map200_response.rb index 6d5e47b59656..2b15275e0af8 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/fake_big_decimal_map200_response.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/fake_big_decimal_map200_response.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -120,18 +121,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -140,11 +152,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/file.rb b/samples/client/petstore/ruby/lib/petstore/models/file.rb index 219237eb3c07..e16db98d6d8e 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/file.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/file.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -111,18 +112,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -131,11 +143,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/file_schema_test_class.rb b/samples/client/petstore/ruby/lib/petstore/models/file_schema_test_class.rb index 8fdab5a25e86..b8c3a85378e7 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/file_schema_test_class.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/file_schema_test_class.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -120,18 +121,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -140,11 +152,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/foo.rb b/samples/client/petstore/ruby/lib/petstore/models/foo.rb index ceb5b7497955..4912ef30b029 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/foo.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/foo.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -111,18 +112,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -131,11 +143,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/foo_get_default_response.rb b/samples/client/petstore/ruby/lib/petstore/models/foo_get_default_response.rb index 42538a14e2cb..9994654f38d4 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/foo_get_default_response.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/foo_get_default_response.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -109,18 +110,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -129,11 +141,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/format_test.rb b/samples/client/petstore/ruby/lib/petstore/models/format_test.rb index 03a4e130a8f9..b22f471e3367 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/format_test.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/format_test.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -525,18 +526,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -545,11 +557,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/has_only_read_only.rb b/samples/client/petstore/ruby/lib/petstore/models/has_only_read_only.rb index cc584c09e54f..e12981d112e4 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/has_only_read_only.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/has_only_read_only.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -118,18 +119,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -138,11 +150,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/health_check_result.rb b/samples/client/petstore/ruby/lib/petstore/models/health_check_result.rb index a66e1b71331d..5ee62c4fc45e 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/health_check_result.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/health_check_result.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -111,18 +112,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -131,11 +143,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/list.rb b/samples/client/petstore/ruby/lib/petstore/models/list.rb index 2dc658065278..ffbc3b957a30 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/list.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/list.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -109,18 +110,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -129,11 +141,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/mammal.rb b/samples/client/petstore/ruby/lib/petstore/models/mammal.rb index 91c5a53ffdcd..9150806f1c9f 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/mammal.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/mammal.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby/lib/petstore/models/mammal_anyof.rb b/samples/client/petstore/ruby/lib/petstore/models/mammal_anyof.rb index 36e88a462640..1e1b125ad925 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/mammal_anyof.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/mammal_anyof.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby/lib/petstore/models/mammal_without_discriminator.rb b/samples/client/petstore/ruby/lib/petstore/models/mammal_without_discriminator.rb index 11556be23523..200f1d743785 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/mammal_without_discriminator.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/mammal_without_discriminator.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby/lib/petstore/models/map_test.rb b/samples/client/petstore/ruby/lib/petstore/models/map_test.rb index 78c5472f24ae..acb0dc9c82d4 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/map_test.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/map_test.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -166,18 +167,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -186,11 +198,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/mixed_properties_and_additional_properties_class.rb b/samples/client/petstore/ruby/lib/petstore/models/mixed_properties_and_additional_properties_class.rb index bf1d3768951b..36969d7426cb 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/mixed_properties_and_additional_properties_class.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/mixed_properties_and_additional_properties_class.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -129,18 +130,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -149,11 +161,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/model200_response.rb b/samples/client/petstore/ruby/lib/petstore/models/model200_response.rb index 9cff83ced2c9..72b7d2292c99 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/model200_response.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/model200_response.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -119,18 +120,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -139,11 +151,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/model_return.rb b/samples/client/petstore/ruby/lib/petstore/models/model_return.rb index d520a45c2040..61b38f1c7145 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/model_return.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/model_return.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -110,18 +111,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -130,11 +142,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/name.rb b/samples/client/petstore/ruby/lib/petstore/models/name.rb index 45b01b5746d3..be828a1f316f 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/name.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/name.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -154,18 +155,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -174,11 +186,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/nullable_class.rb b/samples/client/petstore/ruby/lib/petstore/models/nullable_class.rb index f81fb17f118a..09c9ce983a33 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/nullable_class.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/nullable_class.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -230,18 +231,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -250,11 +262,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/number_only.rb b/samples/client/petstore/ruby/lib/petstore/models/number_only.rb index 9bf457dfd188..f16ccf580bb9 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/number_only.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/number_only.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -109,18 +110,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -129,11 +141,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/object_with_deprecated_fields.rb b/samples/client/petstore/ruby/lib/petstore/models/object_with_deprecated_fields.rb index dceda346bd70..5b49ba4d887a 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/object_with_deprecated_fields.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/object_with_deprecated_fields.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -138,18 +139,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -158,11 +170,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/one_of_primitive_types.rb b/samples/client/petstore/ruby/lib/petstore/models/one_of_primitive_types.rb index 68d2585262a4..e15b48634c65 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/one_of_primitive_types.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/one_of_primitive_types.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby/lib/petstore/models/order.rb b/samples/client/petstore/ruby/lib/petstore/models/order.rb index f7e7b4eb9117..e780b4a33e07 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/order.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/order.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -191,18 +192,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -211,11 +223,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/outer_composite.rb b/samples/client/petstore/ruby/lib/petstore/models/outer_composite.rb index 2245e8512600..3fa7f5c7f2d7 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/outer_composite.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/outer_composite.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -127,18 +128,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -147,11 +159,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/outer_enum.rb b/samples/client/petstore/ruby/lib/petstore/models/outer_enum.rb index 2a28686b572a..a57a48e52b93 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/outer_enum.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/outer_enum.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby/lib/petstore/models/outer_enum_default_value.rb b/samples/client/petstore/ruby/lib/petstore/models/outer_enum_default_value.rb index 97ef2fbb547c..a0d4ef9c80f9 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/outer_enum_default_value.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/outer_enum_default_value.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby/lib/petstore/models/outer_enum_integer.rb b/samples/client/petstore/ruby/lib/petstore/models/outer_enum_integer.rb index c39ede502d25..e01f8df22f36 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/outer_enum_integer.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/outer_enum_integer.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby/lib/petstore/models/outer_enum_integer_default_value.rb b/samples/client/petstore/ruby/lib/petstore/models/outer_enum_integer_default_value.rb index 147293ad274c..ba0177c87428 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/outer_enum_integer_default_value.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/outer_enum_integer_default_value.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby/lib/petstore/models/outer_object_with_enum_property.rb b/samples/client/petstore/ruby/lib/petstore/models/outer_object_with_enum_property.rb index 8ffad20f8d89..4aff91a0894b 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/outer_object_with_enum_property.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/outer_object_with_enum_property.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -148,18 +149,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -168,11 +180,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/pet.rb b/samples/client/petstore/ruby/lib/petstore/models/pet.rb index e3594a1fb052..c6157317e624 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/pet.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/pet.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -227,18 +228,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -247,11 +259,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/property_name_mapping.rb b/samples/client/petstore/ruby/lib/petstore/models/property_name_mapping.rb index 09e50b68dc06..57b0bdc57fcc 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/property_name_mapping.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/property_name_mapping.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -136,18 +137,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -156,11 +168,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/read_only_first.rb b/samples/client/petstore/ruby/lib/petstore/models/read_only_first.rb index c2121474ebb7..b3453085466d 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/read_only_first.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/read_only_first.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -118,18 +119,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -138,11 +150,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/single_ref_type.rb b/samples/client/petstore/ruby/lib/petstore/models/single_ref_type.rb index 3f09a14e0cbb..935576e416a8 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/single_ref_type.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/single_ref_type.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore diff --git a/samples/client/petstore/ruby/lib/petstore/models/special_model_name.rb b/samples/client/petstore/ruby/lib/petstore/models/special_model_name.rb index 9569fbfd13dd..956b8d95ca63 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/special_model_name.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/special_model_name.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -109,18 +110,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -129,11 +141,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/tag.rb b/samples/client/petstore/ruby/lib/petstore/models/tag.rb index 6d6f57468181..dac93098e66f 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/tag.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/tag.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -118,18 +119,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -138,11 +150,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/test_inline_freeform_additional_properties_request.rb b/samples/client/petstore/ruby/lib/petstore/models/test_inline_freeform_additional_properties_request.rb index dc481c119d22..857d0a9ebd3c 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/test_inline_freeform_additional_properties_request.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/test_inline_freeform_additional_properties_request.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -109,18 +110,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -129,11 +141,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/user.rb b/samples/client/petstore/ruby/lib/petstore/models/user.rb index 9b06f2ff6d7a..a4e13e3f82dd 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/user.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/user.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -173,18 +174,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -193,11 +205,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/whale.rb b/samples/client/petstore/ruby/lib/petstore/models/whale.rb index 23249be434e4..b2de797c8a39 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/whale.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/whale.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -144,18 +145,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -164,11 +176,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/zebra.rb b/samples/client/petstore/ruby/lib/petstore/models/zebra.rb index 10e910f409f7..6d766c38164b 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/zebra.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/zebra.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -169,18 +170,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -189,11 +201,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/spec/custom/base_object_spec.rb b/samples/client/petstore/ruby/spec/custom/base_object_spec.rb index a046c5bd4e11..de5c1890f244 100644 --- a/samples/client/petstore/ruby/spec/custom/base_object_spec.rb +++ b/samples/client/petstore/ruby/spec/custom/base_object_spec.rb @@ -166,4 +166,51 @@ def initialize(attributes = {}) expect(obj.to_hash).to eq(expect_data) end end + + describe 'attributes inherited from an allOf parent' do + it 'build_from_hash maps the parent attributes too' do + cat = Petstore::Cat.build_from_hash({ 'className' => 'Cat', 'color' => 'black', 'declawed' => true }) + + expect(cat).to be_instance_of(Petstore::Cat) + expect(cat.class_name).to eq('Cat') + expect(cat.color).to eq('black') + expect(cat.declawed).to eq(true) + end + + it 'to_hash serializes the parent attributes too' do + cat = Petstore::Cat.build_from_hash({ 'className' => 'Cat', 'color' => 'black', 'declawed' => true }) + + expect(cat.to_hash).to eq({ className: 'Cat', color: 'black', declawed: true }) + end + + it 'a child redeclaring an attribute as non-nullable wins over the ancestor nullability' do + parent = Class.new(Petstore::Animal) do + def self.attribute_map + { :flag => :flag } + end + + def self.openapi_types + { :flag => :'String' } + end + + def self.openapi_nullable + Set.new([:flag]) + end + attr_accessor :flag + end + child = Class.new(parent) do + def self.openapi_nullable + Set.new([]) + end + end + + nullable_instance = parent.allocate + nullable_instance.instance_variable_set(:@flag, nil) + expect(nullable_instance.to_hash).to eq({ flag: nil }) + + non_nullable_instance = child.allocate + non_nullable_instance.instance_variable_set(:@flag, nil) + expect(non_nullable_instance.to_hash).not_to have_key(:flag) + end + end end diff --git a/samples/openapi3/client/features/generate-alias-as-model/ruby-client/lib/petstore/models/array_alias.rb b/samples/openapi3/client/features/generate-alias-as-model/ruby-client/lib/petstore/models/array_alias.rb index 9ffe5b9100b1..6cd3cb0be883 100644 --- a/samples/openapi3/client/features/generate-alias-as-model/ruby-client/lib/petstore/models/array_alias.rb +++ b/samples/openapi3/client/features/generate-alias-as-model/ruby-client/lib/petstore/models/array_alias.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -102,20 +103,30 @@ def hash # @return [Object] Returns the model itself def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) - super(attributes) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -124,11 +135,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash - hash = super - self.class.attribute_map.each_pair do |attr, param| + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end + hash = {} + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/openapi3/client/features/generate-alias-as-model/ruby-client/lib/petstore/models/map_alias.rb b/samples/openapi3/client/features/generate-alias-as-model/ruby-client/lib/petstore/models/map_alias.rb index 431c5fbcab6c..740cfc041047 100644 --- a/samples/openapi3/client/features/generate-alias-as-model/ruby-client/lib/petstore/models/map_alias.rb +++ b/samples/openapi3/client/features/generate-alias-as-model/ruby-client/lib/petstore/models/map_alias.rb @@ -11,6 +11,7 @@ =end require 'date' +require 'set' require 'time' module Petstore @@ -100,18 +101,29 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # collect the attributes this model knows about, including the ones + # defined in its parent(s), so an allOf child also maps its inherited + # attributes (the child's own declaration wins on a name clash) + types = openapi_types + map = attribute_map + klass = superclass + while klass.respond_to?(:openapi_types) + types = klass.openapi_types.merge(types) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + types.each_pair do |key, type| + if attributes.key?(map[key]) && attributes[map[key]].nil? transformed_hash["#{key}"] = nil elsif type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not - if attributes[attribute_map[key]].is_a?(Array) - transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) } + if attributes[map[key]].is_a?(Array) + transformed_hash["#{key}"] = attributes[map[key]].map { |v| _deserialize($1, v) } end - elsif !attributes[attribute_map[key]].nil? - transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]]) + elsif !attributes[map[key]].nil? + transformed_hash["#{key}"] = _deserialize(type, attributes[map[key]]) end end new(transformed_hash) @@ -120,11 +132,24 @@ def self.build_from_hash(attributes) # Returns the object in the form of hash # @return [Hash] Returns the object in the form of hash def to_hash + # collect the attributes this model knows about, including the ones defined + # in its parent(s): attribute_map and openapi_nullable resolve to the child + # class in every ancestor frame, so the inherited super chain only repeated + # the child's own attributes and dropped the inherited ones + map = self.class.attribute_map + nullable = self.class.openapi_nullable + klass = self.class.superclass + while klass.respond_to?(:openapi_types) + # an ancestor's nullability only applies to attributes no nearer class redeclares + nullable |= klass.openapi_nullable & (klass.attribute_map.keys - map.keys) + map = klass.attribute_map.merge(map) + klass = klass.superclass + end hash = {} - self.class.attribute_map.each_pair do |attr, param| + map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end