Software / code / prosody
Comparison
util/jsonschema.lua @ 13162:6140aa67c618
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.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 17 Jun 2023 17:12:54 +0200 |
| parent | 13088:0fbb2b3fd4c0 |
| child | 13163:f43d04653bcf |
comparison
equal
deleted
inserted
replaced
| 13161:9ba11ef91ce4 | 13162:6140aa67c618 |
|---|---|
| 197 return false | 197 return false |
| 198 end | 198 end |
| 199 | 199 |
| 200 if type(data) == "table" then | 200 if type(data) == "table" then |
| 201 | 201 |
| 202 if schema.maxItems and #data > schema.maxItems then | 202 if schema.maxItems and #(data) > schema.maxItems then |
| 203 return false | 203 return false |
| 204 end | 204 end |
| 205 | 205 |
| 206 if schema.minItems and #data < schema.minItems then | 206 if schema.minItems and #(data) < schema.minItems then |
| 207 return false | 207 return false |
| 208 end | 208 end |
| 209 | 209 |
| 210 if schema.required then | 210 if schema.required then |
| 211 for _, k in ipairs(schema.required) do | 211 for _, k in ipairs(schema.required) do |
| 301 end | 301 end |
| 302 end | 302 end |
| 303 end | 303 end |
| 304 | 304 |
| 305 if schema.items ~= nil then | 305 if schema.items ~= nil then |
| 306 for i = p + 1, #data do | 306 for i = p + 1, #(data) do |
| 307 if not validate(schema.items, data[i], root) then | 307 if not validate(schema.items, data[i], root) then |
| 308 return false | 308 return false |
| 309 end | 309 end |
| 310 end | 310 end |
| 311 end | 311 end |
| 312 | 312 |
| 313 if schema.contains ~= nil then | 313 if schema.contains ~= nil then |
| 314 local found = 0 | 314 local found = 0 |
| 315 for i = 1, #data do | 315 for i = 1, #(data) do |
| 316 if validate(schema.contains, data[i], root) then | 316 if validate(schema.contains, data[i], root) then |
| 317 found = found + 1 | 317 found = found + 1 |
| 318 end | 318 end |
| 319 end | 319 end |
| 320 if found < (schema.minContains or 1) or found > (schema.maxContains or math.huge) then | 320 if found < (schema.minContains or 1) or found > (schema.maxContains or math.huge) then |