Software /
code /
prosody
Comparison
teal-src/util/jsonschema.tl @ 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 |
parent | 11442:95f0d77175ca |
child | 11444:b3a903032611 |
comparison
equal
deleted
inserted
replaced
11442:95f0d77175ca | 11443:a526abef61e6 |
---|---|
35 minLength : number | 35 minLength : number |
36 pattern : string | 36 pattern : string |
37 format : string | 37 format : string |
38 | 38 |
39 -- arrays | 39 -- arrays |
40 prefixItems : { schema_t } | |
40 items : schema_t | 41 items : schema_t |
41 contains : schema_t | 42 contains : schema_t |
42 maxItems : number | 43 maxItems : number |
43 minItems : number | 44 minItems : number |
44 uniqueItems : boolean | 45 uniqueItems : boolean |
275 values[v] = true | 276 values[v] = true |
276 end | 277 end |
277 return true | 278 return true |
278 end | 279 end |
279 | 280 |
281 local p = 0 | |
282 if schema.prefixItems then | |
283 for i, s in ipairs(schema.prefixItems) do | |
284 if validate(s, data[i]) then | |
285 p = i | |
286 else | |
287 return false | |
288 end | |
289 end | |
290 end | |
291 | |
280 if schema.items then | 292 if schema.items then |
281 for i = 1, #data do | 293 for i = p+1, #data do |
282 if not validate(schema.items, data[i]) then | 294 if not validate(schema.items, data[i]) then |
283 return false | 295 return false |
284 end | 296 end |
285 end | 297 end |
286 end | 298 end |