Comparison

util/jsonschema.lua @ 13087:5d3e8a226840

util.jsonschema: Implement 'minContains' and 'maxContains'
author Kim Alvefur <zash@zash.se>
date Sun, 23 Apr 2023 10:26:43 +0200
parent 13085:0e17cb78264f
child 13088:0fbb2b3fd4c0
comparison
equal deleted inserted replaced
13086:42ea593bfa8d 13087:5d3e8a226840
303 end 303 end
304 end 304 end
305 end 305 end
306 306
307 if schema.contains ~= nil then 307 if schema.contains ~= nil then
308 local found = false 308 local found = 0
309 for i = 1, #data do 309 for i = 1, #data do
310 if validate(schema.contains, data[i], root) then 310 if validate(schema.contains, data[i], root) then
311 found = true 311 found = found + 1
312 break 312 end
313 end 313 end
314 end 314 if found < (schema.minContains or 1) or found > (schema.maxContains or math.huge) then
315 if not found then
316 return false 315 return false
317 end 316 end
318 end 317 end
319 end 318 end
320 319