Diff

util/jsonschema.lua @ 11446:58c534bac798

util.jsonschema: Implement "propertyNames" This is a bit special in Lua as tables are not limited to string keys
author Kim Alvefur <zash@zash.se>
date Tue, 09 Mar 2021 02:43:50 +0100
parent 11445:c73744fa3bdf
child 11447:7ad137fe665b
line wrap: on
line diff
--- a/util/jsonschema.lua	Tue Mar 09 02:41:47 2021 +0100
+++ b/util/jsonschema.lua	Tue Mar 09 02:43:50 2021 +0100
@@ -158,6 +158,9 @@
 		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 @@
 			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