Skip to content

Commit 59e9075

Browse files
committed
chore(test): fix rounding for integer
1 parent 1fb3ba5 commit 59e9075

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

spec/extra/errors/collect_all_errors.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
"data": ["aa", "bb", "cc", "dd", "ee", "ff"],
7777
"valid": false,
7878
"error_entries": [
79-
{"schema_path": "/maxItems", "instance_path": "", "error": "expect array to have at most 5.0 items"}
79+
{"schema_path": "/maxItems", "instance_path": "", "error": "expect array to have at most 5 items"}
8080
]
8181
}
8282
]
@@ -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: 4 additions & 4 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"', 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"', 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
@@ -1051,8 +1051,8 @@ generate_validator = function(ctx, schema)
10511051
-- ctx:stmt("print('quotient:', quotient)")
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
1054-
ctx:handle_error(' ', sformat('%s("expected %%s to be a multiple of %s", %s)',
1055-
ctx:libfunc('string.format'), mof, ctx:param(1)), '"/multipleOf"', '""')
1054+
ctx:handle_error(' ', sformat('%s("expected %%d to be a multiple of %s", %s)',
1055+
ctx:libfunc('string.format'), format_number(mof), ctx:param(1)), '"/multipleOf"', '""')
10561056
ctx:stmt( ' end')
10571057
end
10581058
ctx:stmt('end') -- if number

0 commit comments

Comments
 (0)