# HG changeset patch # User Kim Alvefur # Date 1615253608 -3600 # Node ID 75a280e6e046f50b079163ccf7c17c18fccf2a27 # Parent d5288c99bb5a9a823c82aa2df3dd9450805b435e util.jsonschema: Allow a boolean as schema Apparently a schema must be either an object or a boolean. Not sure where I got this string shortcut from, but I think I will keep it as it is very convenient. diff -r d5288c99bb5a -r 75a280e6e046 teal-src/util/jsonschema.tl --- a/teal-src/util/jsonschema.tl Tue Mar 09 02:26:05 2021 +0100 +++ b/teal-src/util/jsonschema.tl Tue Mar 09 02:33:28 2021 +0100 @@ -136,7 +136,10 @@ type_validators.integer = type_validators.number -local function validate(schema : schema_t | type_e, data : any) : boolean +local function validate(schema : schema_t | type_e | boolean, data : any) : boolean + if schema is boolean then + return schema + end if schema is type_e then return simple_validate(schema, data) end diff -r d5288c99bb5a -r 75a280e6e046 util/jsonschema.lua --- a/util/jsonschema.lua Tue Mar 09 02:26:05 2021 +0100 +++ b/util/jsonschema.lua Tue Mar 09 02:33:28 2021 +0100 @@ -57,6 +57,9 @@ type_validators.integer = type_validators.number local function validate(schema, data) + if type(schema) == "boolean" then + return schema + end if type(schema) == "string" then return simple_validate(schema, data) end