mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-14 19:24:10 +03:00
JSON parser: Add maximum and minimum for integers
This commit is contained in:
parent
a60924e676
commit
84718825e2
@ -259,7 +259,29 @@ class Validator
|
||||
#
|
||||
#
|
||||
def validate_integer(body, schema_array, schema_key)
|
||||
Integer(body)
|
||||
value = Integer(body)
|
||||
|
||||
if schema_array[:maximum]
|
||||
excl = schema_array[:exclusiveMaximum]
|
||||
max = schema_array[:maximum]
|
||||
if !(excl ? value < max : value <= max)
|
||||
raise ParseException, "KEY: '#{schema_key}' must be "\
|
||||
"lower than #{excl ? '' : 'or equal to'} #{max};"\
|
||||
" SCHEMA: #{schema_array}"
|
||||
end
|
||||
end
|
||||
|
||||
if schema_array[:minimum]
|
||||
excl = schema_array[:exclusiveMinimum]
|
||||
min = schema_array[:minimum]
|
||||
if !(excl ? value > min : value >= min)
|
||||
raise ParseException, "KEY: '#{schema_key}' must be "\
|
||||
"greater than #{excl ? '' : 'or equal to'} #{min};"\
|
||||
" SCHEMA: #{schema_array}"
|
||||
end
|
||||
end
|
||||
|
||||
value
|
||||
rescue ArgumentError
|
||||
raise ParseException, "KEY: '#{schema_key}' must be an Integer;"\
|
||||
" SCHEMA: #{schema_array}"
|
||||
|
Loading…
x
Reference in New Issue
Block a user