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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions .generator/src/generator/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@ def format_data_with_schema_dict(
missing = required_properties - set(data.keys())
if missing:
raise ValueError(f"missing required properties: {missing}")
additionalProperties = set(data.keys()) - set(schema["properties"].keys())
if schema.get("additionalProperties") == False and additionalProperties:
raise ValueError(f"additional properties not allowed: {additionalProperties}")

for k, v in data.items():
if k not in schema["properties"]:
Expand Down
5 changes: 5 additions & 0 deletions .generator/src/generator/templates/model_base.j2
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ module {{ module_name }}::{{ version|upper }}
# @!visibility private
def build_from_hash(attributes)
return nil unless attributes.is_a?(Hash)
unless self.respond_to?(:additional_properties)
unless attributes.keys.all? { |key| self.class.openapi_types.key?(key) }
raise SchemaMismatchError, "Additional properties are not allowed"
end
end
self.class.openapi_types.each_pair do |key, type|
if attributes.key?(self.class.attribute_map[key]) && attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
self.send("#{key}=", nil)
Expand Down
11 changes: 6 additions & 5 deletions .generator/src/generator/templates/model_generic.j2
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
attr_accessor :{{ attr|attribute_name }}
{%- endif %}
{%- endfor %}
{%- if model.get("additionalProperties") %}
{%- set additionalProperties = model.get("additionalProperties") %}
{%- if additionalProperties is not false %}

attr_accessor :additional_properties
{%- endif %}
Expand Down Expand Up @@ -71,13 +72,13 @@
fail ArgumentError, "The input argument (attributes) must be a hash in `{{ module_name }}::{{ version|upper }}::{{ name }}` initialize method"
end
{# preserve blank line #}
{%- if model.get("additionalProperties") %}
{%- if additionalProperties is not false %}
self.additional_properties = {}
{%- endif %}
# check to see if the attribute exists and convert string to symbol for hash key
attributes = attributes.each_with_object({}) { |(k, v), h|
if (!self.class.attribute_map.key?(k.to_sym))
{%- if model.get("additionalProperties") %}
{%- if additionalProperties is not false %}
self.additional_properties[k.to_sym] = v
else
h[k.to_sym] = v
Expand Down Expand Up @@ -240,7 +241,7 @@
end
{%- endif %}
{%- endfor %}
{%- if model.get("additionalProperties") %}
{%- if additionalProperties is not false %}

# Returns the object in the form of hash, with additionalProperties support.
# @return [Hash] Returns the object in the form of hash
Expand Down Expand Up @@ -272,7 +273,7 @@
{%- for attr in model.properties %}
{{ attr|attribute_name }} == o.{{ attr|attribute_name }}{% if not loop.last or model.get("additionalProperties") %} &&{% endif %}
{%- endfor %}
{%- if model.get("additionalProperties") %}
{%- if additionalProperties is not false %}
additional_properties == o.additional_properties
{%- endif %}
end
Expand Down
5 changes: 5 additions & 0 deletions lib/datadog_api_client/v1/model_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ def eql?(o)
# @!visibility private
def build_from_hash(attributes)
return nil unless attributes.is_a?(Hash)
unless self.respond_to?(:additional_properties)
unless attributes.keys.all? { |key| self.class.openapi_types.key?(key) }
raise SchemaMismatchError, "Additional properties are not allowed"
end
end
self.class.openapi_types.each_pair do |key, type|
if attributes.key?(self.class.attribute_map[key]) && attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
self.send("#{key}=", nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class AddSignalToIncidentRequest
# Version of the updated signal. If server side version is higher, update will be rejected.
attr_accessor :version

attr_accessor :additional_properties

# Attribute mapping from ruby-style variable name to JSON key.
# @!visibility private
def self.attribute_map
Expand Down Expand Up @@ -58,12 +60,14 @@ def initialize(attributes = {})
fail ArgumentError, "The input argument (attributes) must be a hash in `DatadogAPIClient::V1::AddSignalToIncidentRequest` initialize method"
end

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

if attributes.key?(:'add_to_signal_timeline')
Expand Down Expand Up @@ -97,6 +101,26 @@ def incident_id=(incident_id)
@incident_id = incident_id
end

# Returns the object in the form of hash, with additionalProperties support.
# @return [Hash] Returns the object in the form of hash
# @!visibility private
def to_hash
hash = {}
self.class.attribute_map.each_pair do |attr, param|
value = self.send(attr)
if value.nil?
is_nullable = self.class.openapi_nullable.include?(attr)
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
end

hash[param] = _to_hash(value)
end
self.additional_properties.each_pair do |attr, value|
hash[attr] = value
end
hash
end

# Checks equality by comparing each attribute.
# @param o [Object] Object to be compared
# @!visibility private
Expand All @@ -106,6 +130,7 @@ def ==(o)
add_to_signal_timeline == o.add_to_signal_timeline &&
incident_id == o.incident_id &&
version == o.version
additional_properties == o.additional_properties
end

# Calculates hash code according to all attributes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class AlertGraphWidgetDefinition
# Whether to display the Alert Graph as a timeseries or a top list.
attr_reader :viz_type

attr_accessor :additional_properties

# Attribute mapping from ruby-style variable name to JSON key.
# @!visibility private
def self.attribute_map
Expand Down Expand Up @@ -78,12 +80,14 @@ def initialize(attributes = {})
fail ArgumentError, "The input argument (attributes) must be a hash in `DatadogAPIClient::V1::AlertGraphWidgetDefinition` initialize method"
end

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

if attributes.key?(:'alert_id')
Expand Down Expand Up @@ -155,6 +159,26 @@ def viz_type=(viz_type)
@viz_type = viz_type
end

# Returns the object in the form of hash, with additionalProperties support.
# @return [Hash] Returns the object in the form of hash
# @!visibility private
def to_hash
hash = {}
self.class.attribute_map.each_pair do |attr, param|
value = self.send(attr)
if value.nil?
is_nullable = self.class.openapi_nullable.include?(attr)
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
end

hash[param] = _to_hash(value)
end
self.additional_properties.each_pair do |attr, value|
hash[attr] = value
end
hash
end

# Checks equality by comparing each attribute.
# @param o [Object] Object to be compared
# @!visibility private
Expand All @@ -168,6 +192,7 @@ def ==(o)
title_size == o.title_size &&
type == o.type &&
viz_type == o.viz_type
additional_properties == o.additional_properties
end

# Calculates hash code according to all attributes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class AlertValueWidgetDefinition
# Unit to display with the value.
attr_accessor :unit

attr_accessor :additional_properties

# Attribute mapping from ruby-style variable name to JSON key.
# @!visibility private
def self.attribute_map
Expand Down Expand Up @@ -83,12 +85,14 @@ def initialize(attributes = {})
fail ArgumentError, "The input argument (attributes) must be a hash in `DatadogAPIClient::V1::AlertValueWidgetDefinition` initialize method"
end

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

if attributes.key?(:'alert_id')
Expand Down Expand Up @@ -153,6 +157,26 @@ def type=(type)
@type = type
end

# Returns the object in the form of hash, with additionalProperties support.
# @return [Hash] Returns the object in the form of hash
# @!visibility private
def to_hash
hash = {}
self.class.attribute_map.each_pair do |attr, param|
value = self.send(attr)
if value.nil?
is_nullable = self.class.openapi_nullable.include?(attr)
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
end

hash[param] = _to_hash(value)
end
self.additional_properties.each_pair do |attr, value|
hash[attr] = value
end
hash
end

# Checks equality by comparing each attribute.
# @param o [Object] Object to be compared
# @!visibility private
Expand All @@ -167,6 +191,7 @@ def ==(o)
title_size == o.title_size &&
type == o.type &&
unit == o.unit
additional_properties == o.additional_properties
end

# Calculates hash code according to all attributes.
Expand Down
29 changes: 27 additions & 2 deletions lib/datadog_api_client/v1/models/api_error_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class APIErrorResponse
# Array of errors returned by the API.
attr_reader :errors

attr_accessor :additional_properties

# Attribute mapping from ruby-style variable name to JSON key.
# @!visibility private
def self.attribute_map
Expand All @@ -48,12 +50,14 @@ def initialize(attributes = {})
fail ArgumentError, "The input argument (attributes) must be a hash in `DatadogAPIClient::V1::APIErrorResponse` initialize method"
end

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

if attributes.key?(:'errors')
Expand Down Expand Up @@ -81,13 +85,34 @@ def errors=(errors)
@errors = errors
end

# Returns the object in the form of hash, with additionalProperties support.
# @return [Hash] Returns the object in the form of hash
# @!visibility private
def to_hash
hash = {}
self.class.attribute_map.each_pair do |attr, param|
value = self.send(attr)
if value.nil?
is_nullable = self.class.openapi_nullable.include?(attr)
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
end

hash[param] = _to_hash(value)
end
self.additional_properties.each_pair do |attr, value|
hash[attr] = value
end
hash
end

# Checks equality by comparing each attribute.
# @param o [Object] Object to be compared
# @!visibility private
def ==(o)
return true if self.equal?(o)
self.class == o.class &&
errors == o.errors
additional_properties == o.additional_properties
end

# Calculates hash code according to all attributes.
Expand Down
29 changes: 27 additions & 2 deletions lib/datadog_api_client/v1/models/api_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class ApiKey
# Name of your API key.
attr_accessor :name

attr_accessor :additional_properties

# Attribute mapping from ruby-style variable name to JSON key.
# @!visibility private
def self.attribute_map
Expand Down Expand Up @@ -63,12 +65,14 @@ def initialize(attributes = {})
fail ArgumentError, "The input argument (attributes) must be a hash in `DatadogAPIClient::V1::ApiKey` initialize method"
end

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

if attributes.key?(:'created')
Expand Down Expand Up @@ -110,6 +114,26 @@ def key=(key)
@key = key
end

# Returns the object in the form of hash, with additionalProperties support.
# @return [Hash] Returns the object in the form of hash
# @!visibility private
def to_hash
hash = {}
self.class.attribute_map.each_pair do |attr, param|
value = self.send(attr)
if value.nil?
is_nullable = self.class.openapi_nullable.include?(attr)
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
end

hash[param] = _to_hash(value)
end
self.additional_properties.each_pair do |attr, value|
hash[attr] = value
end
hash
end

# Checks equality by comparing each attribute.
# @param o [Object] Object to be compared
# @!visibility private
Expand All @@ -120,6 +144,7 @@ def ==(o)
created_by == o.created_by &&
key == o.key &&
name == o.name
additional_properties == o.additional_properties
end

# Calculates hash code according to all attributes.
Expand Down
Loading