Merge pull request #18 from matrix-org/event-schemas

Event schemas
templating
Kegsay 9 years ago
commit 4f0073105f

@ -0,0 +1,13 @@
Testing a schema
----------------
There are [many](http://json-schema.org/implementations.html) JSON Schema
validators you can use to validate incoming events. Not all of them support
JSON Schema v4, and some of them have bugs which prevent ``$ref`` from being
resolved correctly. For basic CLI testing, we recommend and have verified they
work with the Node.js package [z-schema](https://github.com/zaggino/z-schema):
```
$ npm install -g z-schema
$ z-schema schema/v1/m.room.message examples/v1/m.room.message_m.text
schema validation passed
json #1 validation passed
```

@ -0,0 +1,17 @@
{
"age": 242352,
"content": {
"version" : 0,
"call_id": "12345",
"lifetime": 60000,
"answer": {
"type" : "answer",
"sdp" : "v=0\r\no=- 6584580628695956864 2 IN IP4 127.0.0.1[...]"
}
},
"origin_server_ts": 1431961217939,
"event_id": "$WLGTSEFSEF:localhost",
"type": "m.call.answer",
"room_id": "!Cuyf34gef24t:localhost",
"user_id": "@example:localhost"
}

@ -0,0 +1,19 @@
{
"age": 242352,
"content": {
"version" : 0,
"call_id": "12345",
"candidates": [
{
"sdpMid": "audio",
"sdpMLineIndex": 0,
"candidate": "candidate:863018703 1 udp 2122260223 10.9.64.156 43670 typ host generation 0"
}
]
},
"origin_server_ts": 1431961217939,
"event_id": "$WLGTSEFSEF:localhost",
"type": "m.call.candidates",
"room_id": "!Cuyf34gef24t:localhost",
"user_id": "@example:localhost"
}

@ -0,0 +1,12 @@
{
"age": 242352,
"content": {
"version" : 0,
"call_id": "12345"
},
"origin_server_ts": 1431961217939,
"event_id": "$WLGTSEFSEF:localhost",
"type": "m.call.hangup",
"room_id": "!Cuyf34gef24t:localhost",
"user_id": "@example:localhost"
}

@ -0,0 +1,17 @@
{
"age": 242352,
"content": {
"version" : 0,
"call_id": "12345",
"lifetime": 60000,
"offer": {
"type" : "offer",
"sdp" : "v=0\r\no=- 6584580628695956864 2 IN IP4 127.0.0.1[...]"
}
},
"origin_server_ts": 1431961217939,
"event_id": "$WLGTSEFSEF:localhost",
"type": "m.call.invite",
"room_id": "!Cuyf34gef24t:localhost",
"user_id": "@example:localhost"
}

@ -0,0 +1,10 @@
{
"content": {
"avatar_url": "mxc://localhost:wefuiwegh8742w",
"last_active_ago": 2478593,
"presence": "online",
"user_id": "@example:localhost"
},
"event_id": "$WLGTSEFSEF:localhost",
"type": "m.presence"
}

@ -0,0 +1,12 @@
{
"age": 242352,
"content": {
"aliases": ["#somewhere:localhost", "#another:localhost"]
},
"state_key": "localhost",
"origin_server_ts": 1431961217939,
"event_id": "$WLGTSEFSEF:localhost",
"type": "m.room.aliases",
"room_id": "!Cuyf34gef24t:localhost",
"user_id": "@example:localhost"
}

@ -0,0 +1,12 @@
{
"age": 242352,
"content": {
"creator": "@example:localhost"
},
"state_key": "",
"origin_server_ts": 1431961217939,
"event_id": "$WLGTSEFSEF:localhost",
"type": "m.room.create",
"room_id": "!Cuyf34gef24t:localhost",
"user_id": "@example:localhost"
}

@ -0,0 +1,12 @@
{
"age": 242352,
"content": {
"join_rule": "public"
},
"state_key": "",
"origin_server_ts": 1431961217939,
"event_id": "$WLGTSEFSEF:localhost",
"type": "m.room.join_rules",
"room_id": "!Cuyf34gef24t:localhost",
"user_id": "@example:localhost"
}

@ -0,0 +1,12 @@
{
"age": 242352,
"content": {
"membership": "join"
},
"state_key": "@alice:localhost",
"origin_server_ts": 1431961217939,
"event_id": "$WLGTSEFSEF:localhost",
"type": "m.room.member",
"room_id": "!Cuyf34gef24t:localhost",
"user_id": "@example:localhost"
}

@ -0,0 +1,12 @@
{
"age": 242352,
"content": {
"type": "delivered",
"target_event_id": "$WEIGFHFW:localhost"
},
"origin_server_ts": 1431961217939,
"event_id": "$WLGTSEFSEF:localhost",
"type": "m.room.message.feedback",
"room_id": "!Cuyf34gef24t:localhost",
"user_id": "@example:localhost"
}

@ -0,0 +1,12 @@
{
"age": 242352,
"content": {
"body": "thinks this is an example emote",
"msgtype": "m.emote"
},
"origin_server_ts": 1431961217939,
"event_id": "$WLGTSEFSEF:localhost",
"type": "m.room.message",
"room_id": "!Cuyf34gef24t:localhost",
"user_id": "@example:localhost"
}

@ -0,0 +1,19 @@
{
"age": 242352,
"content": {
"body": "filename.jpg",
"info": {
"h": 398,
"w": 394,
"mimetype": "image/jpeg",
"size": 31037
},
"url": "mxc://localhost/JWEIFJgwEIhweiWJE",
"msgtype": "m.image"
},
"origin_server_ts": 1431961217939,
"event_id": "$WLGTSEFSEF:localhost",
"type": "m.room.message",
"room_id": "!Cuyf34gef24t:localhost",
"user_id": "@example:localhost"
}

@ -0,0 +1,12 @@
{
"age": 242352,
"content": {
"body": "This is an example notice",
"msgtype": "m.notice"
},
"origin_server_ts": 1431961217939,
"event_id": "$WLGTSEFSEF:localhost",
"type": "m.room.message",
"room_id": "!Cuyf34gef24t:localhost",
"user_id": "@example:localhost"
}

@ -0,0 +1,12 @@
{
"age": 242352,
"content": {
"body": "This is an example text message",
"msgtype": "m.text"
},
"origin_server_ts": 1431961217939,
"event_id": "$WLGTSEFSEF:localhost",
"type": "m.room.message",
"room_id": "!Cuyf34gef24t:localhost",
"user_id": "@example:localhost"
}

@ -0,0 +1,12 @@
{
"age": 242352,
"content": {
"name": "The room name"
},
"state_key": "",
"origin_server_ts": 1431961217939,
"event_id": "$WLGTSEFSEF:localhost",
"type": "m.room.name",
"room_id": "!Cuyf34gef24t:localhost",
"user_id": "@example:localhost"
}

@ -0,0 +1,24 @@
{
"age": 242352,
"content": {
"ban": 50,
"events": {
"m.room.name": 100,
"m.room.power_levels": 100
},
"events_default": 0,
"kick": 50,
"redact": 50,
"state_default": 50,
"users": {
"@example:localhost": 100
},
"users_default": 0
},
"state_key": "",
"origin_server_ts": 1431961217939,
"event_id": "$WLGTSEFSEF:localhost",
"type": "m.room.power_levels",
"room_id": "!Cuyf34gef24t:localhost",
"user_id": "@example:localhost"
}

@ -0,0 +1,10 @@
{
"age": 242352,
"content": {},
"origin_server_ts": 1431961217939,
"event_id": "$WLGTSEFSEF:localhost",
"type": "m.room.redaction",
"room_id": "!Cuyf34gef24t:localhost",
"redacts": "!fukweghifu23:localhost",
"user_id": "@example:localhost"
}

@ -0,0 +1,12 @@
{
"age": 242352,
"content": {
"topic": "A room topic"
},
"state_key": "",
"origin_server_ts": 1431961217939,
"event_id": "$WLGTSEFSEF:localhost",
"type": "m.room.topic",
"room_id": "!Cuyf34gef24t:localhost",
"user_id": "@example:localhost"
}

@ -0,0 +1,61 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"definitions": {
"event": {
"title": "Event",
"description": "The basic set of fields all events must have.",
"type": "object",
"properties": {
"event_id": {
"type": "string",
"description": "The globally unique event identifier."
},
"user_id": {
"type": "string"
},
"content": {
"type": "object",
"description": "The fields in this object will vary depending on the type of event."
},
"type": {
"type": "string",
"description": "The type of event. This SHOULD be namespaced similar to Java package naming conventions e.g. 'com.example.subdomain.event.type'"
}
},
"required": ["event_id", "user_id", "content", "type"]
},
"room_event": {
"type": "object",
"title": "Room Event",
"description": "The basic set of fields all room events must have.",
"allOf":[{
"$ref": "#/definitions/event"
}],
"properties": {
"room_id": {
"type": "string"
}
},
"required": ["room_id"]
},
"state_event": {
"type": "object",
"title": "State Event",
"description": "The basic set of fields which define a room state event.",
"allOf":[{
"$ref": "#/definitions/room_event"
}],
"properties": {
"state_key": {
"type": "string",
"description": "A unique key which defines the overwriting semantics for this piece of room state. This value is often a 0-length string."
},
"prev_content": {
"type": "object",
"description": "The previous content if this event has overwritten another event."
}
},
"required": ["state_key"]
}
}
}

@ -0,0 +1,38 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"allOf": [{
"$ref": "core#/definitions/room_event"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"call_id": {
"type": "string"
},
"answer": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": ["answer"]
},
"sdp": {
"type": "string"
}
},
"required": ["type", "sdp"]
},
"version": {
"type": "number"
}
},
"required": ["call_id", "answer", "version"]
},
"type": {
"type": "string",
"enum": ["m.call.answer"]
}
}
}

