# HG changeset patch # User Kim Alvefur # Date 1687014774 -7200 # Node ID 6140aa67c61835005a65fdf7aabd676b714c240d # Parent 9ba11ef91ce428ace86418eeb2b1bba3869983a0 util.jsonschema: Silence Teal warnings about counting items in tables Teal thinks that these are key-value maps which are always of length zero, but that is not the case. diff -r 9ba11ef91ce4 -r 6140aa67c618 teal-src/prosody/util/jsonschema.tl --- a/teal-src/prosody/util/jsonschema.tl Wed Jan 12 10:23:13 2022 +0100 +++ b/teal-src/prosody/util/jsonschema.tl Sat Jun 17 17:12:54 2023 +0200 @@ -320,11 +320,11 @@ -- validations in this block, which could be useful for validating Lua -- tables - if schema.maxItems and #data > schema.maxItems then + if schema.maxItems and #(data as {any}) > schema.maxItems then return false end - if schema.minItems and #data < schema.minItems then + if schema.minItems and #(data as {any}) < schema.minItems then return false end @@ -428,7 +428,7 @@ end if schema.items ~= nil then - for i = p+1, #data do + for i = p+1, #(data as {any}) do if not validate(schema.items, data[i], root) then return false end @@ -437,7 +437,7 @@ if schema.contains ~= nil then local found = 0 - for i = 1, #data do + for i = 1, #(data as {any}) do if validate(schema.contains, data[i], root) then found = found + 1 end diff -r 9ba11ef91ce4 -r 6140aa67c618 util/jsonschema.lua --- a/util/jsonschema.lua Wed Jan 12 10:23:13 2022 +0100 +++ b/util/jsonschema.lua Sat Jun 17 17:12:54 2023 +0200 @@ -199,11 +199,11 @@ if type(data) == "table" then - if schema.maxItems and #data > schema.maxItems then + if schema.maxItems and #(data) > schema.maxItems then return false end - if schema.minItems and #data < schema.minItems then + if schema.minItems and #(data) < schema.minItems then return false end @@ -303,7 +303,7 @@ end if schema.items ~= nil then - for i = p + 1, #data do + for i = p + 1, #(data) do if not validate(schema.items, data[i], root) then return false end @@ -312,7 +312,7 @@ if schema.contains ~= nil then local found = 0 - for i = 1, #data do + for i = 1, #(data) do if validate(schema.contains, data[i], root) then found = found + 1 end