util.jsonschema: Implement the "contains" keyword

And apparently I had mistaken this for an array
pull/26/head
Kim Alvefur 5 years ago
parent 5a44c4a32b
commit ce4040e109
  1. 15
      teal-src/util/jsonschema.tl
  2. 13
      util/jsonschema.lua

@ -38,7 +38,7 @@ local record schema_t
-- arrays
items : schema_t
contains : { schema_t }
contains : schema_t
maxItems : number
minItems : number
uniqueItems : boolean
@ -285,6 +285,19 @@ type_validators.table = function (schema : schema_t, data : any) : boolean
end
end
if schema.contains then
local found = false
for i = 1, #data do
if validate(schema.contains, data[i]) then
found = true
break
end
end
if not found then
return false
end
end
return true
end
return false

@ -205,6 +205,19 @@ type_validators.table = function(schema, data)
end
end
if schema.contains then
local found = false
for i = 1, #data do
if validate(schema.contains, data[i]) then
found = true
break
end
end
if not found then
return false
end
end
return true
end
return false

Loading…
Cancel
Save