@ -0,0 +1,43 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"allOf": [{
"$ref": "core#/definitions/room_event"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"call_id": {
"type": "string"
},
"candidates": {
"type": "array",
"items": {
"type": "object",
"properties": {
"sdpMid": {
"type": "string"
},
"sdpMLineIndex": {
"type": "number"
},
"candidate": {
"type": "string"
}
},
"required": ["candidate", "sdpMLineIndex", "sdpMid"]
}
},
"version": {
"type": "number"
}
},
"required": ["call_id", "candidates", "version"]
},
"type": {
"type": "string",
"enum": ["m.call.candidates"]
}
}
}

@ -0,0 +1,25 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"allOf": [{
"$ref": "core#/definitions/room_event"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"call_id": {
"type": "string"
},
"version": {
"type": "number"
}
},
"required": ["call_id", "version"]
},
"type": {
"type": "string",
"enum": ["m.call.hangup"]
}
}
}

@ -0,0 +1,38 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"allOf": [{
"$ref": "core#/definitions/room_event"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"call_id": {
"type": "string"
},
"offer": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": ["offer"]
},
"sdp": {
"type": "string"
}
},
"required": ["type", "sdp"]
},
"version": {
"type": "number"
}
},
"required": ["call_id", "offer", "version"]
},
"type": {
"type": "string",
"enum": ["m.call.invite"]
}
}
}

