# HG changeset patch # User Kim Alvefur # Date 1615253165 -3600 # Node ID d5288c99bb5a9a823c82aa2df3dd9450805b435e # Parent 9abcdfdcdb011102b4264bab284cb60b12e6a464 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. diff -r 9abcdfdcdb01 -r d5288c99bb5a teal-src/util/jsonschema.tl --- a/teal-src/util/jsonschema.tl Sun Mar 07 12:48:49 2021 +0100 +++ b/teal-src/util/jsonschema.tl Tue Mar 09 02:26:05 2021 +0100 @@ -37,7 +37,7 @@ format : string -- arrays - items : { schema_t } | schema_t + items : schema_t contains : { schema_t } maxItems : number minItems : number @@ -274,20 +274,12 @@ return true end - local item_schemas = schema.items as {schema_t} - if item_schemas and item_schemas[1] == nil then - local item_schema = item_schemas as schema_t - for i, v in pairs(data) do - if i is number then - if not validate(item_schema, v) then - return false - end + if schema.items then + for i = 1, #data do + if not validate(schema.items, data[i]) then + return false end end - elseif item_schemas and item_schemas[1] ~= nil then - for i, s in ipairs(item_schemas) do - validate(s, data[i]) - end end return true diff -r 9abcdfdcdb01 -r d5288c99bb5a util/jsonschema.lua --- a/util/jsonschema.lua Sun Mar 07 12:48:49 2021 +0100 +++ b/util/jsonschema.lua Tue Mar 09 02:26:05 2021 +0100 @@ -194,20 +194,12 @@ return true end - local item_schemas = schema.items - if item_schemas and item_schemas[1] == nil then - local item_schema = item_schemas - for i, v in pairs(data) do - if type(i) == "number" then - if not validate(item_schema, v) then - return false - end + if schema.items then + for i = 1, #data do + if not validate(schema.items, data[i]) then + return false end end - elseif item_schemas and item_schemas[1] ~= nil then - for i, s in ipairs(item_schemas) do - validate(s, data[i]) - end end return true