util.jsonschema: Implement the "contains" keyword
And apparently I had mistaken this for an array
--- a/teal-src/util/jsonschema.tl Tue Mar 09 02:33:28 2021 +0100
+++ b/teal-src/util/jsonschema.tl Tue Mar 09 02:35:00 2021 +0100
@@ -38,7 +38,7 @@
-- arrays
items : schema_t
- contains : { schema_t }
+ contains : schema_t
maxItems : number
minItems : number
uniqueItems : boolean
@@ -285,6 +285,19 @@
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
--- a/util/jsonschema.lua Tue Mar 09 02:33:28 2021 +0100
+++ b/util/jsonschema.lua Tue Mar 09 02:35:00 2021 +0100
@@ -205,6 +205,19 @@
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