@ -0,0 +1,36 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"content": {
"type": "object",
"properties": {
"avatar_url": {
"type": "string"
},
"displayname": {
"type": "string"
},
"last_active_ago": {
"type": "number"
},
"presence": {
"type": "string",
"enum": ["online", "offline", "unavailable", "free_for_chat", "hidden"]
},
"user_id": {
"type": "string"
}
},
"required": ["presence", "user_id"]
},
"type": {
"type": "string",
"enum": ["m.presence"]
},
"event_id": {
"type": "string"
}
},
"required": ["event_id", "type", "content"]
}

@ -0,0 +1,25 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"allOf": [{
"$ref": "core#/definitions/state_event"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"aliases": {
"type": "array",
"items": {
"type": "string"
}
}
},
"required": ["aliases"]
},
"type": {
"type": "string",
"enum": ["m.room.aliases"]
}
}
}

@ -0,0 +1,26 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"allOf": [{
"$ref": "core#/definitions/state_event"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"creator": {
"type": "string"
}
},
"required": ["creator"]
},
"state_key": {
"type": "string",
"pattern": "^$"
},
"type": {
"type": "string",
"enum": ["m.room.create"]
}
}
}

@ -0,0 +1,27 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"allOf": [{
"$ref": "core#/definitions/state_event"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"join_rule": {
"type": "string",
"enum": ["public","knock","invite","private"]
}
},
"required": ["join_rule"]
},
"state_key": {
"type": "string",
"pattern": "^$"
},
"type": {
"type": "string",
"enum": ["m.room.join_rules"]
}
}
}

