# HG changeset patch # User Kim Alvefur # Date 1671569308 -3600 # Node ID 048e339706ba6f6b53c07fca4cce907ce086252b # Parent 7bce75e74f86ad223339dcd5a48fb93926b3cd98 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. diff -r 7bce75e74f86 -r 048e339706ba mod_rest/jsonmap.lib.lua --- a/mod_rest/jsonmap.lib.lua Sun Dec 18 15:30:02 2022 +0100 +++ b/mod_rest/jsonmap.lib.lua Tue Dec 20 21:48:28 2022 +0100 @@ -16,13 +16,6 @@ copyto.properties[key] = prop; end end - schema.properties.message.properties.archive.properties.forward = schema.properties.message.properties.forwarded; - schema.properties.message.properties.forwarded.properties.delay = schema._common.delay; - schema.properties.message.properties.forwarded.properties.message = schema.properties.message; - schema.properties.iq.properties.archive.properties.form = schema._common.dataform; - schema.properties.iq.properties.archive.properties.page = schema._common.rsm; - schema.properties.iq.properties.result.properties.page = schema._common.rsm; - schema._common = nil; end end @@ -406,9 +399,21 @@ end return { xmpp = result }; end - local t = map.parse(schema.properties[s.name], s); - t.kind = s.name; + local t; + do + local wrap_s = st.stanza("xmpp", { xmlns = "jabber:client" }):add_child(s); + local wrap_t = map.parse(schema, wrap_s); + if not wrap_t then + return nil, "parse"; + end + local kind; + kind, t = next(wrap_t); + if kind == nil then + return nil, "parse"; + end + t.kind = kind; + end if s.name == "presence" and not s.attr.type then t.type = "available"; diff -r 7bce75e74f86 -r 048e339706ba mod_rest/res/schema-xmpp.json --- a/mod_rest/res/schema-xmpp.json Sun Dec 18 15:30:02 2022 +0100 +++ b/mod_rest/res/schema-xmpp.json Tue Dec 20 21:48:28 2022 +0100 @@ -406,6 +406,9 @@ "namespace" : "jabber:iq:oob" } }, + "payload" : { + "$ref" : "#/_common/payload" + }, "ping" : { "description" : "Test reachability of some XMPP address", "enum" : [ @@ -865,6 +868,9 @@ "namespace" : "jabber:x:oob" } }, + "payload" : { + "$ref" : "#/_common/payload" + }, "reactions" : { "properties" : { "id" : {