module JSI
module Schema::Validation::Items
def internal_validate_items(result_builder)
if keyword?('items')
value = schema_content['items']
if value.respond_to?(:to_ary)
if result_builder.instance.respond_to?(:to_ary)
results = {}
result_builder.instance.each_index do |i|
if i < value.size
results[i] = result_builder.child_subschema_validate(i, ['items', i])
elsif keyword?('additionalItems')
results[i] = result_builder.child_subschema_validate(i, ['additionalItems'])
end
end
result_builder.validate(
results.values.all?(&:valid?),
'instance array items are not all valid against corresponding `items` or `additionalItems` schema values',
keyword: 'items',
results: results.values,
)
end
else
if result_builder.instance.respond_to?(:to_ary)
results = result_builder.instance.each_index.map do |i|
result_builder.child_subschema_validate(i, ['items'])
end
result_builder.validate(
results.all?(&:valid?),
'instance array items are not all valid against `items` schema value',
keyword: 'items',
results: results,
)
end
if keyword?('additionalItems')
result_builder.schema_warning('`additionalItems` has no effect when adjacent `items` keyword is not an array', 'items')
end
end
else
if keyword?('additionalItems')
result_builder.schema_warning('`additionalItems` has no effect without adjacent `items` keyword', 'items')
end
end
end
end
end