# HG changeset patch # User Kim Alvefur # Date 1615253700 -3600 # Node ID 95f0d77175caa99ee2f4c630858a5632932f616f # Parent 75a280e6e046f50b079163ccf7c17c18fccf2a27 util.jsonschema: Implement the "contains" keyword And apparently I had mistaken this for an array diff -r 75a280e6e046 -r 95f0d77175ca teal-src/util/jsonschema.tl --- 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 diff -r 75a280e6e046 -r 95f0d77175ca util/jsonschema.lua --- a/util/jsonschema.lua Tue Mar 09 02:33:28 2021 +0100 +++ b/util/jsonschema.lua Tue Mar 09 02:35:00 2021 +0100 @@ -205,6 +205,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