From 8f448a176415430203a22783043b73b53c2c81e0 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Wed, 20 May 2015 11:49:10 +0100 Subject: [PATCH] Produce valid JSON (escape \n), add indent filter --- event-schemas/schema/v1/m.room.aliases | 12 +----------- event-schemas/schema/v1/m.room.create | 3 +-- event-schemas/schema/v1/m.room.join_rules | 5 +---- event-schemas/schema/v1/m.room.member | 7 +------ event-schemas/schema/v1/m.room.message | 6 +----- event-schemas/schema/v1/m.room.message.feedback | 9 ++------- event-schemas/schema/v1/m.room.name | 7 +------ event-schemas/schema/v1/m.room.power_levels | 14 +------------- event-schemas/schema/v1/m.room.redaction | 9 +-------- event-schemas/schema/v1/m.room.topic | 6 +----- templating/build.py | 4 ++++ templating/internal/units.py | 2 +- templating/templates/events.tmpl | 2 +- 13 files changed, 17 insertions(+), 69 deletions(-) diff --git a/event-schemas/schema/v1/m.room.aliases b/event-schemas/schema/v1/m.room.aliases index 25f62876..1c86183f 100644 --- a/event-schemas/schema/v1/m.room.aliases +++ b/event-schemas/schema/v1/m.room.aliases @@ -2,17 +2,7 @@ "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "title": "Informs the room about what room aliases it has been given.", - "description": "This event is sent by a homeserver directly to inform of changes - to the list of aliases it knows about for that room. The - ``state_key`` for this event is set to the homeserver which - owns the room alias. The entire set of known aliases for the - room is the union of all the ``m.room.aliases`` events, one - for each homeserver. Clients **should** check the validity - of any room alias given in this list before presenting it to - the user as trusted fact. The lists given by this event - should be considered simply as advice on which aliases - might exist, for which the client can perform the lookup to - confirm whether it receives the correct room ID.", + "description": "This event is sent by a homeserver directly to inform of changes\nto the list of aliases it knows about for that room. The\n``state_key`` for this event is set to the homeserver which\nowns the room alias. The entire set of known aliases for the\nroom is the union of all the ``m.room.aliases`` events, one\nfor each homeserver. Clients **should** check the validity\nof any room alias given in this list before presenting it to\nthe user as trusted fact. The lists given by this event\nshould be considered simply as advice on which aliases\nmight exist, for which the client can perform the lookup to\nconfirm whether it receives the correct room ID.", "allOf": [{ "$ref": "core#/definitions/state_event" }], diff --git a/event-schemas/schema/v1/m.room.create b/event-schemas/schema/v1/m.room.create index bfb4a6a9..c1cd1a39 100644 --- a/event-schemas/schema/v1/m.room.create +++ b/event-schemas/schema/v1/m.room.create @@ -2,8 +2,7 @@ "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "title": "The first event in the room.", - "description": "This is the first event in a room and cannot be changed. It acts - as the root of all other events.", + "description": "This is the first event in a room and cannot be changed. It acts\nas the root of all other events.", "allOf": [{ "$ref": "core#/definitions/state_event" }], diff --git a/event-schemas/schema/v1/m.room.join_rules b/event-schemas/schema/v1/m.room.join_rules index a9c6eb58..ec430ff7 100644 --- a/event-schemas/schema/v1/m.room.join_rules +++ b/event-schemas/schema/v1/m.room.join_rules @@ -2,10 +2,7 @@ "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "title": "Describes how users are allowed to join the room.", - "description": "A room may be ``public`` meaning anyone can join the room without - any prior action. Alternatively, it can be ``invite`` meaning that - a user who wishes to join the room must first receive an invite to - the room from someone already inside of the room.", + "description": "A room may be ``public`` meaning anyone can join the room without\nany prior action. Alternatively, it can be ``invite`` meaning that\na user who wishes to join the room must first receive an invite to\nthe room from someone already inside of the room.", "allOf": [{ "$ref": "core#/definitions/state_event" }], diff --git a/event-schemas/schema/v1/m.room.member b/event-schemas/schema/v1/m.room.member index 71b1fe67..22be8218 100644 --- a/event-schemas/schema/v1/m.room.member +++ b/event-schemas/schema/v1/m.room.member @@ -2,12 +2,7 @@ "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "title": "The current membership state of a user in the room.", - "description": "Adjusts the membership state for a user in a room. It is preferable to use - the membership APIs (``/rooms//invite`` etc) when performing - membership actions rather than adjusting the state directly as there are a - restricted set of valid transformations. For example, user A cannot force - user B to join a room, and trying to force this state change directly will - fail.", + "description": "Adjusts the membership state for a user in a room. It is preferable to use\nthe membership APIs (``/rooms//invite`` etc) when performing\nmembership actions rather than adjusting the state directly as there are a\nrestricted set of valid transformations. For example, user A cannot force\nuser B to join a room, and trying to force this state change directly will\nfail.", "allOf": [{ "$ref": "core#/definitions/state_event" }], diff --git a/event-schemas/schema/v1/m.room.message b/event-schemas/schema/v1/m.room.message index 42dc7439..58e929e6 100644 --- a/event-schemas/schema/v1/m.room.message +++ b/event-schemas/schema/v1/m.room.message @@ -2,11 +2,7 @@ "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "title": "A human-readable message in the room.", - "description": "This event is used when sending messages in a room. Messages are - not limited to be text. The ``msgtype`` key outlines the type - of message, e.g. text, audio, image, video, etc. The ``body`` key - is text and MUST be used with every kind of ``msgtype`` as a - fallback mechanism for when a client cannot render a message.", + "description": "This event is used when sending messages in a room. Messages are\nnot limited to be text. The ``msgtype`` key outlines the type\nof message, e.g. text, audio, image, video, etc. The ``body`` key\nis text and MUST be used with every kind of ``msgtype`` as a \nfallback mechanism for when a client cannot render a message.", "allOf": [{ "$ref": "core#/definitions/room_event" }], diff --git a/event-schemas/schema/v1/m.room.message.feedback b/event-schemas/schema/v1/m.room.message.feedback index 5784d9fd..062581e7 100644 --- a/event-schemas/schema/v1/m.room.message.feedback +++ b/event-schemas/schema/v1/m.room.message.feedback @@ -1,13 +1,8 @@ { "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", - "title": "A receipt for a message. N.B. not implemented in Synapse, and superceded in - v2 CS API by the ``relates_to`` event field.", - "description": "Feedback events are events sent to acknowledge a message in some way. There - are two supported acknowledgements: ``delivered`` (sent when the event has - been received) and ``read`` (sent when the event has been observed by the - end-user). The ``target_event_id`` should reference the ``m.room.message`` - event being acknowledged.", + "title": "A receipt for a message. N.B. not implemented in Synapse, and superceded in\nv2 CS API by the ``relates_to`` event field.", + "description": "Feedback events are events sent to acknowledge a message in some way. There\nare two supported acknowledgements: ``delivered`` (sent when the event has\nbeen received) and ``read`` (sent when the event has been observed by the\nend-user). The ``target_event_id`` should reference the ``m.room.message``\nevent being acknowledged.", "allOf": [{ "$ref": "core#/definitions/room_event" }], diff --git a/event-schemas/schema/v1/m.room.name b/event-schemas/schema/v1/m.room.name index 56fdca9a..cc27c84b 100644 --- a/event-schemas/schema/v1/m.room.name +++ b/event-schemas/schema/v1/m.room.name @@ -1,12 +1,7 @@ { "$schema": "http://json-schema.org/draft-04/schema#", "title": "Set the human-readable name for the room.", - "description": "A room has an opaque room ID which is not human-friendly to read. A room - alias is human-friendly, but not all rooms have room aliases. The room - name is a human-friendly string designed to be displayed to the end-user. - The room name is not unique, as multiple rooms can have the same room name - set. The room name can also be set when creating a room using ``/createRoom`` - with the ``name`` key.", + "description": "A room has an opaque room ID which is not human-friendly to read. A room\nalias is human-friendly, but not all rooms have room aliases. The room \nname is a human-friendly string designed to be displayed to the end-user.\nThe room name is not unique, as multiple rooms can have the same room name\nset. The room name can also be set when creating a room using ``/createRoom`` \nwith the ``name`` key.", "type": "object", "allOf": [{ "$ref": "core#/definitions/state_event" diff --git a/event-schemas/schema/v1/m.room.power_levels b/event-schemas/schema/v1/m.room.power_levels index 4104bab7..0e8e3946 100644 --- a/event-schemas/schema/v1/m.room.power_levels +++ b/event-schemas/schema/v1/m.room.power_levels @@ -2,19 +2,7 @@ "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "title": "Defines the power levels (privileges) of users in the room.", - "description": "This event specifies the minimum level a user must have in order - to perform a certain action. It also specifies the levels - of each user in the room. If a ``user_id`` is in the - ``users`` list, then that ``user_id`` has the associated - power level. Otherwise they have the default level - ``users_default``. If ``users_default`` is not supplied, - it is assumed to be 0. The level required to send a - certain event is governed by ``events``, ``state_default`` - and ``events_default``. If an event type is specified in - ``events``, then the user must have at least the level - specified in order to send that event. If the event type is - not supplied, it defaults to ``events_default`` for Message - Events and ``state_default`` for State Events.", + "description": "This event specifies the minimum level a user must have in order\nto perform a certain action. It also specifies the levels\nof each user in the room. If a ``user_id`` is in the\n``users`` list, then that ``user_id`` has the associated\npower level. Otherwise they have the default level\n``users_default``. If ``users_default`` is not supplied,\nit is assumed to be 0. The level required to send a\ncertain event is governed by ``events``, ``state_default``\nand ``events_default``. If an event type is specified in \n``events``, then the user must have at least the level\nspecified in order to send that event. If the event type is\nnot supplied, it defaults to ``events_default`` for Message\nEvents and ``state_default`` for State Events.", "allOf": [{ "$ref": "core#/definitions/state_event" }], diff --git a/event-schemas/schema/v1/m.room.redaction b/event-schemas/schema/v1/m.room.redaction index 910e3215..f036500b 100644 --- a/event-schemas/schema/v1/m.room.redaction +++ b/event-schemas/schema/v1/m.room.redaction @@ -2,14 +2,7 @@ "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "title": "Indicates a previous event has been redacted.", - "description": "Events can be redacted by either room or server admins. Redacting an event - means that all keys not required by the protocol are stripped off, allowing - admins to remove offensive or illegal content that may have been attached - to any event. This cannot be undone, allowing server owners to physically - delete the offending data. There is also a concept of a moderator hiding a - message event, which can be undone, but cannot be applied to state - events. The event that has been redacted is specified in the ``redacts`` - event level key.", + "description": "Events can be redacted by either room or server admins. Redacting an event\nmeans that all keys not required by the protocol are stripped off, allowing\nadmins to remove offensive or illegal content that may have been attached\nto any event. This cannot be undone, allowing server owners to physically\ndelete the offending data. There is also a concept of a moderator hiding a\nmessage event, which can be undone, but cannot be applied to state\nevents. The event that has been redacted is specified in the ``redacts``\nevent level key.", "allOf": [{ "$ref": "core#/definitions/room_event" }], diff --git a/event-schemas/schema/v1/m.room.topic b/event-schemas/schema/v1/m.room.topic index 86f4c97b..5847fa65 100644 --- a/event-schemas/schema/v1/m.room.topic +++ b/event-schemas/schema/v1/m.room.topic @@ -2,11 +2,7 @@ "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "title": "Set a topic for the room.", - "description": "A topic is a short message detailing what is currently being discussed in - the room. It can also be used as a way to display extra information about - the room, which may not be suitable for the room name. The room topic can - also be set when creating a room using ``/createRoom`` with the ``topic`` - key.", + "description": "A topic is a short message detailing what is currently being discussed in\nthe room. It can also be used as a way to display extra information about\nthe room, which may not be suitable for the room name. The room topic can\nalso be set when creating a room using ``/createRoom`` with the ``topic``\nkey.", "allOf": [{ "$ref": "core#/definitions/state_event" }], diff --git a/templating/build.py b/templating/build.py index 4de25791..35fde617 100755 --- a/templating/build.py +++ b/templating/build.py @@ -78,12 +78,16 @@ def main(file_stream=None, out_dir=None): return code + def indent(input, indent): + return input.replace("\n", ("\n" + " "*indent)) + # make Jinja aware of the templates and filters env = Environment( loader=FileSystemLoader("templates"), undefined=StrictUndefined ) env.filters["jsonify"] = jsonify + env.filters["indent"] = indent # load up and parse the lowest single units possible: we don't know or care # which spec section will use it, we just need it there in memory for when diff --git a/templating/internal/units.py b/templating/internal/units.py index 5d387c99..a1b90ad4 100644 --- a/templating/internal/units.py +++ b/templating/internal/units.py @@ -63,7 +63,7 @@ def _load_schemas(): continue print "Reading %s" % os.path.join(path, filename) with open(os.path.join(path, filename), "r") as f: - json_schema = json.loads(f.read(), strict=False) + json_schema = json.loads(f.read()) schema = { "typeof": None, "type": None, diff --git a/templating/templates/events.tmpl b/templating/templates/events.tmpl index 7520701c..80a751e0 100644 --- a/templating/templates/events.tmpl +++ b/templating/templates/events.tmpl @@ -4,7 +4,7 @@ Type: {{event.typeof}} Description: - {{event.desc}} + {{event.desc | indent(4)}} Required Keys: ``{{event.required_keys | jsonify}}``