From ce4040e1091705d94bb46c59dcd0cc16edde702e Mon Sep 17 00:00:00 2001
From: Kim Alvefur <zash@zash.se>
Date: Tue, 9 Mar 2021 02:35:00 +0100
Subject: util.jsonschema: Implement the "contains" keyword

And apparently I had mistaken this for an array
---
 teal-src/util/jsonschema.tl | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

(limited to 'teal-src/util')

diff --git a/teal-src/util/jsonschema.tl b/teal-src/util/jsonschema.tl
index d2390f7e..3f5b0f26 100644
--- a/teal-src/util/jsonschema.tl
+++ b/teal-src/util/jsonschema.tl
@@ -38,7 +38,7 @@ local record schema_t
 
 	-- arrays
 	items : schema_t
-	contains : { schema_t }
+	contains : schema_t
 	maxItems : number
 	minItems : number
 	uniqueItems : boolean
@@ -285,6 +285,19 @@ type_validators.table = function (schema : schema_t, data : any) : boolean
 			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
-- 
cgit v1.2.3