Software /
code /
prosody
Comparison
spec/util_datamapper_spec.lua @ 12580:a9dbf657c894 0.12
util.datamapper: Improve handling of schemas with non-obvious "type"
The JSON Schema specification says that schemas are objects or booleans,
and that the 'type' property is optional and can be an array.
This module previously allowed bare type names as schemas and did not
really handle booleans.
It now handles missing 'type' properties and boolean 'true' as a schema.
Objects and arrays are guessed based on the presence of 'properties' or
'items' field.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 08 Jul 2022 17:32:48 +0200 |
parent | 12134:912614c4bf3e |
child | 12818:74ed772ff5fb |
comparison
equal
deleted
inserted
replaced
12579:ca6a43fe0231 | 12580:a9dbf657c894 |
---|---|
23 properties = { | 23 properties = { |
24 to = attr(); | 24 to = attr(); |
25 from = attr(); | 25 from = attr(); |
26 type = attr(); | 26 type = attr(); |
27 id = attr(); | 27 id = attr(); |
28 body = "string"; | 28 body = true; -- should be assumed to be a string |
29 lang = {type = "string"; xml = {attribute = true; prefix = "xml"}}; | 29 lang = {type = "string"; xml = {attribute = true; prefix = "xml"}}; |
30 delay = { | 30 delay = { |
31 type = "object"; | 31 type = "object"; |
32 xml = {namespace = "urn:xmpp:delay"; name = "delay"}; | 32 xml = {namespace = "urn:xmpp:delay"; name = "delay"}; |
33 properties = {stamp = attr(); from = attr(); reason = {type = "string"; xml = {text = true}}}; | 33 properties = {stamp = attr(); from = attr(); reason = {type = "string"; xml = {text = true}}}; |
54 react = { | 54 react = { |
55 type = "object"; | 55 type = "object"; |
56 xml = {namespace = "urn:xmpp:reactions:0"; name = "reactions"}; | 56 xml = {namespace = "urn:xmpp:reactions:0"; name = "reactions"}; |
57 properties = { | 57 properties = { |
58 to = {type = "string"; xml = {attribute = true; name = "id"}}; | 58 to = {type = "string"; xml = {attribute = true; name = "id"}}; |
59 reactions = {type = "array"; items = {type = "string"; xml = {name = "reaction"}}}; | 59 -- should be assumed to be array since it has 'items' |
60 reactions = { items = { xml = { name = "reaction" } } }; | |
60 }; | 61 }; |
61 }; | 62 }; |
62 stanza_ids = { | 63 stanza_ids = { |
63 type = "array"; | 64 type = "array"; |
64 items = { | 65 items = { |
188 type = {type = "string"; xml = {attribute = true}}; | 189 type = {type = "string"; xml = {attribute = true}}; |
189 id = {type = "string"; xml = {attribute = true}}; | 190 id = {type = "string"; xml = {attribute = true}}; |
190 version = { | 191 version = { |
191 type = "object"; | 192 type = "object"; |
192 xml = {name = "query"; namespace = "jabber:iq:version"}; | 193 xml = {name = "query"; namespace = "jabber:iq:version"}; |
193 properties = {name = "string"; version = "string"; os = "string"}; | 194 -- properties should be assumed to be strings |
195 properties = {name = true; version = {}; os = {}}; | |
194 }; | 196 }; |
195 }; | 197 }; |
196 }; | 198 }; |
197 local ver_st = st.iq({type = "result"; id = "v1"}) | 199 local ver_st = st.iq({type = "result"; id = "v1"}) |
198 :query("jabber:iq:version") | 200 :query("jabber:iq:version") |