diff options
author | Kim Alvefur <zash@zash.se> | 2021-03-22 10:05:41 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2021-03-22 10:05:41 +0100 |
commit | 6f0532b89f16874878dde97319d14970c535f5de (patch) | |
tree | a1181c4af3cac63dd66d955501e4b6254425a66c /util | |
parent | f68d29bafdfce1a5deff8608c543158a4524ae91 (diff) | |
download | prosody-6f0532b89f16874878dde97319d14970c535f5de.tar.gz prosody-6f0532b89f16874878dde97319d14970c535f5de.zip |
util.datamapper: Handle nested arrays or objects in arrays
Diffstat (limited to 'util')
-rw-r--r-- | util/datamapper.lua | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/util/datamapper.lua b/util/datamapper.lua index d989c75f..96b4a42e 100644 --- a/util/datamapper.lua +++ b/util/datamapper.lua @@ -156,17 +156,35 @@ function parse_object(schema, s) end function parse_array(schema, s) - local proptype, value_where, child_name, namespace, prefix, single_attribute, enums = unpack_propschema(schema.items, nil, s.attr.xmlns) + local itemschema = schema.items; + local proptype, value_where, child_name, namespace, prefix, single_attribute, enums = unpack_propschema(itemschema, nil, s.attr.xmlns) local attr_name if value_where == "in_single_attribute" then value_where = "in_attribute"; attr_name = single_attribute; end local out = {} - for c in s:childtags(child_name, namespace) do - local value = extract_value(c, value_where, proptype, attr_name or child_name, namespace, prefix, single_attribute, enums) - table.insert(out, totype(proptype, value)); + if proptype == "object" then + if type(itemschema) == "table" then + for c in s:childtags(child_name, namespace) do + table.insert(out, parse_object(itemschema, c)); + end + else + error("array items must be schema object") + end + elseif proptype == "array" then + if type(itemschema) == "table" then + for c in s:childtags(child_name, namespace) do + table.insert(out, parse_array(itemschema, c)); + end + end + else + for c in s:childtags(child_name, namespace) do + local value = extract_value(c, value_where, proptype, attr_name or child_name, namespace, prefix, single_attribute, enums) + + table.insert(out, totype(proptype, value)); + end end return out end |