aboutsummaryrefslogtreecommitdiffstats
path: root/teal-src
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2023-03-26 15:20:07 +0200
committerKim Alvefur <zash@zash.se>2023-03-26 15:20:07 +0200
commit8c9ffa25eb18f8ccdd3d3aa515a01efaf9814680 (patch)
treeced85b064be32794f596c08c20f2b6f43289d0d3 /teal-src
parent4bc62438dbabb8fbe7ff3c4eca69c30cc04dd8bd (diff)
downloadprosody-8c9ffa25eb18f8ccdd3d3aa515a01efaf9814680.tar.gz
prosody-8c9ffa25eb18f8ccdd3d3aa515a01efaf9814680.zip
util.jsonschema: Implement 'dependentSchemas'
If this object key exists then this schema must validate against the current object. Seems useful.
Diffstat (limited to 'teal-src')
-rw-r--r--teal-src/prosody/util/jsonschema.tl9
1 files changed, 9 insertions, 0 deletions
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 } = {}