module JSI
module Schema::Validation::ArrayLength
def internal_validate_maxItems(result_builder)
if keyword?('maxItems')
value = schema_content['maxItems']
if internal_integer?(value) && value >= 0
if result_builder.instance.respond_to?(:to_ary)
result_builder.validate(
result_builder.instance.to_ary.size <= value,
'instance array size is greater than `maxItems` value',
keyword: 'maxItems',
)
end
else
result_builder.schema_error('`maxItems` is not a non-negative integer', 'maxItems')
end
end
end
def internal_validate_minItems(result_builder)
if keyword?('minItems')
value = schema_content['minItems']
if internal_integer?(value) && value >= 0
if result_builder.instance.respond_to?(:to_ary)
result_builder.validate(
result_builder.instance.to_ary.size >= value,
'instance array size is less than `minItems` value',
keyword: 'minItems',
)
end
else
result_builder.schema_error('`minItems` is not a non-negative integer', 'minItems')
end
end
end
end
module Schema::Validation::UniqueItems
def internal_validate_uniqueItems(result_builder)
if keyword?('uniqueItems')
value = schema_content['uniqueItems']
if value == false
elsif value == true
if result_builder.instance.respond_to?(:to_ary)
result_builder.validate(
result_builder.instance.uniq.size == result_builder.instance.size,
"instance array items' uniqueness does not match `uniqueItems` value",
keyword: 'uniqueItems',
)
end
else
result_builder.schema_error('`uniqueItems` is not a boolean', 'uniqueItems')
end
end
end
end
end