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..68767dfcfb7c 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,21 @@ # @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) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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 +26,12 @@ # 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| + hash = {} + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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/partial_model_generic.mustache b/modules/openapi-generator/src/main/resources/ruby-client/partial_model_generic.mustache index d5ef9e8ab420..05e8b0bf0c78 100644 --- a/modules/openapi-generator/src/main/resources/ruby-client/partial_model_generic.mustache +++ b/modules/openapi-generator/src/main/resources/ruby-client/partial_model_generic.mustache @@ -42,17 +42,17 @@ } end - # Returns attribute mapping this model knows about{{#parent}}, including the ones defined in its parent(s){{/parent}} + # Returns attribute mapping this model knows about{{#parentModel}}, including the ones defined in its parent(s){{/parentModel}} def self.acceptable_attribute_map - {{^parent}} + {{^parentModel}} attribute_map - {{/parent}} - {{#parent}} + {{/parentModel}} + {{#parentModel}} superclass.acceptable_attribute_map.merge(attribute_map) - {{/parent}} + {{/parentModel}} end - # Returns all the JSON keys this model knows about{{#parent}}, including the ones defined in its parent(s){{/parent}} + # Returns all the JSON keys this model knows about{{#parentModel}}, including the ones defined in its parent(s){{/parentModel}} def self.acceptable_attributes acceptable_attribute_map.values end @@ -77,6 +77,26 @@ ]) end + # Returns attribute type mapping{{#parentModel}}, including the ones defined in its parent(s){{/parentModel}} + def self.acceptable_openapi_types + {{^parentModel}} + openapi_types + {{/parentModel}} + {{#parentModel}} + superclass.acceptable_openapi_types.merge(openapi_types) + {{/parentModel}} + end + + # Returns the nullable attributes{{#parentModel}}, including the ones defined in its parent(s) that it does not redeclare{{/parentModel}} + def self.acceptable_openapi_nullable + {{^parentModel}} + openapi_nullable + {{/parentModel}} + {{#parentModel}} + (superclass.acceptable_openapi_nullable - attribute_map.keys) | openapi_nullable + {{/parentModel}} + end + {{#anyOf}} {{#-first}} # List of class defined in anyOf (OpenAPI v3) @@ -127,11 +147,11 @@ end h[k.to_sym] = v } - {{#parent}} + {{#parentModel}} # call parent's initialize super(attributes) - {{/parent}} + {{/parentModel}} {{#vars}} if attributes.key?(:'{{{name}}}') 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 f67bb6720788..a9914a9b8acf 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 @@ -26,12 +26,14 @@ import org.openapitools.codegen.model.ModelMap; import org.openapitools.codegen.model.OperationMap; import org.openapitools.codegen.model.OperationsMap; +import org.openapitools.codegen.utils.ModelUtils; import org.testng.Assert; import org.testng.annotations.Test; import java.io.File; import java.nio.charset.StandardCharsets; import java.nio.file.Files; +import java.nio.file.Path; import java.util.*; import java.util.stream.Collectors; @@ -799,4 +801,61 @@ 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 and to_hash include 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: types and nullability merge along the ancestry, the nearest declaration wins + Path lizard = new File(output, "lib/openapi_client/models/lizard.rb").toPath(); + TestUtils.assertFileContains(lizard, + "superclass.acceptable_openapi_types.merge(openapi_types)", + "(superclass.acceptable_openapi_nullable - attribute_map.keys) | openapi_nullable"); + // build_from_hash and to_hash use the merged maps + TestUtils.assertFileContains(lizard, + "acceptable_openapi_types.each_pair do |key, type|", + "self.class.acceptable_attribute_map.each_pair do |attr, param|", + "is_nullable = self.class.acceptable_openapi_nullable.include?(attr)"); + // the super call that built and discarded a second instance is gone + TestUtils.assertFileNotContains(lizard, "super(attributes)\n attributes = attributes.transform_keys(&:to_sym)"); + // a root model has no parent to merge + TestUtils.assertFileNotContains(new File(output, "lib/openapi_client/models/pet.rb").toPath(), "superclass.acceptable_openapi_types"); + // a generated parent still receives the initializer call + TestUtils.assertFileContains(lizard, "# call parent's initialize\n super(attributes)"); + } + + @Test(description = "a model whose superclass is not a generated model (an alias to an array) does not delegate to it") + public void testAliasModelDoesNotDelegateToItsBuiltInSuperclass() throws Exception { + final File output = Files.createTempDirectory("test").toFile(); + output.deleteOnExit(); + + final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/features/generate-alias-as-model.yaml"); + CodegenConfig codegenConfig = new RubyClientCodegen(); + codegenConfig.setOutputDir(output.getAbsolutePath()); + + ClientOptInput clientOptInput = new ClientOptInput().openAPI(openAPI).config(codegenConfig); + ModelUtils.setGenerateAliasAsModel(true); + try { + new DefaultGenerator().opts(clientOptInput).generate(); + } finally { + ModelUtils.setGenerateAliasAsModel(false); + } + + // ArrayAlias < Array: Array has none of the helpers, so each one is its own base case + Path arrayAlias = new File(output, "lib/openapi_client/models/array_alias.rb").toPath(); + TestUtils.assertFileContains(arrayAlias, + "class ArrayAlias < Array", + "def self.acceptable_attribute_map\n attribute_map\n end", + "def self.acceptable_openapi_types\n openapi_types\n end", + "def self.acceptable_openapi_nullable\n openapi_nullable\n end"); + TestUtils.assertFileNotContains(arrayAlias, "superclass.", "super(attributes)"); + } } 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..9f03a6daeca5 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 @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -118,18 +128,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +151,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..a9e3fae3e988 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 @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -118,18 +128,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +151,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..0575446c351f 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 @@ -80,6 +80,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping, including the ones defined in its parent(s) + def self.acceptable_openapi_types + superclass.acceptable_openapi_types.merge(openapi_types) + end + + # Returns the nullable attributes, including the ones defined in its parent(s) that it does not redeclare + def self.acceptable_openapi_nullable + (superclass.acceptable_openapi_nullable - attribute_map.keys) | openapi_nullable + end + # List of class defined in allOf (OpenAPI v3) def self.openapi_all_of [ @@ -161,20 +171,21 @@ 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) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,12 @@ 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| + hash = {} + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..451707d0eeb9 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 @@ -101,6 +101,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -212,18 +222,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -233,10 +245,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..20ace6a8baad 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 @@ -55,6 +55,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -155,18 +165,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -176,10 +188,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..c756e2ce6b41 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 @@ -90,6 +90,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -227,18 +237,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -248,10 +260,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..1e1b31de201b 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 @@ -74,6 +74,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -143,18 +153,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +176,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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/tag.rb b/samples/client/echo_api/ruby-faraday/lib/openapi_client/models/tag.rb index d087eafa1516..e0d61143d2f0 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 @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -118,18 +128,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +151,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..6b33437e3258 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 @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -109,18 +119,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +142,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..04a9bd521165 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 @@ -59,6 +59,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # List of class defined in allOf (OpenAPI v3) def self.openapi_all_of [ @@ -144,18 +154,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -165,10 +177,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..3c67a8e0f2a9 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 @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -111,18 +121,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -132,10 +144,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..9f03a6daeca5 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 @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -118,18 +128,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +151,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..a9e3fae3e988 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 @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -118,18 +128,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +151,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..0575446c351f 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 @@ -80,6 +80,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping, including the ones defined in its parent(s) + def self.acceptable_openapi_types + superclass.acceptable_openapi_types.merge(openapi_types) + end + + # Returns the nullable attributes, including the ones defined in its parent(s) that it does not redeclare + def self.acceptable_openapi_nullable + (superclass.acceptable_openapi_nullable - attribute_map.keys) | openapi_nullable + end + # List of class defined in allOf (OpenAPI v3) def self.openapi_all_of [ @@ -161,20 +171,21 @@ 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) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,12 @@ 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| + hash = {} + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..451707d0eeb9 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 @@ -101,6 +101,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -212,18 +222,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -233,10 +245,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..20ace6a8baad 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 @@ -55,6 +55,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -155,18 +165,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -176,10 +188,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..c756e2ce6b41 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 @@ -90,6 +90,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -227,18 +237,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -248,10 +260,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..1e1b31de201b 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 @@ -74,6 +74,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -143,18 +153,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +176,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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/tag.rb b/samples/client/echo_api/ruby-httpx/lib/openapi_client/models/tag.rb index d087eafa1516..e0d61143d2f0 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 @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -118,18 +128,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +151,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..6b33437e3258 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 @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -109,18 +119,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +142,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..04a9bd521165 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 @@ -59,6 +59,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # List of class defined in allOf (OpenAPI v3) def self.openapi_all_of [ @@ -144,18 +154,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -165,10 +177,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..3c67a8e0f2a9 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 @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -111,18 +121,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -132,10 +144,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..9f03a6daeca5 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 @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -118,18 +128,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +151,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..a9e3fae3e988 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 @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -118,18 +128,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +151,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..0575446c351f 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 @@ -80,6 +80,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping, including the ones defined in its parent(s) + def self.acceptable_openapi_types + superclass.acceptable_openapi_types.merge(openapi_types) + end + + # Returns the nullable attributes, including the ones defined in its parent(s) that it does not redeclare + def self.acceptable_openapi_nullable + (superclass.acceptable_openapi_nullable - attribute_map.keys) | openapi_nullable + end + # List of class defined in allOf (OpenAPI v3) def self.openapi_all_of [ @@ -161,20 +171,21 @@ 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) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,12 @@ 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| + hash = {} + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..451707d0eeb9 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 @@ -101,6 +101,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -212,18 +222,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -233,10 +245,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..20ace6a8baad 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 @@ -55,6 +55,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -155,18 +165,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -176,10 +188,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..c756e2ce6b41 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 @@ -90,6 +90,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -227,18 +237,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -248,10 +260,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..1e1b31de201b 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 @@ -74,6 +74,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -143,18 +153,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +176,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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/tag.rb b/samples/client/echo_api/ruby-typhoeus/lib/openapi_client/models/tag.rb index d087eafa1516..e0d61143d2f0 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 @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -118,18 +128,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +151,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..6b33437e3258 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 @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -109,18 +119,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +142,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..04a9bd521165 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 @@ -59,6 +59,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # List of class defined in allOf (OpenAPI v3) def self.openapi_all_of [ @@ -144,18 +154,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -165,10 +177,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..3c67a8e0f2a9 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 @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -111,18 +121,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -132,10 +144,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..a240cadf547e 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 @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -122,18 +132,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -143,10 +155,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..9977e0212627 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 @@ -73,6 +73,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -140,18 +150,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -161,10 +173,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..b58dbb506d4e 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/animal.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/animal.rb @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # discriminator's property name in OpenAPI v3 def self.openapi_discriminator_name :'class_name' @@ -142,18 +152,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +175,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..6b8e2bf4005f 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 @@ -55,6 +55,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -127,18 +137,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -148,10 +160,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..40b968094257 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 @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -111,18 +121,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -132,10 +144,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..6b9bc3627785 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 @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -111,18 +121,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -132,10 +144,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..fc5e9d297766 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 @@ -55,6 +55,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -161,18 +171,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -182,10 +194,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..9031ca3f7d51 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/capitalization.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/capitalization.rb @@ -68,6 +68,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -155,18 +165,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -176,10 +188,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..a1f3de5272b6 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/cat.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/cat.rb @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping, including the ones defined in its parent(s) + def self.acceptable_openapi_types + superclass.acceptable_openapi_types.merge(openapi_types) + end + + # Returns the nullable attributes, including the ones defined in its parent(s) that it does not redeclare + def self.acceptable_openapi_nullable + (superclass.acceptable_openapi_nullable - attribute_map.keys) | openapi_nullable + end + # List of class defined in allOf (OpenAPI v3) def self.openapi_all_of [ @@ -118,20 +128,21 @@ 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) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,12 @@ 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| + hash = {} + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..a5af1c3f9acc 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/category.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/category.rb @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -135,18 +145,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +168,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..1e4671c79c42 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 @@ -69,6 +69,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping, including the ones defined in its parent(s) + def self.acceptable_openapi_types + superclass.acceptable_openapi_types.merge(openapi_types) + end + + # Returns the nullable attributes, including the ones defined in its parent(s) that it does not redeclare + def self.acceptable_openapi_nullable + (superclass.acceptable_openapi_nullable - attribute_map.keys) | openapi_nullable + end + # List of class defined in allOf (OpenAPI v3) def self.openapi_all_of [ @@ -140,20 +150,21 @@ 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) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,12 @@ 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| + hash = {} + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..4e611ee27f3e 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 @@ -48,6 +48,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -110,18 +120,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +143,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..f775d0f1d542 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/client.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/client.rb @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -109,18 +119,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +142,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..bdc86013c848 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 @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -109,18 +119,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +142,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..2e8f95136f9a 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/dog.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/dog.rb @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping, including the ones defined in its parent(s) + def self.acceptable_openapi_types + superclass.acceptable_openapi_types.merge(openapi_types) + end + + # Returns the nullable attributes, including the ones defined in its parent(s) that it does not redeclare + def self.acceptable_openapi_nullable + (superclass.acceptable_openapi_nullable - attribute_map.keys) | openapi_nullable + end + # List of class defined in allOf (OpenAPI v3) def self.openapi_all_of [ @@ -118,20 +128,21 @@ 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) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,12 @@ 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| + hash = {} + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..8058a6ac60bb 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 @@ -73,6 +73,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -154,18 +164,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +187,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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_test.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/enum_test.rb index 5159875cb89b..3b3905c138a3 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 @@ -98,6 +98,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -254,18 +264,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -275,10 +287,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..b7be6af6d90e 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 @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -120,18 +130,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -141,10 +153,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..4fac9978fcaa 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/file.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/file.rb @@ -49,6 +49,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -111,18 +121,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -132,10 +144,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..074c235ebe17 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 @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -120,18 +130,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -141,10 +153,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..811726434b54 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/foo.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/foo.rb @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -111,18 +121,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -132,10 +144,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..61d044ad8f26 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 @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -109,18 +119,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +142,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..6760f6807c59 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 @@ -109,6 +109,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -525,18 +535,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -546,10 +558,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..604a3da147bd 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 @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -118,18 +128,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +151,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..0792044db072 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 @@ -49,6 +49,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -111,18 +121,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -132,10 +144,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..ecc8eb8aafc5 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/list.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/list.rb @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -109,18 +119,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +142,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..eca01649a52a 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 @@ -81,6 +81,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -166,18 +176,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -187,10 +199,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..060c8488652f 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 @@ -55,6 +55,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -129,18 +139,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -150,10 +162,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..2ea5253eb3d4 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 @@ -52,6 +52,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -119,18 +129,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +152,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..c2b6ac11c2e9 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 @@ -48,6 +48,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -110,18 +120,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +143,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..c989368e6597 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/name.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/name.rb @@ -60,6 +60,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -154,18 +164,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +187,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..de5510060a65 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 @@ -101,6 +101,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -230,18 +240,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -251,10 +263,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..b4fb53e2c3d3 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 @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -109,18 +119,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +142,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..3819fef7a58b 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 @@ -59,6 +59,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -138,18 +148,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -159,10 +171,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..8cebfcefa34e 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/order.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/order.rb @@ -90,6 +90,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -191,18 +201,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -212,10 +224,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..afa9203ebde9 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 @@ -55,6 +55,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -127,18 +137,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -148,10 +160,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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_object_with_enum_property.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/outer_object_with_enum_property.rb index 8ffad20f8d89..1fd79229d4f6 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 @@ -69,6 +69,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -148,18 +158,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -169,10 +181,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..5af979aaa167 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 @@ -74,6 +74,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # discriminator's property name in OpenAPI v3 def self.openapi_discriminator_name :'type' @@ -158,18 +168,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -179,10 +191,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..5a86112a15cf 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/pet.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/pet.rb @@ -90,6 +90,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -227,18 +237,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -248,10 +260,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..d008b4369a91 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 @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -118,18 +128,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +151,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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/special_model_name.rb b/samples/client/petstore/ruby-autoload/lib/petstore/models/special_model_name.rb index 9569fbfd13dd..b6d4135991be 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 @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -109,18 +119,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +142,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..22589f4e58b3 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/tag.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/tag.rb @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -118,18 +128,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +151,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..9e52e64e286b 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 @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -109,18 +119,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +142,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..4b67db8214e2 100644 --- a/samples/client/petstore/ruby-autoload/lib/petstore/models/user.rb +++ b/samples/client/petstore/ruby-autoload/lib/petstore/models/user.rb @@ -76,6 +76,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -173,18 +183,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -194,10 +206,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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/additional_properties_class.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/additional_properties_class.rb index 9b823593d156..a240cadf547e 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 @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -122,18 +132,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -143,10 +155,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..9977e0212627 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 @@ -73,6 +73,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -140,18 +150,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -161,10 +173,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..b58dbb506d4e 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/animal.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/animal.rb @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # discriminator's property name in OpenAPI v3 def self.openapi_discriminator_name :'class_name' @@ -142,18 +152,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +175,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..6b8e2bf4005f 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 @@ -55,6 +55,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -127,18 +137,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -148,10 +160,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..40b968094257 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 @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -111,18 +121,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -132,10 +144,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..6b9bc3627785 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 @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -111,18 +121,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -132,10 +144,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..fc5e9d297766 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 @@ -55,6 +55,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -161,18 +171,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -182,10 +194,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..9031ca3f7d51 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/capitalization.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/capitalization.rb @@ -68,6 +68,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -155,18 +165,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -176,10 +188,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..a1f3de5272b6 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/cat.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/cat.rb @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping, including the ones defined in its parent(s) + def self.acceptable_openapi_types + superclass.acceptable_openapi_types.merge(openapi_types) + end + + # Returns the nullable attributes, including the ones defined in its parent(s) that it does not redeclare + def self.acceptable_openapi_nullable + (superclass.acceptable_openapi_nullable - attribute_map.keys) | openapi_nullable + end + # List of class defined in allOf (OpenAPI v3) def self.openapi_all_of [ @@ -118,20 +128,21 @@ 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) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,12 @@ 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| + hash = {} + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..a5af1c3f9acc 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/category.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/category.rb @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -135,18 +145,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +168,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..4e611ee27f3e 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 @@ -48,6 +48,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -110,18 +120,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +143,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..f775d0f1d542 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/client.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/client.rb @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -109,18 +119,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +142,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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/deprecated_object.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/deprecated_object.rb index 9f1ee6720cab..bdc86013c848 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 @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -109,18 +119,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +142,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..2e8f95136f9a 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/dog.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/dog.rb @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping, including the ones defined in its parent(s) + def self.acceptable_openapi_types + superclass.acceptable_openapi_types.merge(openapi_types) + end + + # Returns the nullable attributes, including the ones defined in its parent(s) that it does not redeclare + def self.acceptable_openapi_nullable + (superclass.acceptable_openapi_nullable - attribute_map.keys) | openapi_nullable + end + # List of class defined in allOf (OpenAPI v3) def self.openapi_all_of [ @@ -118,20 +128,21 @@ 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) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,12 @@ 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| + hash = {} + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..8058a6ac60bb 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 @@ -73,6 +73,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -154,18 +164,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +187,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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_test.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/enum_test.rb index 5159875cb89b..3b3905c138a3 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 @@ -98,6 +98,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -254,18 +264,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -275,10 +287,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..b7be6af6d90e 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 @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -120,18 +130,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -141,10 +153,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..4fac9978fcaa 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/file.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/file.rb @@ -49,6 +49,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -111,18 +121,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -132,10 +144,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..074c235ebe17 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 @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -120,18 +130,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -141,10 +153,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..811726434b54 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/foo.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/foo.rb @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -111,18 +121,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -132,10 +144,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..61d044ad8f26 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 @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -109,18 +119,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +142,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..6760f6807c59 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 @@ -109,6 +109,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -525,18 +535,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -546,10 +558,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..604a3da147bd 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 @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -118,18 +128,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +151,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..0792044db072 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 @@ -49,6 +49,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -111,18 +121,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -132,10 +144,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..ecc8eb8aafc5 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/list.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/list.rb @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -109,18 +119,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +142,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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/map_test.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/map_test.rb index 78c5472f24ae..eca01649a52a 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 @@ -81,6 +81,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -166,18 +176,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -187,10 +199,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..060c8488652f 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 @@ -55,6 +55,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -129,18 +139,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -150,10 +162,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..2ea5253eb3d4 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 @@ -52,6 +52,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -119,18 +129,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +152,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..c2b6ac11c2e9 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 @@ -48,6 +48,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -110,18 +120,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +143,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..c989368e6597 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/name.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/name.rb @@ -60,6 +60,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -154,18 +164,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +187,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..de5510060a65 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 @@ -101,6 +101,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -230,18 +240,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -251,10 +263,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..b4fb53e2c3d3 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 @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -109,18 +119,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +142,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..3819fef7a58b 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 @@ -59,6 +59,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -138,18 +148,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -159,10 +171,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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/order.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/order.rb index f7e7b4eb9117..8cebfcefa34e 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/order.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/order.rb @@ -90,6 +90,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -191,18 +201,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -212,10 +224,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..afa9203ebde9 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 @@ -55,6 +55,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -127,18 +137,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -148,10 +160,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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_object_with_enum_property.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/outer_object_with_enum_property.rb index 8ffad20f8d89..1fd79229d4f6 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 @@ -69,6 +69,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -148,18 +158,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -169,10 +181,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..5a86112a15cf 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/pet.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/pet.rb @@ -90,6 +90,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -227,18 +237,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -248,10 +260,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..82c1d3be0d08 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 @@ -59,6 +59,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -136,18 +146,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -157,10 +169,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..d008b4369a91 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 @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -118,18 +128,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +151,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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/special_model_name.rb b/samples/client/petstore/ruby-faraday/lib/petstore/models/special_model_name.rb index 9569fbfd13dd..b6d4135991be 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 @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -109,18 +119,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +142,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..22589f4e58b3 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/tag.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/tag.rb @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -118,18 +128,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +151,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..9e52e64e286b 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 @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -109,18 +119,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +142,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..4b67db8214e2 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/user.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/user.rb @@ -76,6 +76,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -173,18 +183,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -194,10 +206,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..f29de72ecb1a 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/whale.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/whale.rb @@ -55,6 +55,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -144,18 +154,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -165,10 +177,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..79771e498151 100644 --- a/samples/client/petstore/ruby-faraday/lib/petstore/models/zebra.rb +++ b/samples/client/petstore/ruby-faraday/lib/petstore/models/zebra.rb @@ -73,6 +73,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -169,18 +179,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -190,10 +202,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..bc0ed63000b4 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,34 @@ 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 and to_hash include the parent attributes' 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) + expect(cat.to_hash).to eq({ className: 'Cat', color: 'black', declawed: true }) + end + + # passes on master too: guards that a subclass narrowing attribute_map is not handed its parent's attributes + it 'a subclass that narrows attribute_map is only handed the attributes it accepts' do + narrowed = Class.new(Petstore::Animal) do + def self.attribute_map + { :class_name => :className } + end + + def self.openapi_types + { :class_name => :'String' } + end + end + + obj = narrowed.build_from_hash({ 'className' => 'Cat', 'color' => 'black' }) + + expect(obj.class_name).to eq('Cat') + expect(obj.to_hash).to eq({ className: 'Cat' }) + 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..a240cadf547e 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 @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -122,18 +132,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -143,10 +155,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..9977e0212627 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 @@ -73,6 +73,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -140,18 +150,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -161,10 +173,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..b58dbb506d4e 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/animal.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/animal.rb @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # discriminator's property name in OpenAPI v3 def self.openapi_discriminator_name :'class_name' @@ -142,18 +152,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +175,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..6b8e2bf4005f 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 @@ -55,6 +55,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -127,18 +137,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -148,10 +160,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..40b968094257 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 @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -111,18 +121,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -132,10 +144,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..6b9bc3627785 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 @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -111,18 +121,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -132,10 +144,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..fc5e9d297766 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 @@ -55,6 +55,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -161,18 +171,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -182,10 +194,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..9031ca3f7d51 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/capitalization.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/capitalization.rb @@ -68,6 +68,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -155,18 +165,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -176,10 +188,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..a1f3de5272b6 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/cat.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/cat.rb @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping, including the ones defined in its parent(s) + def self.acceptable_openapi_types + superclass.acceptable_openapi_types.merge(openapi_types) + end + + # Returns the nullable attributes, including the ones defined in its parent(s) that it does not redeclare + def self.acceptable_openapi_nullable + (superclass.acceptable_openapi_nullable - attribute_map.keys) | openapi_nullable + end + # List of class defined in allOf (OpenAPI v3) def self.openapi_all_of [ @@ -118,20 +128,21 @@ 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) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,12 @@ 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| + hash = {} + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..a5af1c3f9acc 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/category.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/category.rb @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -135,18 +145,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +168,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..4e611ee27f3e 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 @@ -48,6 +48,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -110,18 +120,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +143,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..f775d0f1d542 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/client.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/client.rb @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -109,18 +119,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +142,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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/deprecated_object.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/deprecated_object.rb index 9f1ee6720cab..bdc86013c848 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 @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -109,18 +119,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +142,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..2e8f95136f9a 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/dog.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/dog.rb @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping, including the ones defined in its parent(s) + def self.acceptable_openapi_types + superclass.acceptable_openapi_types.merge(openapi_types) + end + + # Returns the nullable attributes, including the ones defined in its parent(s) that it does not redeclare + def self.acceptable_openapi_nullable + (superclass.acceptable_openapi_nullable - attribute_map.keys) | openapi_nullable + end + # List of class defined in allOf (OpenAPI v3) def self.openapi_all_of [ @@ -118,20 +128,21 @@ 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) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,12 @@ 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| + hash = {} + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..8058a6ac60bb 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 @@ -73,6 +73,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -154,18 +164,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +187,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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_test.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/enum_test.rb index 5159875cb89b..3b3905c138a3 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 @@ -98,6 +98,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -254,18 +264,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -275,10 +287,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..b7be6af6d90e 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 @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -120,18 +130,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -141,10 +153,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..4fac9978fcaa 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/file.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/file.rb @@ -49,6 +49,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -111,18 +121,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -132,10 +144,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..074c235ebe17 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 @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -120,18 +130,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -141,10 +153,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..811726434b54 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/foo.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/foo.rb @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -111,18 +121,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -132,10 +144,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..61d044ad8f26 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 @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -109,18 +119,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +142,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..6760f6807c59 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 @@ -109,6 +109,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -525,18 +535,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -546,10 +558,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..604a3da147bd 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 @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -118,18 +128,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +151,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..0792044db072 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 @@ -49,6 +49,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -111,18 +121,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -132,10 +144,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..ecc8eb8aafc5 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/list.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/list.rb @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -109,18 +119,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +142,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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/map_test.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/map_test.rb index 78c5472f24ae..eca01649a52a 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 @@ -81,6 +81,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -166,18 +176,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -187,10 +199,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..060c8488652f 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 @@ -55,6 +55,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -129,18 +139,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -150,10 +162,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..2ea5253eb3d4 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 @@ -52,6 +52,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -119,18 +129,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +152,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..c2b6ac11c2e9 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 @@ -48,6 +48,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -110,18 +120,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +143,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..c989368e6597 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/name.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/name.rb @@ -60,6 +60,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -154,18 +164,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +187,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..de5510060a65 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 @@ -101,6 +101,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -230,18 +240,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -251,10 +263,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..b4fb53e2c3d3 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 @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -109,18 +119,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +142,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..3819fef7a58b 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 @@ -59,6 +59,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -138,18 +148,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -159,10 +171,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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/order.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/order.rb index f7e7b4eb9117..8cebfcefa34e 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/order.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/order.rb @@ -90,6 +90,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -191,18 +201,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -212,10 +224,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..afa9203ebde9 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 @@ -55,6 +55,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -127,18 +137,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -148,10 +160,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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_object_with_enum_property.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/outer_object_with_enum_property.rb index 8ffad20f8d89..1fd79229d4f6 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 @@ -69,6 +69,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -148,18 +158,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -169,10 +181,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..5a86112a15cf 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/pet.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/pet.rb @@ -90,6 +90,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -227,18 +237,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -248,10 +260,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..82c1d3be0d08 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 @@ -59,6 +59,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -136,18 +146,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -157,10 +169,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..d008b4369a91 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 @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -118,18 +128,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +151,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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/special_model_name.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/special_model_name.rb index 9569fbfd13dd..b6d4135991be 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 @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -109,18 +119,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +142,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..22589f4e58b3 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/tag.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/tag.rb @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -118,18 +128,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +151,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..9e52e64e286b 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 @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -109,18 +119,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +142,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..4b67db8214e2 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/user.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/user.rb @@ -76,6 +76,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -173,18 +183,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -194,10 +206,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..f29de72ecb1a 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/whale.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/whale.rb @@ -55,6 +55,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -144,18 +154,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -165,10 +177,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..79771e498151 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/zebra.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/zebra.rb @@ -73,6 +73,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -169,18 +179,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -190,10 +202,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..bc0ed63000b4 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,34 @@ 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 and to_hash include the parent attributes' 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) + expect(cat.to_hash).to eq({ className: 'Cat', color: 'black', declawed: true }) + end + + # passes on master too: guards that a subclass narrowing attribute_map is not handed its parent's attributes + it 'a subclass that narrows attribute_map is only handed the attributes it accepts' do + narrowed = Class.new(Petstore::Animal) do + def self.attribute_map + { :class_name => :className } + end + + def self.openapi_types + { :class_name => :'String' } + end + end + + obj = narrowed.build_from_hash({ 'className' => 'Cat', 'color' => 'black' }) + + expect(obj.class_name).to eq('Cat') + expect(obj.to_hash).to eq({ className: 'Cat' }) + 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..a240cadf547e 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 @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -122,18 +132,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -143,10 +155,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..9977e0212627 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 @@ -73,6 +73,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -140,18 +150,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -161,10 +173,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..b58dbb506d4e 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/animal.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/animal.rb @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # discriminator's property name in OpenAPI v3 def self.openapi_discriminator_name :'class_name' @@ -142,18 +152,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +175,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..6b8e2bf4005f 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/api_response.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/api_response.rb @@ -55,6 +55,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -127,18 +137,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -148,10 +160,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..40b968094257 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 @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -111,18 +121,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -132,10 +144,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..6b9bc3627785 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 @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -111,18 +121,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -132,10 +144,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..fc5e9d297766 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/array_test.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/array_test.rb @@ -55,6 +55,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -161,18 +171,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -182,10 +194,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..9031ca3f7d51 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/capitalization.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/capitalization.rb @@ -68,6 +68,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -155,18 +165,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -176,10 +188,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..a1f3de5272b6 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/cat.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/cat.rb @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping, including the ones defined in its parent(s) + def self.acceptable_openapi_types + superclass.acceptable_openapi_types.merge(openapi_types) + end + + # Returns the nullable attributes, including the ones defined in its parent(s) that it does not redeclare + def self.acceptable_openapi_nullable + (superclass.acceptable_openapi_nullable - attribute_map.keys) | openapi_nullable + end + # List of class defined in allOf (OpenAPI v3) def self.openapi_all_of [ @@ -118,20 +128,21 @@ 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) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,12 @@ 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| + hash = {} + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..a5af1c3f9acc 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/category.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/category.rb @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -135,18 +145,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +168,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..4e611ee27f3e 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/class_model.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/class_model.rb @@ -48,6 +48,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -110,18 +120,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +143,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..f775d0f1d542 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/client.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/client.rb @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -109,18 +119,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +142,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end 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..bdc86013c848 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/deprecated_object.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/deprecated_object.rb @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -109,18 +119,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +142,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..2e8f95136f9a 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/dog.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/dog.rb @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping, including the ones defined in its parent(s) + def self.acceptable_openapi_types + superclass.acceptable_openapi_types.merge(openapi_types) + end + + # Returns the nullable attributes, including the ones defined in its parent(s) that it does not redeclare + def self.acceptable_openapi_nullable + (superclass.acceptable_openapi_nullable - attribute_map.keys) | openapi_nullable + end + # List of class defined in allOf (OpenAPI v3) def self.openapi_all_of [ @@ -118,20 +128,21 @@ 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) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,12 @@ 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| + hash = {} + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..8058a6ac60bb 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/enum_arrays.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/enum_arrays.rb @@ -73,6 +73,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -154,18 +164,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +187,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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_test.rb b/samples/client/petstore/ruby/lib/petstore/models/enum_test.rb index 5159875cb89b..3b3905c138a3 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/enum_test.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/enum_test.rb @@ -98,6 +98,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -254,18 +264,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -275,10 +287,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..b7be6af6d90e 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 @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -120,18 +130,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -141,10 +153,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..4fac9978fcaa 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/file.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/file.rb @@ -49,6 +49,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -111,18 +121,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -132,10 +144,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..074c235ebe17 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 @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -120,18 +130,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -141,10 +153,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..811726434b54 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/foo.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/foo.rb @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -111,18 +121,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -132,10 +144,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..61d044ad8f26 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 @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -109,18 +119,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +142,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..6760f6807c59 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/format_test.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/format_test.rb @@ -109,6 +109,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -525,18 +535,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -546,10 +558,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..604a3da147bd 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 @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -118,18 +128,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +151,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..0792044db072 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 @@ -49,6 +49,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -111,18 +121,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -132,10 +144,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..ecc8eb8aafc5 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/list.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/list.rb @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -109,18 +119,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +142,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end 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..eca01649a52a 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/map_test.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/map_test.rb @@ -81,6 +81,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -166,18 +176,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -187,10 +199,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..060c8488652f 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 @@ -55,6 +55,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -129,18 +139,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -150,10 +162,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..2ea5253eb3d4 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/model200_response.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/model200_response.rb @@ -52,6 +52,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -119,18 +129,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +152,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..c2b6ac11c2e9 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/model_return.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/model_return.rb @@ -48,6 +48,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -110,18 +120,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +143,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..c989368e6597 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/name.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/name.rb @@ -60,6 +60,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -154,18 +164,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +187,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..de5510060a65 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/nullable_class.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/nullable_class.rb @@ -101,6 +101,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -230,18 +240,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -251,10 +263,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..b4fb53e2c3d3 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/number_only.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/number_only.rb @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -109,18 +119,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +142,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..3819fef7a58b 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 @@ -59,6 +59,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -138,18 +148,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -159,10 +171,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end diff --git a/samples/client/petstore/ruby/lib/petstore/models/order.rb b/samples/client/petstore/ruby/lib/petstore/models/order.rb index f7e7b4eb9117..8cebfcefa34e 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/order.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/order.rb @@ -90,6 +90,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -191,18 +201,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -212,10 +224,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..afa9203ebde9 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/outer_composite.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/outer_composite.rb @@ -55,6 +55,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -127,18 +137,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -148,10 +160,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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_object_with_enum_property.rb b/samples/client/petstore/ruby/lib/petstore/models/outer_object_with_enum_property.rb index 8ffad20f8d89..1fd79229d4f6 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 @@ -69,6 +69,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -148,18 +158,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -169,10 +181,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..5a86112a15cf 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/pet.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/pet.rb @@ -90,6 +90,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -227,18 +237,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -248,10 +260,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..ed1c46eeef88 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 @@ -59,6 +59,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -136,18 +146,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -157,10 +169,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..d008b4369a91 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 @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -118,18 +128,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +151,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end 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..b6d4135991be 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 @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -109,18 +119,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +142,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..22589f4e58b3 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/tag.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/tag.rb @@ -51,6 +51,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -118,18 +128,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +151,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..9e52e64e286b 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 @@ -47,6 +47,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -109,18 +119,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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,10 +142,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..4b67db8214e2 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/user.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/user.rb @@ -76,6 +76,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -173,18 +183,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -194,10 +206,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..f29de72ecb1a 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/whale.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/whale.rb @@ -55,6 +55,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -144,18 +154,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -165,10 +177,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..79771e498151 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/zebra.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/zebra.rb @@ -73,6 +73,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -169,18 +179,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -190,10 +202,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..bc0ed63000b4 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,34 @@ 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 and to_hash include the parent attributes' 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) + expect(cat.to_hash).to eq({ className: 'Cat', color: 'black', declawed: true }) + end + + # passes on master too: guards that a subclass narrowing attribute_map is not handed its parent's attributes + it 'a subclass that narrows attribute_map is only handed the attributes it accepts' do + narrowed = Class.new(Petstore::Animal) do + def self.attribute_map + { :class_name => :className } + end + + def self.openapi_types + { :class_name => :'String' } + end + end + + obj = narrowed.build_from_hash({ 'className' => 'Cat', 'color' => 'black' }) + + expect(obj.class_name).to eq('Cat') + expect(obj.to_hash).to eq({ className: 'Cat' }) + 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..857c8a4b76da 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 @@ -21,12 +21,12 @@ def self.attribute_map } end - # Returns attribute mapping this model knows about, including the ones defined in its parent(s) + # Returns attribute mapping this model knows about def self.acceptable_attribute_map - superclass.acceptable_attribute_map.merge(attribute_map) + attribute_map end - # Returns all the JSON keys this model knows about, including the ones defined in its parent(s) + # Returns all the JSON keys this model knows about def self.acceptable_attributes acceptable_attribute_map.values end @@ -43,6 +43,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -58,9 +68,6 @@ def initialize(attributes = {}) end h[k.to_sym] = v } - - # call parent's initialize - super(attributes) end # Show invalid properties with the reasons. Usually used together with valid? @@ -102,20 +109,21 @@ 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) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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 +132,12 @@ 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| + hash = {} + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_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..78aa109d56b0 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 @@ -43,6 +43,16 @@ def self.openapi_nullable ]) end + # Returns attribute type mapping + def self.acceptable_openapi_types + openapi_types + end + + # Returns the nullable attributes + def self.acceptable_openapi_nullable + openapi_nullable + end + # Initializes the object # @param [Hash] attributes Model attributes in the form of hash def initialize(attributes = {}) @@ -100,18 +110,20 @@ def hash def self.build_from_hash(attributes) return nil unless attributes.is_a?(Hash) attributes = attributes.transform_keys(&:to_sym) + # include attributes inherited from allOf parents (the nearest declaration wins) + map = acceptable_attribute_map transformed_hash = {} - openapi_types.each_pair do |key, type| - if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil? + acceptable_openapi_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) @@ -121,10 +133,11 @@ def self.build_from_hash(attributes) # @return [Hash] Returns the object in the form of hash def to_hash hash = {} - self.class.attribute_map.each_pair do |attr, param| + # include attributes inherited from allOf parents (the nearest declaration wins) + self.class.acceptable_attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? - is_nullable = self.class.openapi_nullable.include?(attr) + is_nullable = self.class.acceptable_openapi_nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end