Comparison

spec/util_datamapper_spec.lua @ 12133:11060c8919b6

util.datamapper: Add support for $ref pointers Allows reuse of repetitive definitions in schemas.
author Kim Alvefur <zash@zash.se>
date Wed, 29 Dec 2021 17:57:09 +0100
parent 11494:284c822d4c3d
child 12134:912614c4bf3e
comparison
equal deleted inserted replaced
12132:4ff0d33dfb2b 12133:11060c8919b6
13 local s, x, d 13 local s, x, d
14 local disco, disco_info, disco_schema 14 local disco, disco_info, disco_schema
15 setup(function() 15 setup(function()
16 16
17 -- a convenience function for simple attributes, there's a few of them 17 -- a convenience function for simple attributes, there's a few of them
18 local function attr() return {type = "string"; xml = {attribute = true}} end 18 local function attr() return {["$ref"]="#/$defs/attr"} end
19 s = { 19 s = {
20 ["$defs"] = { attr = { type = "string"; xml = { attribute = true } } };
20 type = "object"; 21 type = "object";
21 xml = {name = "message"; namespace = "jabber:client"}; 22 xml = {name = "message"; namespace = "jabber:client"};
22 properties = { 23 properties = {
23 to = attr(); 24 to = attr();
24 from = attr(); 25 from = attr();
109 }; 110 };
110 }; 111 };
111 }; 112 };
112 113
113 disco_schema = { 114 disco_schema = {
115 ["$defs"] = { attr = { type = "string"; xml = { attribute = true } } };
114 type = "object"; 116 type = "object";
115 xml = { 117 xml = {
116 name = "iq"; 118 name = "iq";
117 namespace = "jabber:client" 119 namespace = "jabber:client"
118 }; 120 };