Changeset

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
parents 11445:c73744fa3bdf
children 11447:7ad137fe665b
files teal-src/util/jsonschema.tl util/jsonschema.lua
diffstat 2 files changed, 13 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/teal-src/util/jsonschema.tl	Tue Mar 09 02:41:47 2021 +0100
+++ b/teal-src/util/jsonschema.tl	Tue Mar 09 02:43:50 2021 +0100
@@ -54,6 +54,7 @@
 	dependentRequired : { string : { string } }
 	additionalProperties: schema_t
 	patternProperties: schema_t
+	propertyNames : schema_t
 
 	-- xml
 	record xml_t
@@ -239,6 +240,9 @@
 		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 @@
 			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
--- 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