Changeset

11441:75a280e6e046

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.
author Kim Alvefur <zash@zash.se>
date Tue, 09 Mar 2021 02:33:28 +0100
parents 11440:d5288c99bb5a
children 11442:95f0d77175ca
files teal-src/util/jsonschema.tl util/jsonschema.lua
diffstat 2 files changed, 7 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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