aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-03-20 21:29:51 +0100
committerKim Alvefur <zash@zash.se>2021-03-20 21:29:51 +0100
commit4f191a323991dcfd5dae3c7a0b68a0c83715625f (patch)
tree42a1bee41dc8ca1ff0a8c205ec3a38dc574bee79
parent366edae2398710b57e4febd8101b238eff414e57 (diff)
downloadprosody-4f191a323991dcfd5dae3c7a0b68a0c83715625f.tar.gz
prosody-4f191a323991dcfd5dae3c7a0b68a0c83715625f.zip
util.datamapper: Complete array building support
-rw-r--r--spec/util_datamapper_spec.lua11
-rw-r--r--teal-src/util/datamapper.tl15
-rw-r--r--util/datamapper.lua15
3 files changed, 17 insertions, 24 deletions
diff --git a/spec/util_datamapper_spec.lua b/spec/util_datamapper_spec.lua
index cbb579dc..37b3e3b6 100644
--- a/spec/util_datamapper_spec.lua
+++ b/spec/util_datamapper_spec.lua
@@ -181,5 +181,16 @@ describe("util.datampper", function()
assert.equal(#x.tags-1, #u.tags)
end);
+
+ it("handles arrays", function ()
+ local u = map.unparse(disco_schema, disco);
+ assert.equal("urn:example:feature:1", u:find("{http://jabber.org/protocol/disco#info}query/feature/@var"))
+ local n = 0;
+ for child in u:get_child("query", "http://jabber.org/protocol/disco#info"):childtags("feature") do
+ n = n + 1;
+ assert.equal(string.format("urn:example:feature:%d", n), child.attr.var);
+ end
+ end);
+
end);
end)
diff --git a/teal-src/util/datamapper.tl b/teal-src/util/datamapper.tl
index 2c1b05dc..75b65afd 100644
--- a/teal-src/util/datamapper.tl
+++ b/teal-src/util/datamapper.tl
@@ -323,18 +323,9 @@ function unparse ( schema : json_schema_object, t : table, current_name : string
return out;
elseif schema.type == "array" then
- local proptype, value_where, name, namespace = unpack_propschema(schema.items, current_name, current_ns)
- -- TODO , prefix, single_attribute
- if proptype == "string" then
- for _, item in ipairs(t as { string }) do
- if value_where == "in_text_tag" then
- out:text_tag(name, item, { xmlns = namespace });
- else
- error "NYI"
- end
- end
- else
- error "NYI"
+ local proptype, value_where, name, namespace, prefix, single_attribute = unpack_propschema(schema.items, current_name, current_ns)
+ for _, item in ipairs(t as { string }) do
+ unparse_property(out, item, proptype, schema.items, value_where, name, namespace, current_ns, prefix, single_attribute)
end
return out;
end
diff --git a/util/datamapper.lua b/util/datamapper.lua
index 66e3fe7b..65fa8e36 100644
--- a/util/datamapper.lua
+++ b/util/datamapper.lua
@@ -290,18 +290,9 @@ function unparse(schema, t, current_name, current_ns, ctx)
return out
elseif schema.type == "array" then
- local proptype, value_where, name, namespace = unpack_propschema(schema.items, current_name, current_ns)
-
- if proptype == "string" then
- for _, item in ipairs(t) do
- if value_where == "in_text_tag" then
- out:text_tag(name, item, {xmlns = namespace});
- else
- error("NYI")
- end
- end
- else
- error("NYI")
+ local proptype, value_where, name, namespace, prefix, single_attribute = unpack_propschema(schema.items, current_name, current_ns)
+ for _, item in ipairs(t) do
+ unparse_property(out, item, proptype, schema.items, value_where, name, namespace, current_ns, prefix, single_attribute)
end
return out
end