Changeset

5119:048e339706ba

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.
author Kim Alvefur <zash@zash.se>
date Tue, 20 Dec 2022 21:48:28 +0100
parents 5118:7bce75e74f86
children 5120:83afe4078e6e
files mod_rest/jsonmap.lib.lua mod_rest/res/schema-xmpp.json
diffstat 2 files changed, 20 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- 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";
--- 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" : {