Diff

spec/util_datamapper_spec.lua @ 12580:a9dbf657c894 0.12

util.datamapper: Improve handling of schemas with non-obvious "type" The JSON Schema specification says that schemas are objects or booleans, and that the 'type' property is optional and can be an array. This module previously allowed bare type names as schemas and did not really handle booleans. It now handles missing 'type' properties and boolean 'true' as a schema. Objects and arrays are guessed based on the presence of 'properties' or 'items' field.
author Kim Alvefur <zash@zash.se>
date Fri, 08 Jul 2022 17:32:48 +0200
parent 12134:912614c4bf3e
child 12818:74ed772ff5fb
line wrap: on
line diff
--- a/spec/util_datamapper_spec.lua	Fri Jul 08 14:38:23 2022 +0200
+++ b/spec/util_datamapper_spec.lua	Fri Jul 08 17:32:48 2022 +0200
@@ -25,7 +25,7 @@
 				from = attr();
 				type = attr();
 				id = attr();
-				body = "string";
+				body = true; -- should be assumed to be a string
 				lang = {type = "string"; xml = {attribute = true; prefix = "xml"}};
 				delay = {
 					type = "object";
@@ -56,7 +56,8 @@
 					xml = {namespace = "urn:xmpp:reactions:0"; name = "reactions"};
 					properties = {
 						to = {type = "string"; xml = {attribute = true; name = "id"}};
-						reactions = {type = "array"; items = {type = "string"; xml = {name = "reaction"}}};
+						-- should be assumed to be array since it has 'items'
+						reactions = { items = { xml = { name = "reaction" } } };
 					};
 				};
 				stanza_ids = {
@@ -190,7 +191,8 @@
 					version = {
 						type = "object";
 						xml = {name = "query"; namespace = "jabber:iq:version"};
-						properties = {name = "string"; version = "string"; os = "string"};
+						-- properties should be assumed to be strings
+						properties = {name = true; version = {}; os = {}};
 					};
 				};
 			};