# HG changeset patch # User Kim Alvefur # Date 1615253768 -3600 # Node ID a526abef61e6318b2741e48919a9082db3fa2cd8 # Parent 95f0d77175caa99ee2f4c630858a5632932f616f util.jsonschema: Implement the "prefixItems" keyword This may have been what got me confused about "items" being an array. diff -r 95f0d77175ca -r a526abef61e6 teal-src/util/jsonschema.tl --- a/teal-src/util/jsonschema.tl Tue Mar 09 02:35:00 2021 +0100 +++ b/teal-src/util/jsonschema.tl Tue Mar 09 02:36:08 2021 +0100 @@ -37,6 +37,7 @@ format : string -- arrays + prefixItems : { schema_t } items : schema_t contains : schema_t maxItems : number @@ -277,8 +278,19 @@ 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 diff -r 95f0d77175ca -r a526abef61e6 util/jsonschema.lua --- a/util/jsonschema.lua Tue Mar 09 02:35:00 2021 +0100 +++ b/util/jsonschema.lua Tue Mar 09 02:36:08 2021 +0100 @@ -197,8 +197,19 @@ 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