Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Ruby client nullable #4391

Merged
merged 3 commits into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
hash = {{^parent}}{}{{/parent}}{{#parent}}super{{/parent}}
self.class.attribute_map.each_pair do |attr, param|
value = self.send(attr)
next if value.nil?
next if value.nil? && !self.class.openapi_nullable.include?(attr)
hash[param] = _to_hash(value)
end
hash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@
}
end

# List of attributes with nullable: true
def self.openapi_nullable
[
{{#vars}}
{{#isNullable}}
:'{{{name}}}'{{#hasMore}},{{/hasMore}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent seems to be too depth.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And what about defining it as a hash instead similar to self.openapi_types?

If an object contains a lot of nullable properties, using include? may result in performance issues.

Copy link
Contributor Author

@slemrmartin slemrmartin Nov 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see usage for key-value, but what about using Set instead of Array, it should have better performance for include?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the format

def self.openapi_nullable
      Set.new([
      ])
end

is it possible to define it in template in a way that empty set won't generate new line?

Copy link
Contributor

@autopp autopp Nov 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... it seems to be difficult because there is no way to directly enumerate nullable attributes in template.
@wing328 Do you have any ideas?

By the way, I don't like this format, but it's acceptable (Rubocop also allows this), so I think this PR can be merged.
Isn't it okay to make another PR for reformatting?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set is definitely better than array in this case.

About empty set, I think it's acceptable for day 1 requirement. We can always improve it later with another PR.

{{/isNullable}}
{{/vars}}
]
end

{{#anyOf}}
{{#-first}}
# List of class defined in anyOf (OpenAPI v3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ def self.openapi_types
}
end

# List of attributes with nullable: true
def self.openapi_nullable
[
]
end

# Initializes the object
# @param [Hash] attributes Model attributes in the form of hash
def initialize(attributes = {})
Expand Down Expand Up @@ -169,7 +175,7 @@ def to_hash
hash = {}
self.class.attribute_map.each_pair do |attr, param|
value = self.send(attr)
next if value.nil?
next if value.nil? && !self.class.openapi_nullable.include?(attr)
hash[param] = _to_hash(value)
end
hash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ def self.openapi_types
}
end

# List of attributes with nullable: true
def self.openapi_nullable
[
]
end

# Initializes the object
# @param [Hash] attributes Model attributes in the form of hash
def initialize(attributes = {})
Expand Down Expand Up @@ -169,7 +175,7 @@ def to_hash
hash = {}
self.class.attribute_map.each_pair do |attr, param|
value = self.send(attr)
next if value.nil?
next if value.nil? && !self.class.openapi_nullable.include?(attr)
hash[param] = _to_hash(value)
end
hash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ def self.openapi_types
}
end

# List of attributes with nullable: true
def self.openapi_nullable
[
]
end

# Initializes the object
# @param [Hash] attributes Model attributes in the form of hash
def initialize(attributes = {})
Expand Down Expand Up @@ -169,7 +175,7 @@ def to_hash
hash = {}
self.class.attribute_map.each_pair do |attr, param|
value = self.send(attr)
next if value.nil?
next if value.nil? && !self.class.openapi_nullable.include?(attr)
hash[param] = _to_hash(value)
end
hash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ def self.openapi_types
}
end

# List of attributes with nullable: true
def self.openapi_nullable
[
]
end

# Initializes the object
# @param [Hash] attributes Model attributes in the form of hash
def initialize(attributes = {})
Expand Down Expand Up @@ -275,7 +281,7 @@ def to_hash
hash = {}
self.class.attribute_map.each_pair do |attr, param|
value = self.send(attr)
next if value.nil?
next if value.nil? && !self.class.openapi_nullable.include?(attr)
hash[param] = _to_hash(value)
end
hash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ def self.openapi_types
}
end

# List of attributes with nullable: true
def self.openapi_nullable
[
]
end

# Initializes the object
# @param [Hash] attributes Model attributes in the form of hash
def initialize(attributes = {})
Expand Down Expand Up @@ -169,7 +175,7 @@ def to_hash
hash = {}
self.class.attribute_map.each_pair do |attr, param|
value = self.send(attr)
next if value.nil?
next if value.nil? && !self.class.openapi_nullable.include?(attr)
hash[param] = _to_hash(value)
end
hash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ def self.openapi_types
}
end

# List of attributes with nullable: true
def self.openapi_nullable
[
]
end

# Initializes the object
# @param [Hash] attributes Model attributes in the form of hash
def initialize(attributes = {})
Expand Down Expand Up @@ -169,7 +175,7 @@ def to_hash
hash = {}
self.class.attribute_map.each_pair do |attr, param|
value = self.send(attr)
next if value.nil?
next if value.nil? && !self.class.openapi_nullable.include?(attr)
hash[param] = _to_hash(value)
end
hash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ def self.openapi_types
}
end

# List of attributes with nullable: true
def self.openapi_nullable
[
]
end

# Initializes the object
# @param [Hash] attributes Model attributes in the form of hash
def initialize(attributes = {})
Expand Down Expand Up @@ -169,7 +175,7 @@ def to_hash
hash = {}
self.class.attribute_map.each_pair do |attr, param|
value = self.send(attr)
next if value.nil?
next if value.nil? && !self.class.openapi_nullable.include?(attr)
hash[param] = _to_hash(value)
end
hash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ def self.openapi_types
}
end

# List of attributes with nullable: true
def self.openapi_nullable
[
]
end

# Initializes the object
# @param [Hash] attributes Model attributes in the form of hash
def initialize(attributes = {})
Expand Down Expand Up @@ -169,7 +175,7 @@ def to_hash
hash = {}
self.class.attribute_map.each_pair do |attr, param|
value = self.send(attr)
next if value.nil?
next if value.nil? && !self.class.openapi_nullable.include?(attr)
hash[param] = _to_hash(value)
end
hash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ def self.openapi_types
}
end

# List of attributes with nullable: true
def self.openapi_nullable
[
]
end

# discriminator's property name in OpenAPI v3
def self.openapi_discriminator_name
:'class_name'
Expand Down Expand Up @@ -190,7 +196,7 @@ def to_hash
hash = {}
self.class.attribute_map.each_pair do |attr, param|
value = self.send(attr)
next if value.nil?
next if value.nil? && !self.class.openapi_nullable.include?(attr)
hash[param] = _to_hash(value)
end
hash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ def self.openapi_types
}
end

# List of attributes with nullable: true
def self.openapi_nullable
[
]
end

# Initializes the object
# @param [Hash] attributes Model attributes in the form of hash
def initialize(attributes = {})
Expand Down Expand Up @@ -187,7 +193,7 @@ def to_hash
hash = {}
self.class.attribute_map.each_pair do |attr, param|
value = self.send(attr)
next if value.nil?
next if value.nil? && !self.class.openapi_nullable.include?(attr)
hash[param] = _to_hash(value)
end
hash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ def self.openapi_types
}
end

