aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-03-09 02:35:00 +0100
committerKim Alvefur <zash@zash.se>2021-03-09 02:35:00 +0100
commitce4040e1091705d94bb46c59dcd0cc16edde702e (patch)
treeae9d2c4737407a200f19ca3ee8e2148d3148b8e8
parent5a44c4a32b928ac44e5e6f6b028310b9c78faf87 (diff)
downloadprosody-ce4040e1091705d94bb46c59dcd0cc16edde702e.tar.gz
prosody-ce4040e1091705d94bb46c59dcd0cc16edde702e.zip
util.jsonschema: Implement the "contains" keyword
And apparently I had mistaken this for an array
-rw-r--r--teal-src/util/jsonschema.tl15
-rw-r--r--util/jsonschema.lua13
2 files changed, 27 insertions, 1 deletions
diff --git a/teal-src/util/jsonschema.tl b/teal-src/util/jsonschema.tl
index d2390f7e..3f5b0f26 100644
--- a/teal-src/util/jsonschema.tl
+++ b/teal-src/util/jsonschema.tl
@@ -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
diff --git a/util/jsonschema.lua b/util/jsonschema.lua
index b285feb4..4ace2d2d 100644
--- a/util/jsonschema.lua
+++ b/util/jsonschema.lua
@@ -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