aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2023-03-26 15:19:14 +0200
committerKim Alvefur <zash@zash.se>2023-03-26 15:19:14 +0200
commit4bc62438dbabb8fbe7ff3c4eca69c30cc04dd8bd (patch)
tree0dfeba809d89b5bac9928b784e8e1872f32ea16e
parent5427c2472d1b6ddd57b01eaafe90a0bc4f09ffaa (diff)
downloadprosody-4bc62438dbabb8fbe7ff3c4eca69c30cc04dd8bd.tar.gz
prosody-4bc62438dbabb8fbe7ff3c4eca69c30cc04dd8bd.zip
util.jsonschema: Implement 'dependentRequired'
If this field exists, then these fields must also exist.
-rw-r--r--spec/util_jsonschema_spec.lua1
-rw-r--r--teal-src/prosody/util/jsonschema.tl12
-rw-r--r--util/jsonschema.lua12
3 files changed, 24 insertions, 1 deletions
diff --git a/spec/util_jsonschema_spec.lua b/spec/util_jsonschema_spec.lua
index 735b4f32..7d05af4a 100644
--- a/spec/util_jsonschema_spec.lua
+++ b/spec/util_jsonschema_spec.lua
@@ -19,7 +19,6 @@ local skip = {
["const.json:9"] = "deepcompare",
["contains.json:0:5"] = "distinguishing objects from arrays",
["defs.json"] = "need built-in meta-schema",
- ["dependentRequired.json"] = "NYI",
["dependentSchemas.json"] = "NYI",
["dynamicRef.json"] = "NYI",
["enum.json:1:3"] = "deepcompare",
diff --git a/teal-src/prosody/util/jsonschema.tl b/teal-src/prosody/util/jsonschema.tl
index 8e5d69bc..fa230cac 100644
--- a/teal-src/prosody/util/jsonschema.tl
+++ b/teal-src/prosody/util/jsonschema.tl
@@ -295,6 +295,18 @@ function complex_validate (schema : json_schema_object, data : any, root : json_
end
end
+ if schema.dependentRequired then
+ for k, reqs in pairs(schema.dependentRequired) do
+ if data[k] ~= nil then
+ for _, req in ipairs(reqs) do
+ if data[req] == nil then
+ return false
+ end
+ end
+ end
+ end
+ end
+
if schema.propertyNames ~= nil then
for k in pairs(data) do
if not validate(schema.propertyNames, k, root) then
diff --git a/util/jsonschema.lua b/util/jsonschema.lua
index be0b72fd..1c4dcfbd 100644
--- a/util/jsonschema.lua
+++ b/util/jsonschema.lua
@@ -206,6 +206,18 @@ function complex_validate(schema, data, root)
end
end
+ if schema.dependentRequired then
+ for k, reqs in pairs(schema.dependentRequired) do
+ if data[k] ~= nil then
+ for _, req in ipairs(reqs) do
+ if data[req] == nil then
+ return false
+ end
+ end
+ end
+ end
+ end
+
if schema.propertyNames ~= nil then
for k in pairs(data) do
if not validate(schema.propertyNames, k, root) then