aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--spec/util_jsonschema_spec.lua2
-rw-r--r--teal-src/prosody/util/jsonschema.tl9
-rw-r--r--util/jsonschema.lua8
3 files changed, 18 insertions, 1 deletions
diff --git a/spec/util_jsonschema_spec.lua b/spec/util_jsonschema_spec.lua
index 7d05af4a..602a2b7f 100644
--- a/spec/util_jsonschema_spec.lua
+++ b/spec/util_jsonschema_spec.lua
@@ -19,7 +19,7 @@ local skip = {
["const.json:9"] = "deepcompare",
["contains.json:0:5"] = "distinguishing objects from arrays",
["defs.json"] = "need built-in meta-schema",
- ["dependentSchemas.json"] = "NYI",
+ ["dependentSchemas.json:2:2"] = "NYI", -- minProperties
["dynamicRef.json"] = "NYI",
["enum.json:1:3"] = "deepcompare",
["id.json"] = "NYI",
diff --git a/teal-src/prosody/util/jsonschema.tl b/teal-src/prosody/util/jsonschema.tl
index fa230cac..efdb8f25 100644
--- a/teal-src/prosody/util/jsonschema.tl
+++ b/teal-src/prosody/util/jsonschema.tl
@@ -71,6 +71,7 @@ local record json_schema_object
additionalProperties: schema_t
patternProperties: schema_t -- NYI
propertyNames : schema_t
+ dependentSchemas : { string : schema_t }
-- xml
record xml_t
@@ -333,6 +334,14 @@ function complex_validate (schema : json_schema_object, data : any, root : json_
end
end
+ if schema.dependentSchemas then
+ for k, sub in pairs(schema.dependentSchemas) do
+ if data[k] ~= nil and not validate(sub, data, root) then
+ return false
+ end
+ end
+ end
+
if schema.uniqueItems then
-- only works for scalars, would need to deep-compare for objects/arrays/tables
local values : { any : boolean } = {}
diff --git a/util/jsonschema.lua b/util/jsonschema.lua
index 1c4dcfbd..3160229f 100644
--- a/util/jsonschema.lua
+++ b/util/jsonschema.lua
@@ -244,6 +244,14 @@ function complex_validate(schema, data, root)
end
end
+ if schema.dependentSchemas then
+ for k, sub in pairs(schema.dependentSchemas) do
+ if data[k] ~= nil and not validate(sub, data, root) then
+ return false
+ end
+ end
+ end
+
if schema.uniqueItems then
local values = {}