Comparison

mod_rest/jsonmap.lib.lua @ 3894:14a32224900c

mod_rest: Rename table of mappings The later items aren't very simple.
author Kim Alvefur <zash@zash.se>
date Sat, 22 Feb 2020 13:35:58 +0100
parent 3889:59765d1bb6dc
child 3895:25a3ad36ef3e
comparison
equal deleted inserted replaced
3893:3f20b7c88afb 3894:14a32224900c
103 end 103 end
104 end 104 end
105 return form; 105 return form;
106 end 106 end
107 107
108 local simple_types = { 108 local field_mappings = {
109 -- top level stanza attributes 109 -- top level stanza attributes
110 -- needed here to mark them as known fields 110 -- needed here to mark them as known fields
111 kind = "attr", 111 kind = "attr",
112 type = "attr", 112 type = "attr",
113 to = "attr", 113 to = "attr",
409 by = error.attr.by, 409 by = error.attr.by,
410 }; 410 };
411 return t; 411 return t;
412 end 412 end
413 413
414 for k, typ in pairs(simple_types) do 414 for k, typ in pairs(field_mappings) do
415 if typ == "text_tag" then 415 if typ == "text_tag" then
416 t[k] = s:get_child_text(k); 416 t[k] = s:get_child_text(k);
417 elseif typ[1] == "text_tag" then 417 elseif typ[1] == "text_tag" then
418 t[k] = s:get_child_text(typ[3], typ[2]); 418 t[k] = s:get_child_text(typ[3], typ[2]);
419 elseif typ[1] == "name" then 419 elseif typ[1] == "name" then
485 s:text_tag("error", t.body, { code = t.error_code and tostring(t.error_code) }); 485 s:text_tag("error", t.body, { code = t.error_code and tostring(t.error_code) });
486 return s; 486 return s;
487 end 487 end
488 488
489 for k, v in pairs(t) do 489 for k, v in pairs(t) do
490 local typ = simple_types[k]; 490 local typ = field_mappings[k];
491 if typ then 491 if typ then
492 if typ == "text_tag" then 492 if typ == "text_tag" then
493 s:text_tag(k, v); 493 s:text_tag(k, v);
494 elseif typ == "attr" then -- luacheck: ignore 542 494 elseif typ == "attr" then -- luacheck: ignore 542
495 -- handled already 495 -- handled already