# List of attributes with nullable: true
def self.openapi_nullable
[
]
end

# Initializes the object
# @param [Hash] attributes Model attributes in the form of hash
def initialize(attributes = {})
Expand Down Expand Up @@ -171,7 +177,7 @@ def to_hash
hash = {}
self.class.attribute_map.each_pair do |attr, param|
value = self.send(attr)
next if value.nil?
next if value.nil? && !self.class.openapi_nullable.include?(attr)
hash[param] = _to_hash(value)
end
hash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ def self.openapi_types
}
end

# List of attributes with nullable: true
def self.openapi_nullable
[
]
end

# Initializes the object
# @param [Hash] attributes Model attributes in the form of hash
def initialize(attributes = {})
Expand Down Expand Up @@ -171,7 +177,7 @@ def to_hash
hash = {}
self.class.attribute_map.each_pair do |attr, param|
value = self.send(attr)
next if value.nil?
next if value.nil? && !self.class.openapi_nullable.include?(attr)
hash[param] = _to_hash(value)
end
hash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ def self.openapi_types
}
end

# List of attributes with nullable: true
def self.openapi_nullable
[
]
end

# Initializes the object
# @param [Hash] attributes Model attributes in the form of hash
def initialize(attributes = {})
Expand Down Expand Up @@ -193,7 +199,7 @@ def to_hash
hash = {}
self.class.attribute_map.each_pair do |attr, param|
value = self.send(attr)
next if value.nil?
next if value.nil? && !self.class.openapi_nullable.include?(attr)
hash[param] = _to_hash(value)
end
hash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ def self.openapi_types
}
end

# List of attributes with nullable: true
def self.openapi_nullable
[
]
end

# Initializes the object
# @param [Hash] attributes Model attributes in the form of hash
def initialize(attributes = {})
Expand Down Expand Up @@ -215,7 +221,7 @@ def to_hash
hash = {}
self.class.attribute_map.each_pair do |attr, param|
value = self.send(attr)
next if value.nil?
next if value.nil? && !self.class.openapi_nullable.include?(attr)
hash[param] = _to_hash(value)
end
hash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ def self.openapi_types
}
end

# List of attributes with nullable: true
def self.openapi_nullable
[
]
end

# List of class defined in allOf (OpenAPI v3)
def self.openapi_all_of
[
Expand Down Expand Up @@ -181,7 +187,7 @@ def to_hash
hash = super
self.class.attribute_map.each_pair do |attr, param|
value = self.send(attr)
next if value.nil?
next if value.nil? && !self.class.openapi_nullable.include?(attr)
hash[param] = _to_hash(value)
end
hash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ def self.openapi_types
}
end

# List of attributes with nullable: true
def self.openapi_nullable
[
]
end

# Initializes the object
# @param [Hash] attributes Model attributes in the form of hash
def initialize(attributes = {})
Expand Down Expand Up @@ -169,7 +175,7 @@ def to_hash
hash = {}
self.class.attribute_map.each_pair do |attr, param|
value = self.send(attr)
next if value.nil?
next if value.nil? && !self.class.openapi_nullable.include?(attr)
hash[param] = _to_hash(value)
end
hash
Expand Down
Loading