@ -0,0 +1,26 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"allOf": [{
"$ref": "core#/definitions/state_event"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"membership": {
"type": "string",
"enum": ["invite","join","knock","leave","ban"]
}
},
"required": ["membership"]
},
"state_key": {
"type": "string"
},
"type": {
"type": "string",
"enum": ["m.room.member"]
}
}
}

@ -0,0 +1,25 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"allOf": [{
"$ref": "core#/definitions/room_event"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"msgtype": {
"type": "string"
},
"body": {
"type": "string"
}
},
"required": ["msgtype", "body"]
},
"type": {
"type": "string",
"enum": ["m.room.message"]
}
}
}

@ -0,0 +1,26 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"allOf": [{
"$ref": "core#/definitions/room_event"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": ["delivered", "read"]
},
"target_event_id": {
"type": "string"
}
},
"required": ["type", "target_event_id"]
},
"type": {
"type": "string",
"enum": ["m.room.message.feedback"]
}
}
}

@ -0,0 +1,26 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"allOf": [{
"$ref": "core#/definitions/state_event"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"name": {
"type": "string"
}
},
"required": ["name"]
},
"state_key": {
"type": "string",
"pattern": "^$"
},
"type": {
"type": "string",
"enum": ["m.room.name"]
}
}
}

@ -0,0 +1,42 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"allOf": [{
"$ref": "core#/definitions/state_event"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"ban": { "type": "number" },
"events_default": { "type": "number" },
"kick": { "type": "number" },
"redact": { "type": "number" },
"state_default": { "type": "number" },
"users_default": { "type": "number" },
"events": {
"type": "object",
"additionalProperties": {
"type": "number"
}
},
"users": {
"type": "object",
"additionalProperties": {
"type": "number"
}
}
},
"required": ["ban","events","events_default","kick","redact",
"state_default","users","users_default"]
},
"state_key": {
"type": "string",
"pattern": "^$"
},
"type": {
"type": "string",
"enum": ["m.room.power_levels"]
}
}
}

@ -0,0 +1,25 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"allOf": [{
"$ref": "core#/definitions/room_event"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"reason": {
"type": "string"
}
}
},
"redacts": {
"type": "string"
},
"type": {
"type": "string",
"enum": ["m.room.redaction"]
}
},
"required": ["redacts"]
}

@ -0,0 +1,26 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"allOf": [{
"$ref": "core#/definitions/state_event"
}],
"properties": {
"content": {
"type": "object",
"properties": {
"topic": {
"type": "string"
}
},
"required": ["topic"]
},
"state_key": {
"type": "string",
"pattern": "^$"
},
"type": {
"type": "string",
"enum": ["m.room.topic"]
}
}
}
Loading…
Cancel
Save