module JSI
module Schema::Validation::Draft04::MinMax
def internal_validate_maximum(result_builder)
if keyword?('exclusiveMaximum')
value = schema_content['exclusiveMaximum']
unless [true, false].include?(value)
result_builder.schema_error('`exclusiveMaximum` is not true or false', 'exclusiveMaximum')
end
if !keyword?('maximum')
result_builder.schema_error('`exclusiveMaximum` has no effect without adjacent `maximum` keyword', 'exclusiveMaximum')
end
end
if keyword?('maximum')
value = schema_content['maximum']
if value.is_a?(Numeric)
if result_builder.instance.is_a?(Numeric)
if schema_content['exclusiveMaximum'] == true
result_builder.validate(
result_builder.instance < value,
'instance is not less than `maximum` value with `exclusiveMaximum` = true',
keyword: 'maximum',
)
else
result_builder.validate(
result_builder.instance <= value,
'instance is not less than or equal to `maximum` value',
keyword: 'maximum',
)
end
end
else
result_builder.schema_error('`maximum` is not a number', 'maximum')
end
end
end
def internal_validate_minimum(result_builder)
if keyword?('exclusiveMinimum')
value = schema_content['exclusiveMinimum']
unless [true, false].include?(value)
result_builder.schema_error('`exclusiveMinimum` is not true or false', 'exclusiveMinimum')
end
if !keyword?('minimum')
result_builder.schema_error('`exclusiveMinimum` has no effect without adjacent `minimum` keyword', 'exclusiveMinimum')
end
end
if keyword?('minimum')
value = schema_content['minimum']
if value.is_a?(Numeric)
if result_builder.instance.is_a?(Numeric)
if schema_content['exclusiveMinimum'] == true
result_builder.validate(
result_builder.instance > value,
'instance is not greater than `minimum` value with `exclusiveMinimum` = true',
keyword: 'minimum',
)
else
result_builder.validate(
result_builder.instance >= value,
'instance is not greater than or equal to `minimum` value',
keyword: 'minimum',
)
end
end
else
result_builder.schema_error('`minimum` is not a number', 'minimum')
end
end
end
end
end