comparison mod_rest/jsonmap.lib.lua @ 5119:048e339706ba

mod_rest: Remove manual reference expansion in schema This hack was originally added to reduce the number of definitions of common attributes (type, to, from etc) and payloads (e.g. delay). This predated pointers and references, and until now was needed because parsing picked out the correct stanza kind from the schema, which broke internal references. Removing this hack paves the way for allowing the schema to be configured or customized more easily.
author Kim Alvefur <zash@zash.se>
date Tue, 20 Dec 2022 21:48:28 +0100
parents b171ddf1bc3e
children e5b5a74feb91
comparison
equal deleted inserted replaced
5118:7bce75e74f86 5119:048e339706ba
14 for key, prop in pairs(schema._common) do 14 for key, prop in pairs(schema._common) do
15 for _, copyto in pairs(schema.properties) do 15 for _, copyto in pairs(schema.properties) do
16 copyto.properties[key] = prop; 16 copyto.properties[key] = prop;
17 end 17 end
18 end 18 end
19 schema.properties.message.properties.archive.properties.forward = schema.properties.message.properties.forwarded;
20 schema.properties.message.properties.forwarded.properties.delay = schema._common.delay;
21 schema.properties.message.properties.forwarded.properties.message = schema.properties.message;
22 schema.properties.iq.properties.archive.properties.form = schema._common.dataform;
23 schema.properties.iq.properties.archive.properties.page = schema._common.rsm;
24 schema.properties.iq.properties.result.properties.page = schema._common.rsm;
25 schema._common = nil;
26 end 19 end
27 end 20 end
28 21
29 -- Some mappings that are still hard to do in a nice way with util.datamapper 22 -- Some mappings that are still hard to do in a nice way with util.datamapper
30 local field_mappings; -- in scope for "func" mappings 23 local field_mappings; -- in scope for "func" mappings
404 for child in s:childtags() do 397 for child in s:childtags() do
405 result:push(st2json(child)); 398 result:push(st2json(child));
406 end 399 end
407 return { xmpp = result }; 400 return { xmpp = result };
408 end 401 end
409 local t = map.parse(schema.properties[s.name], s); 402
410 403 local t;
411 t.kind = s.name; 404 do
405 local wrap_s = st.stanza("xmpp", { xmlns = "jabber:client" }):add_child(s);
406 local wrap_t = map.parse(schema, wrap_s);
407 if not wrap_t then
408 return nil, "parse";
409 end
410 local kind;
411 kind, t = next(wrap_t);
412 if kind == nil then
413 return nil, "parse";
414 end
415 t.kind = kind;
416 end
412 417
413 if s.name == "presence" and not s.attr.type then 418 if s.name == "presence" and not s.attr.type then
414 t.type = "available"; 419 t.type = "available";
415 end 420 end
416 421