Comparison

teal-src/util/jsonschema.tl @ 11440:d5288c99bb5a

util.jsonschema: Correct "items" keyword Upon re-reading the JSON Schema spec, I found that 'items' wasn't a union of an array of schemas or a single schema, not sure where I got that from.
author Kim Alvefur <zash@zash.se>
date Tue, 09 Mar 2021 02:26:05 +0100
parent 11439:9abcdfdcdb01
child 11441:75a280e6e046
comparison
equal deleted inserted replaced
11439:9abcdfdcdb01 11440:d5288c99bb5a
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 items : { schema_t } | schema_t 40 items : schema_t
41 contains : { schema_t } 41 contains : { schema_t }
42 maxItems : number 42 maxItems : number
43 minItems : number 43 minItems : number
44 uniqueItems : boolean 44 uniqueItems : boolean
45 maxContains : number 45 maxContains : number
272 values[v] = true 272 values[v] = true
273 end 273 end
274 return true 274 return true
275 end 275 end
276 276
277 local item_schemas = schema.items as {schema_t} 277 if schema.items then
278 if item_schemas and item_schemas[1] == nil then 278 for i = 1, #data do
279 local item_schema = item_schemas as schema_t 279 if not validate(schema.items, data[i]) then
280 for i, v in pairs(data) do 280 return false
281 if i is number then 281 end
282 if not validate(item_schema, v) then
283 return false
284 end
285 end
286 end
287 elseif item_schemas and item_schemas[1] ~= nil then
288 for i, s in ipairs(item_schemas) do
289 validate(s, data[i])
290 end 282 end
291 end 283 end
292 284
293 return true 285 return true
294 end 286 end