Changeset

11442:95f0d77175ca

util.jsonschema: Implement the "contains" keyword And apparently I had mistaken this for an array
author Kim Alvefur <zash@zash.se>
date Tue, 09 Mar 2021 02:35:00 +0100
parents 11441:75a280e6e046
children 11443:a526abef61e6
files teal-src/util/jsonschema.tl util/jsonschema.lua
diffstat 2 files changed, 27 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/teal-src/util/jsonschema.tl	Tue Mar 09 02:33:28 2021 +0100
+++ b/teal-src/util/jsonschema.tl	Tue Mar 09 02:35:00 2021 +0100
@@ -38,7 +38,7 @@
 
 	-- arrays
 	items : schema_t
-	contains : { schema_t }
+	contains : schema_t
 	maxItems : number
 	minItems : number
 	uniqueItems : boolean
@@ -285,6 +285,19 @@
 			end
 		end
 
+		if schema.contains then
+			local found = false
+			for i = 1, #data do
+				if validate(schema.contains, data[i]) then
+					found = true
+					break
+				end
+			end
+			if not found then
+				return false
+			end
+		end
+
 		return true
 	end
 	return false
--- a/util/jsonschema.lua	Tue Mar 09 02:33:28 2021 +0100
+++ b/util/jsonschema.lua	Tue Mar 09 02:35:00 2021 +0100
@@ -205,6 +205,19 @@
 			end
 		end
 
+		if schema.contains then
+			local found = false
+			for i = 1, #data do
+				if validate(schema.contains, data[i]) then
+					found = true
+					break
+				end
+			end
+			if not found then
+				return false
+			end
+		end
+
 		return true
 	end
 	return false