module JSI
module Schema::Validation::StringLength
def internal_validate_maxLength(result_builder)
if keyword?('maxLength')
value = schema_content['maxLength']
if internal_integer?(value) && value >= 0
if result_builder.instance.respond_to?(:to_str)
result_builder.validate(
result_builder.instance.to_str.length <= value,
'instance string length is not less than or equal to `maxLength` value',
keyword: 'maxLength',
)
end
else
result_builder.schema_error('`maxLength` is not a non-negative integer', 'maxLength')
end
end
end
def internal_validate_minLength(result_builder)
if keyword?('minLength')
value = schema_content['minLength']
if internal_integer?(value) && value >= 0
if result_builder.instance.respond_to?(:to_str)
result_builder.validate(
result_builder.instance.to_str.length >= value,
'instance string length is not greater than or equal to `minLength` value',
keyword: 'minLength',
)
end
else
result_builder.schema_error('`minLength` is not a non-negative integer', 'minLength')
end
end
end
end
end