Software /
code /
prosody
Diff
teal-src/util/jsonschema.tl @ 11442:95f0d77175ca
util.jsonschema: Implement the "contains" keyword
And apparently I had mistaken this for an array
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 09 Mar 2021 02:35:00 +0100 |
parent | 11441:75a280e6e046 |
child | 11443:a526abef61e6 |
line wrap: on
line diff
--- a/teal-src/util/jsonschema.tl Tue Mar 09 02:33:28 2021 +0100 +++ b/teal-src/util/jsonschema.tl Tue Mar 09 02:35:00 2021 +0100 @@ -38,7 +38,7 @@ -- arrays items : schema_t - contains : { schema_t } + contains : schema_t maxItems : number minItems : number uniqueItems : boolean @@ -285,6 +285,19 @@ end end + if schema.contains then + local found = false + for i = 1, #data do + if validate(schema.contains, data[i]) then + found = true + break + end + end + if not found then + return false + end + end + return true end return false