From da85d37bcb847acf53031811277392afe2a17ed2 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 9 Mar 2021 02:36:08 +0100 Subject: util.jsonschema: Implement the "prefixItems" keyword This may have been what got me confused about "items" being an array. --- util/jsonschema.lua | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'util') diff --git a/util/jsonschema.lua b/util/jsonschema.lua index 4ace2d2d..97068c5c 100644 --- a/util/jsonschema.lua +++ b/util/jsonschema.lua @@ -197,8 +197,19 @@ type_validators.table = function(schema, data) return true end + local p = 0 + if schema.prefixItems then + for i, s in ipairs(schema.prefixItems) do + if validate(s, data[i]) then + p = i + else + return false + end + end + end + if schema.items then - for i = 1, #data do + for i = p + 1, #data do if not validate(schema.items, data[i]) then return false end -- cgit v1.2.3