aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2023-04-22 12:14:29 +0200
committerKim Alvefur <zash@zash.se>2023-04-22 12:14:29 +0200
commit1dad83d28eafc84d2253eadf8ed58d6caefc78df (patch)
treeb11e423401837d36a58013d9eec3f8df76c67283 /util
parent3697942a4af2d5cf29187ef844798b52a5fff37b (diff)
downloadprosody-1dad83d28eafc84d2253eadf8ed58d6caefc78df.tar.gz
prosody-1dad83d28eafc84d2253eadf8ed58d6caefc78df.zip
util.jsonschema: Implement 'luaPatternProperties' as Lua variant of 'patternProperties'
Previous version of this patch used 'patternProperties' but that would only work with simpler ECMA-262 regular expressions are also valid Lua patterns.
Diffstat (limited to 'util')
-rw-r--r--util/jsonschema.lua19
1 files changed, 18 insertions, 1 deletions
diff --git a/util/jsonschema.lua b/util/jsonschema.lua
index 3160229f..c65470fd 100644
--- a/util/jsonschema.lua
+++ b/util/jsonschema.lua
@@ -226,17 +226,34 @@ function complex_validate(schema, data, root)
end
end
+ local seen_properties = {}
+
if schema.properties then
for k, sub in pairs(schema.properties) do
if data[k] ~= nil and not validate(sub, data[k], root) then
return false
end
+ seen_properties[k] = true
+ end
+ end
+
+ if schema.luaPatternProperties then
+
+ for pattern, sub in pairs(schema.luaPatternProperties) do
+ for k in pairs(data) do
+ if type(k) == "string" and k:match(pattern) then
+ if not validate(sub, data[k], root) then
+ return false
+ end
+ seen_properties[k] = true
+ end
+ end
end
end
if schema.additionalProperties ~= nil then
for k, v in pairs(data) do
- if schema.properties == nil or schema.properties[k] == nil then
+ if not seen_properties[k] then
if not validate(schema.additionalProperties, v, root) then
return false
end