module JSI
module Schema::Validation::Properties
def internal_validate_properties(result_builder)
evaluated_property_names = Set[]
if keyword?('properties')
value = schema_content['properties']
if value.respond_to?(:to_hash)
if result_builder.instance.respond_to?(:to_hash)
results = {}
result_builder.instance.keys.each do |property_name|
if value.key?(property_name)
evaluated_property_names << property_name
results[property_name] = result_builder.child_subschema_validate(
property_name,
['properties', property_name],
)
end
end
result_builder.validate(
results.values.all?(&:valid?),
'instance object properties are not all valid against corresponding `properties` schema values',
keyword: 'properties',
results: results.values,
)
end
else
result_builder.schema_error('`properties` is not an object', 'properties')
end
end
if keyword?('patternProperties')
value = schema_content['patternProperties']
if value.respond_to?(:to_hash)
if result_builder.instance.respond_to?(:to_hash)
results = {}
result_builder.instance.keys.each do |property_name|
value.keys.each do |value_property_pattern|
begin
if value_property_pattern.respond_to?(:to_str) && Regexp.new(value_property_pattern).match(property_name.to_s)
evaluated_property_names << property_name
results[property_name] = result_builder.child_subschema_validate(
property_name,
['patternProperties', value_property_pattern],
)
end
rescue ::RegexpError
result_builder.schema_error("`patternProperties` key #{property_name.inspect} is not a valid regular expression: #{e.message}", 'patternProperties')
end
end
end
result_builder.validate(
results.values.all?(&:valid?),
'instance object properties are not all valid against corresponding `patternProperties` schema values',
keyword: 'patternProperties',
results: results.values,
)
end
else
result_builder.schema_error('`patternProperties` is not an object', 'patternProperties')
end
end
if keyword?('additionalProperties')
value = schema_content['additionalProperties']
if result_builder.instance.respond_to?(:to_hash)
results = {}
result_builder.instance.keys.each do |property_name|
if !evaluated_property_names.include?(property_name)
results[property_name] = result_builder.child_subschema_validate(
property_name,
['additionalProperties'],
)
end
end.compact
result_builder.validate(
results.values.all?(&:valid?),
'instance object additional properties are not all valid against `additionalProperties` schema value',
keyword: 'additionalProperties',
results: results.values,
)
end
end
end
end
end