Skip to content

Commit 3416376

Browse files
committed
use existing number formatter
1 parent 4ccd75d commit 3416376

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

spec/extra/errors/collect_all_errors.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
"valid": false,
146146
"error_entries": [
147147
{"schema_path": "/minimum", "instance_path": "", "error": "expected 7 to be greater than 10"},
148-
{"schema_path": "/multipleOf", "instance_path": "", "error": "expected 7.0 to be a multiple of 5.0"}
148+
{"schema_path": "/multipleOf", "instance_path": "", "error": "expected 7 to be a multiple of 5"}
149149
]
150150
}
151151
]

src/resty/ljsonschema/init.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -800,12 +800,12 @@ generate_validator = function(ctx, schema)
800800
ctx:stmt(sformat( ' local itemcount = #%s', ctx:param(1)))
801801
if schema.minItems then
802802
ctx:stmt(sformat(' if itemcount < %d then', schema.minItems))
803-
ctx:handle_error(' ', sformat('"expect array to have at least %s items"', math.floor(schema.minItems)), '"/minItems"', '""')
803+
ctx:handle_error(' ', sformat('"expect array to have at least %s items"', format_number(schema.minItems)), '"/minItems"', '""')
804804
ctx:stmt( ' end')
805805
end
806806
if schema.maxItems then
807807
ctx:stmt(sformat(' if itemcount > %d then', schema.maxItems))
808-
ctx:handle_error(' ', sformat('"expect array to have at most %s items"', math.floor(schema.maxItems)), '"/maxItems"', '""')
808+
ctx:handle_error(' ', sformat('"expect array to have at most %s items"', format_number(schema.maxItems)), '"/maxItems"', '""')
809809
ctx:stmt( ' end')
810810
end
811811
end
@@ -1052,7 +1052,7 @@ generate_validator = function(ctx, schema)
10521052
ctx:stmt(sformat(' if %s(quotient) ~= quotient or %s == quotient or %s == -quotient then', ctx:libfunc('math.modf'), ctx:libfunc('math.huge'), ctx:libfunc('math.huge')))
10531053
end
10541054
ctx:handle_error(' ', sformat('%s("expected %%s to be a multiple of %s", %s)',
1055-
ctx:libfunc('string.format'), mof, ctx:param(1)), '"/multipleOf"', '""')
1055+
ctx:libfunc('string.format'), format_number(mof), format_number(ctx:param(1))), '"/multipleOf"', '""')
10561056
ctx:stmt( ' end')
10571057
end
10581058
ctx:stmt('end') -- if number

0 commit comments

Comments
 (0)