Comparison

teal-src/util/datamapper.tl @ 11462:d1982b7eb00d

util.datamapper: Fix arrays nesting one level too deep
author Kim Alvefur <zash@zash.se>
date Fri, 19 Mar 2021 01:17:59 +0100
parent 11461:766b0eddd12c
child 11464:6e25409fecbd
comparison
equal deleted inserted replaced
11461:766b0eddd12c 11462:d1982b7eb00d
214 else 214 else
215 error "top-level scalars unsupported" 215 error "top-level scalars unsupported"
216 end 216 end
217 end 217 end
218 218
219 local function unparse ( schema : json_schema_object, t : table, current_name : string, current_ns : string ) : st.stanza_t 219 local function unparse ( schema : json_schema_object, t : table, current_name : string, current_ns : string, ctx : st.stanza_t ) : st.stanza_t
220 220
221 if schema.xml then 221 if schema.xml then
222 if schema.xml.name then 222 if schema.xml.name then
223 current_name = schema.xml.name 223 current_name = schema.xml.name
224 end 224 end
226 current_ns = schema.xml.namespace 226 current_ns = schema.xml.namespace
227 end 227 end
228 -- TODO prefix? 228 -- TODO prefix?
229 end 229 end
230 230
231 local out = st.stanza(current_name, { xmlns = current_ns }) 231 local out = ctx or st.stanza(current_name, { xmlns = current_ns })
232 232
233 if schema.type == "object" then 233 if schema.type == "object" then
234 234
235 for prop, propschema in pairs(schema.properties) do 235 for prop, propschema in pairs(schema.properties) do
236 local v = t[prop] 236 local v = t[prop]
301 local c = unparse(propschema, v, name, namespace); 301 local c = unparse(propschema, v, name, namespace);
302 if c then 302 if c then
303 out:add_direct_child(c); 303 out:add_direct_child(c);
304 end 304 end
305 elseif proptype == "array" and propschema is json_schema_object and v is table then 305 elseif proptype == "array" and propschema is json_schema_object and v is table then
306 local c = unparse(propschema, v, name, namespace); 306 if value_where == "in_wrapper" then
307 if c then 307 local c = unparse(propschema, v, name, namespace);
308 if value_where == "in_wrapper" then 308 if c then
309 local w = st.stanza(propschema.xml.name or name, { xmlns = propschema.xml.namespace or namespace })
310 w:add_direct_child(c);
311 out:add_direct_child(w);
312 else
313 out:add_direct_child(c); 309 out:add_direct_child(c);
314 end 310 end
311 else
312 unparse(propschema, v, name, namespace, out);
315 end 313 end
316 else 314 else
317 error "NYI" 315 error "NYI"
318 end 316 end
319 end 317 end