aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-03-09 02:43:50 +0100
committerKim Alvefur <zash@zash.se>2021-03-09 02:43:50 +0100
commit1317e78fbb50d585d3f0aa55262690db8c096026 (patch)
tree317c704c126613f4c2ea59d84999f89bf2bac581
parentd8303be1456b03c623abc004b415add47318b234 (diff)
downloadprosody-1317e78fbb50d585d3f0aa55262690db8c096026.tar.gz
prosody-1317e78fbb50d585d3f0aa55262690db8c096026.zip
util.jsonschema: Implement "propertyNames"
This is a bit special in Lua as tables are not limited to string keys
-rw-r--r--teal-src/util/jsonschema.tl7
-rw-r--r--util/jsonschema.lua6
2 files changed, 13 insertions, 0 deletions
diff --git a/teal-src/util/jsonschema.tl b/teal-src/util/jsonschema.tl
index d359207b..9600fee4 100644
--- a/teal-src/util/jsonschema.tl
+++ b/teal-src/util/jsonschema.tl
@@ -54,6 +54,7 @@ local record schema_t
dependentRequired : { string : { string } }
additionalProperties: schema_t
patternProperties: schema_t
+ propertyNames : schema_t
-- xml
record xml_t
@@ -239,6 +240,9 @@ type_validators.table = function (schema : schema_t, data : any) : boolean
if schema.properties then
local additional : schema_t | boolean = schema.additionalProperties or true
for k, v in pairs(data) do
+ if schema.propertyNames and not validate(schema.propertyNames, k) then
+ return false
+ end
local s = schema.properties[k as string] or additional as schema_t
if not validate(s, v) then
return false
@@ -246,6 +250,9 @@ type_validators.table = function (schema : schema_t, data : any) : boolean
end
elseif schema.additionalProperties then
for k, v in pairs(data) do
+ if schema.propertyNames and not validate(schema.propertyNames, k) then
+ return false
+ end
if not validate(schema.additionalProperties, v) then
return false
end
diff --git a/util/jsonschema.lua b/util/jsonschema.lua
index 5ba33900..0723a45e 100644
--- a/util/jsonschema.lua
+++ b/util/jsonschema.lua
@@ -158,6 +158,9 @@ type_validators.table = function(schema, data)
if schema.properties then
local additional = schema.additionalProperties or true
for k, v in pairs(data) do
+ if schema.propertyNames and not validate(schema.propertyNames, k) then
+ return false
+ end
local s = schema.properties[k] or additional
if not validate(s, v) then
return false
@@ -165,6 +168,9 @@ type_validators.table = function(schema, data)
end
elseif schema.additionalProperties then
for k, v in pairs(data) do
+ if schema.propertyNames and not validate(schema.propertyNames, k) then
+ return false
+ end
if not validate(schema.additionalProperties, v) then
return false
end