Software /
code /
prosody
Changeset
11443:a526abef61e6
util.jsonschema: Implement the "prefixItems" keyword
This may have been what got me confused about "items" being an array.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 09 Mar 2021 02:36:08 +0100 |
parents | 11442:95f0d77175ca |
children | 11444:b3a903032611 |
files | teal-src/util/jsonschema.tl util/jsonschema.lua |
diffstat | 2 files changed, 25 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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