mirror of
https://github.com/matrix-org/matrix-spec
synced 2026-04-28 05:14:10 +02:00
Compare commits
17 commits
cdcc2b9a03
...
39dfbb9f43
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
39dfbb9f43 | ||
|
|
67743d5715 | ||
|
|
338047ec7b | ||
|
|
0439707624 | ||
|
|
f4e6e6dea9 | ||
|
|
73fcf366a0 | ||
|
|
0a1efd8c9c | ||
|
|
2c6ddafb43 | ||
|
|
fc81171081 | ||
|
|
c74befd111 | ||
|
|
ca9c376076 | ||
|
|
fe46e0c363 | ||
|
|
a8c326962a | ||
|
|
7b3083885b | ||
|
|
a96aeb5882 | ||
|
|
54842585db | ||
|
|
cbcbde8f3c |
16
.github/workflows/main.yml
vendored
16
.github/workflows/main.yml
vendored
|
|
@ -2,6 +2,7 @@ name: "Spec"
|
||||||
|
|
||||||
env:
|
env:
|
||||||
HUGO_VERSION: 0.139.0
|
HUGO_VERSION: 0.139.0
|
||||||
|
PYTHON_VERSION: 3.13
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
|
|
@ -40,7 +41,7 @@ jobs:
|
||||||
- name: "➕ Setup Python"
|
- name: "➕ Setup Python"
|
||||||
uses: actions/setup-python@v5
|
uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: '3.9'
|
python-version: ${{ env.PYTHON_VERSION }}
|
||||||
cache: 'pip'
|
cache: 'pip'
|
||||||
cache-dependency-path: scripts/requirements.txt
|
cache-dependency-path: scripts/requirements.txt
|
||||||
- name: "➕ Install dependencies"
|
- name: "➕ Install dependencies"
|
||||||
|
|
@ -59,7 +60,7 @@ jobs:
|
||||||
- name: "➕ Setup Python"
|
- name: "➕ Setup Python"
|
||||||
uses: actions/setup-python@v5
|
uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: '3.9'
|
python-version: ${{ env.PYTHON_VERSION }}
|
||||||
cache: 'pip'
|
cache: 'pip'
|
||||||
cache-dependency-path: scripts/requirements.txt
|
cache-dependency-path: scripts/requirements.txt
|
||||||
- name: "➕ Install dependencies"
|
- name: "➕ Install dependencies"
|
||||||
|
|
@ -78,7 +79,7 @@ jobs:
|
||||||
- name: "➕ Setup Python"
|
- name: "➕ Setup Python"
|
||||||
uses: actions/setup-python@v5
|
uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: '3.9'
|
python-version: ${{ env.PYTHON_VERSION }}
|
||||||
cache: 'pip'
|
cache: 'pip'
|
||||||
cache-dependency-path: scripts/requirements.txt
|
cache-dependency-path: scripts/requirements.txt
|
||||||
- name: "➕ Install dependencies"
|
- name: "➕ Install dependencies"
|
||||||
|
|
@ -120,7 +121,7 @@ jobs:
|
||||||
- name: "➕ Setup Python"
|
- name: "➕ Setup Python"
|
||||||
uses: actions/setup-python@v5
|
uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: '3.9'
|
python-version: ${{ env.PYTHON_VERSION }}
|
||||||
cache: 'pip'
|
cache: 'pip'
|
||||||
cache-dependency-path: scripts/requirements.txt
|
cache-dependency-path: scripts/requirements.txt
|
||||||
- name: "➕ Install dependencies"
|
- name: "➕ Install dependencies"
|
||||||
|
|
@ -172,7 +173,7 @@ jobs:
|
||||||
- name: "➕ Setup Python"
|
- name: "➕ Setup Python"
|
||||||
uses: actions/setup-python@v5
|
uses: actions/setup-python@v5
|
||||||
with:
|
with:
|
||||||
python-version: '3.9'
|
python-version: ${{ env.PYTHON_VERSION }}
|
||||||
- name: "➕ Install towncrier"
|
- name: "➕ Install towncrier"
|
||||||
run: "pip install 'towncrier'"
|
run: "pip install 'towncrier'"
|
||||||
- name: "Generate changelog"
|
- name: "Generate changelog"
|
||||||
|
|
@ -283,10 +284,11 @@ jobs:
|
||||||
npm i
|
npm i
|
||||||
npm run get-proposals
|
npm run get-proposals
|
||||||
- name: "⚙️ hugo"
|
- name: "⚙️ hugo"
|
||||||
|
env:
|
||||||
|
HUGO_PARAMS_VERSION_STATUS: "historical"
|
||||||
# Create a baseURL like `/v1.2` out of the `v1.2` tag
|
# Create a baseURL like `/v1.2` out of the `v1.2` tag
|
||||||
run: |
|
run: |
|
||||||
echo -e '[params.version]\nstatus="historical"' > historical.toml
|
hugo --baseURL "/${GITHUB_REF/refs\/tags\//}" -d "spec"
|
||||||
hugo --config config.toml,historical.toml --baseURL "/${GITHUB_REF/refs\/tags\//}" -d "spec"
|
|
||||||
|
|
||||||
- name: "📥 Spec definition download"
|
- name: "📥 Spec definition download"
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v4
|
||||||
|
|
|
||||||
1
changelogs/client_server/newsfragments/2095.feature
Normal file
1
changelogs/client_server/newsfragments/2095.feature
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
Add `m.topic` content block to enable rich text in `m.room.topic` events as per [MSC3765](https://github.com/matrix-org/matrix-spec-proposals/pull/3765).
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
"Public" rooms in profile look-ups are defined through their join rule and history visibility.
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
"Public" rooms in user directory queries are defined through their join rule and history visibility.
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
"Public" rooms with respect to call invites are defined through their join rule.
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
"Public" rooms have no specific meaning with respect to moderation policy lists.
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
"Public" rooms with respect to presence are defined through their join rule.
|
||||||
1
changelogs/client_server/newsfragments/2125.feature
Normal file
1
changelogs/client_server/newsfragments/2125.feature
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
Add `/_matrix/client/v1/room_summary/{roomIdOrAlias}` and extend `/_matrix/client/v1/rooms/{roomId}/hierarchy` with the new optional properties `allowed_room_ids`, `encryption` and `room_version` as per [MSC3266](https://github.com/matrix-org/matrix-spec-proposals/pull/3266).
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
Clarify that Well-Known URIs are available on the server name's hostname. Contributed by @HarHarLinks.
|
||||||
1
changelogs/internal/newsfragments/2088.clarification
Normal file
1
changelogs/internal/newsfragments/2088.clarification
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
Replace Hugo shortcodes in OpenAPI output.
|
||||||
1
changelogs/internal/newsfragments/2123.clarification
Normal file
1
changelogs/internal/newsfragments/2123.clarification
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
Fix the historical info box when generating the historical spec in CI.
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
Add a note to the invite endpoints that invites to local users may be received twice over federation if the homeserver is already in the room.
|
||||||
1
changelogs/server_server/newsfragments/2095.feature
Normal file
1
changelogs/server_server/newsfragments/2095.feature
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
Add `m.topic` content block to enable rich text in `m.room.topic` events as per [MSC3765](https://github.com/matrix-org/matrix-spec-proposals/pull/3765).
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
Clarify that auth event of `content.join_authorised_via_users_server` is only necessary for `m.room.member` with a `membership` of `join`.
|
||||||
1
changelogs/server_server/newsfragments/2125.feature
Normal file
1
changelogs/server_server/newsfragments/2125.feature
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
Extend `/_matrix/federation/v1/hierarchy/{roomId}` with the new optional properties `encryption` and `room_version` as per [MSC3266](https://github.com/matrix-org/matrix-spec-proposals/pull/3266).
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
Clarify that Well-Known URIs are available on the server name's hostname. Contributed by @HarHarLinks.
|
||||||
|
|
@ -371,15 +371,23 @@ valid data was obtained, but no server is available to serve the client.
|
||||||
No further guess should be attempted and the user should make a
|
No further guess should be attempted and the user should make a
|
||||||
conscientious decision what to do next.
|
conscientious decision what to do next.
|
||||||
|
|
||||||
### Well-known URI
|
### Well-known URIs
|
||||||
|
|
||||||
|
Matrix facilitates automatic discovery for the Client-Server API base URL and more via the
|
||||||
|
[RFC 8615](https://datatracker.ietf.org/doc/html/rfc8615) "Well-Known URI" method.
|
||||||
|
This method uses JSON files at a predetermined location on the root path `/.well-known/` to
|
||||||
|
specify parameter values.
|
||||||
|
|
||||||
{{% boxes/note %}}
|
{{% boxes/note %}}
|
||||||
|
Diverging from the rest of the endpoints in the Client-Server spec, these files can not be provided
|
||||||
|
on the base URL that the Client-Server API is reachable on, as it is yet to be discovered.
|
||||||
|
Instead, they can be reached via HTTPS on the [server name](/appendices/#server-name)'s hostname as domain.
|
||||||
|
|
||||||
Servers hosting the `.well-known` JSON file SHOULD offer CORS headers,
|
Servers hosting the `.well-known` JSON file SHOULD offer CORS headers,
|
||||||
as per the [CORS](#web-browser-clients) section in this specification.
|
as per the [CORS](#web-browser-clients) section in this specification.
|
||||||
{{% /boxes/note %}}
|
{{% /boxes/note %}}
|
||||||
|
|
||||||
The `.well-known` method uses a JSON file at a predetermined location to
|
The flow for auto-discovery is as follows:
|
||||||
specify parameter values. The flow for this method is as follows:
|
|
||||||
|
|
||||||
1. Extract the [server name](/appendices/#server-name) from the user's Matrix ID by splitting the
|
1. Extract the [server name](/appendices/#server-name) from the user's Matrix ID by splitting the
|
||||||
Matrix ID at the first colon.
|
Matrix ID at the first colon.
|
||||||
|
|
@ -415,10 +423,17 @@ specify parameter values. The flow for this method is as follows:
|
||||||
|
|
||||||
{{% http-api spec="client-server" api="wellknown" %}}
|
{{% http-api spec="client-server" api="wellknown" %}}
|
||||||
|
|
||||||
{{% http-api spec="client-server" api="versions" %}}
|
|
||||||
|
|
||||||
{{% http-api spec="client-server" api="support" %}}
|
{{% http-api spec="client-server" api="support" %}}
|
||||||
|
|
||||||
|
### API Versions
|
||||||
|
|
||||||
|
Upon connecting, the Matrix client and server need to negotiate which version of the specification
|
||||||
|
they commonly support, as the API evolves over time. The server advertises its supported versions
|
||||||
|
and optionally unstable features to the client, which can then go on to make requests to the
|
||||||
|
endpoints it supports.
|
||||||
|
|
||||||
|
{{% http-api spec="client-server" api="versions" %}}
|
||||||
|
|
||||||
## Client Authentication
|
## Client Authentication
|
||||||
|
|
||||||
Most API endpoints require the user to identify themselves by presenting
|
Most API endpoints require the user to identify themselves by presenting
|
||||||
|
|
@ -2835,6 +2850,10 @@ re-invited.
|
||||||
|
|
||||||
{{% http-api spec="client-server" api="list_public_rooms" %}}
|
{{% http-api spec="client-server" api="list_public_rooms" %}}
|
||||||
|
|
||||||
|
### Room Summaries
|
||||||
|
|
||||||
|
{{% http-api spec="client-server" api="room_summary" %}}
|
||||||
|
|
||||||
## User Data
|
## User Data
|
||||||
|
|
||||||
### User Directory
|
### User Directory
|
||||||
|
|
@ -2847,10 +2866,15 @@ re-invited.
|
||||||
|
|
||||||
#### Server behaviour
|
#### Server behaviour
|
||||||
|
|
||||||
Homeservers MUST at a minimum allow profile look-up for:
|
Homeservers MUST at a minimum allow profile look-up for users who are
|
||||||
|
visible to the requester based on their membership in rooms known to the
|
||||||
|
homeserver. This means:
|
||||||
|
|
||||||
- users that share a room with the requesting user
|
- users that share a room with the requesting user
|
||||||
- users that reside in public rooms known to the homeserver
|
- users who are joined to rooms known to the homeserver that have a
|
||||||
|
`public` [join rule](#mroomjoin_rules)
|
||||||
|
- users who are joined to rooms known to the homeserver that have a
|
||||||
|
`world_readable` [history visibility](#room-history-visibility)
|
||||||
|
|
||||||
In all other cases, homeservers MAY deny profile look-up by responding with
|
In all other cases, homeservers MAY deny profile look-up by responding with
|
||||||
403 and an error code of `M_FORBIDDEN`.
|
403 and an error code of `M_FORBIDDEN`.
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,9 @@ the entity making the decisions on filtering is best positioned to
|
||||||
interpret the rules how it sees fit.
|
interpret the rules how it sees fit.
|
||||||
|
|
||||||
Moderation policy lists are stored as room state events. There are no
|
Moderation policy lists are stored as room state events. There are no
|
||||||
restrictions on how the rooms can be configured (they could be public,
|
restrictions on how the rooms can be configured in terms of
|
||||||
private, encrypted, etc).
|
[join rules](#mroomjoin_rules), [history visibility](#room-history-visibility),
|
||||||
|
encryption, etc.
|
||||||
|
|
||||||
There are currently 3 kinds of entities which can be affected by rules:
|
There are currently 3 kinds of entities which can be affected by rules:
|
||||||
`user`, `server`, and `room`. All 3 are described with
|
`user`, `server`, and `room`. All 3 are described with
|
||||||
|
|
|
||||||
|
|
@ -68,5 +68,7 @@ will cause the server to automatically set their presence to `online`.
|
||||||
|
|
||||||
#### Security considerations
|
#### Security considerations
|
||||||
|
|
||||||
Presence information is shared with all users who share a room with the
|
Presence information is published to all users who share a room with the
|
||||||
target user. In large public rooms this could be undesirable.
|
target user. If the target user is a member of a room with a `public`
|
||||||
|
[join rule](#mroomjoin_rules), any other user in the federation is
|
||||||
|
able to gain access to the target user's presence. This could be undesirable.
|
||||||
|
|
|
||||||
|
|
@ -26,9 +26,10 @@ on certain keys of certain event types.
|
||||||
|
|
||||||
The supported keys to search over are:
|
The supported keys to search over are:
|
||||||
|
|
||||||
- `content.body` in `m.room.message`
|
- `content.body` in [`m.room.message`](/client-server-api/#mroommessage)
|
||||||
- `content.name` in `m.room.name`
|
- `content.name` in [`m.room.name`](/client-server-api/#mroomname)
|
||||||
- `content.topic` in `m.room.topic`
|
- In [`m.room.topic`](/client-server-api/#mroomtopic), `content.topic`
|
||||||
|
as well as the `body` of the `text/plain` representation in `content['m.topic']`.
|
||||||
|
|
||||||
The search will *not* include rooms that are end to end encrypted.
|
The search will *not* include rooms that are end to end encrypted.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -202,11 +202,13 @@ specific user, and should be set to the Matrix user ID of that user. Invites
|
||||||
without an `invitee` field are defined to be intended for any member of the
|
without an `invitee` field are defined to be intended for any member of the
|
||||||
room other than the sender of the event.
|
room other than the sender of the event.
|
||||||
|
|
||||||
Clients should consider an incoming call if they see a non-expired invite event where the `invitee` field is either
|
Clients should consider an incoming call if they see a non-expired invite event
|
||||||
absent or equal to their user's Matrix ID, however they should evaluate whether or not to ring based on their
|
where the `invitee` field is either absent or equal to their user's Matrix ID.
|
||||||
user's trust relationship with the callers and/or where the call was placed. As a starting point, it is
|
They should, however, evaluate whether or not to ring based on their user's trust
|
||||||
suggested that clients ignore call invites from users in public rooms. It is strongly recommended that
|
relationship with the callers and/or where the call was placed. As a starting
|
||||||
when clients do not ring for an incoming call invite, they still display the call invite in the room and
|
point, it is RECOMMENDED that clients ignore call invites in rooms with a
|
||||||
|
[join rule](#mroomjoin_rules) of `public`. When clients suppress ringing for an
|
||||||
|
incoming call invite, they SHOULD still display the call invite in the room and
|
||||||
annotate that it was ignored.
|
annotate that it was ignored.
|
||||||
|
|
||||||
##### Glare
|
##### Glare
|
||||||
|
|
|
||||||
|
|
@ -119,7 +119,8 @@ to send. The process overall is as follows:
|
||||||
server must present a valid certificate for the hostname.
|
server must present a valid certificate for the hostname.
|
||||||
|
|
||||||
3. If the hostname is not an IP literal, a regular HTTPS request is
|
3. If the hostname is not an IP literal, a regular HTTPS request is
|
||||||
made to `https://<hostname>/.well-known/matrix/server`, expecting
|
made to `https://<hostname>/.well-known/matrix/server` (according to
|
||||||
|
[RFC 8615](https://datatracker.ietf.org/doc/html/rfc8615)), expecting
|
||||||
the schema defined later in this section. 30x redirects should be
|
the schema defined later in this section. 30x redirects should be
|
||||||
followed, however redirection loops should be avoided. Responses
|
followed, however redirection loops should be avoided. Responses
|
||||||
(successful or otherwise) to the `/.well-known` endpoint should be
|
(successful or otherwise) to the `/.well-known` endpoint should be
|
||||||
|
|
@ -543,8 +544,8 @@ the following subset of the room state:
|
||||||
`third_party_invite` property, the current
|
`third_party_invite` property, the current
|
||||||
`m.room.third_party_invite` event with `state_key` matching
|
`m.room.third_party_invite` event with `state_key` matching
|
||||||
`content.third_party_invite.signed.token`, if any.
|
`content.third_party_invite.signed.token`, if any.
|
||||||
- If `content.join_authorised_via_users_server` is present,
|
- If `membership` is `join`, `content.join_authorised_via_users_server`
|
||||||
and the [room version supports restricted rooms](/rooms/#feature-matrix),
|
is present, and the [room version supports restricted rooms](/rooms/#feature-matrix),
|
||||||
then the `m.room.member` event with `state_key` matching
|
then the `m.room.member` event with `state_key` matching
|
||||||
`content.join_authorised_via_users_server`.
|
`content.join_authorised_via_users_server`.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -109,15 +109,17 @@ paths:
|
||||||
name:
|
name:
|
||||||
type: string
|
type: string
|
||||||
description: |-
|
description: |-
|
||||||
If this is included, an `m.room.name` event will be sent
|
If this is included, an [`m.room.name`](/client-server-api/#mroomname) event
|
||||||
into the room to indicate the name of the room. See Room
|
will be sent into the room to indicate the name for the room.
|
||||||
Events for more information on `m.room.name`.
|
This overwrites any [`m.room.name`](/client-server-api/#mroomname)
|
||||||
|
event in `initial_state`.
|
||||||
topic:
|
topic:
|
||||||
type: string
|
type: string
|
||||||
description: |-
|
description: |-
|
||||||
If this is included, an `m.room.topic` event will be sent
|
If this is included, an [`m.room.topic`](/client-server-api/#mroomtopic)
|
||||||
into the room to indicate the topic for the room. See Room
|
event with a `text/plain` mimetype will be sent into the room
|
||||||
Events for more information on `m.room.topic`.
|
to indicate the topic for the room. This overwrites any
|
||||||
|
[`m.room.topic`](/client-server-api/#mroomtopic) event in `initial_state`.
|
||||||
invite:
|
invite:
|
||||||
type: array
|
type: array
|
||||||
description: |-
|
description: |-
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,9 @@ properties:
|
||||||
example: "!abcdefg:example.org"
|
example: "!abcdefg:example.org"
|
||||||
topic:
|
topic:
|
||||||
type: string
|
type: string
|
||||||
description: The topic of the room, if any.
|
description: |-
|
||||||
|
The plain text topic of the room. Omitted if no `text/plain` mimetype
|
||||||
|
exists in [`m.room.topic`](/client-server-api/#mroomtopic).
|
||||||
example: "All things general"
|
example: "All things general"
|
||||||
world_readable:
|
world_readable:
|
||||||
type: boolean
|
type: boolean
|
||||||
|
|
|
||||||
48
data/api/client-server/definitions/room_summary.yaml
Normal file
48
data/api/client-server/definitions/room_summary.yaml
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
# Copyright 2025 The Matrix.org Foundation C.I.C.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
type: object
|
||||||
|
title: RoomSummary
|
||||||
|
allOf:
|
||||||
|
- $ref: public_rooms_chunk.yaml
|
||||||
|
- type: object
|
||||||
|
properties:
|
||||||
|
room_type:
|
||||||
|
type: string
|
||||||
|
description: The `type` of room (from
|
||||||
|
[`m.room.create`](/client-server-api/#mroomcreate)),
|
||||||
|
if any.
|
||||||
|
allowed_room_ids:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
description: |-
|
||||||
|
If the room is a [restricted room](/server-server-api/#restricted-rooms), these are the room IDs which
|
||||||
|
are specified by the join rules. Empty or omitted otherwise.
|
||||||
|
encryption:
|
||||||
|
type: string
|
||||||
|
enum:
|
||||||
|
- "m.megolm.v1.aes-sha2"
|
||||||
|
description: |-
|
||||||
|
The encryption algorithm to be used to encrypt messages sent in the
|
||||||
|
room.
|
||||||
|
room_version:
|
||||||
|
description: The version of the room.
|
||||||
|
type: string
|
||||||
|
|
||||||
|
required:
|
||||||
|
- room_id
|
||||||
|
- num_joined_members
|
||||||
|
- world_readable
|
||||||
|
- guest_can_join
|
||||||
138
data/api/client-server/room_summary.yaml
Normal file
138
data/api/client-server/room_summary.yaml
Normal file
|
|
@ -0,0 +1,138 @@
|
||||||
|
# Copyright 2025 The Matrix.org Foundation C.I.C.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
openapi: 3.1.0
|
||||||
|
info:
|
||||||
|
title: Matrix Client-Server Room Summary API
|
||||||
|
version: 1.0.0
|
||||||
|
paths:
|
||||||
|
"/room_summary/{roomIdOrAlias}":
|
||||||
|
get:
|
||||||
|
x-addedInMatrixVersion: "1.15"
|
||||||
|
summary: Retrieves a summary for a room.
|
||||||
|
description: |-
|
||||||
|
Retrieves a summary for a room.
|
||||||
|
|
||||||
|
Clients should note that requests for rooms where the user's membership
|
||||||
|
is `invite` or `knock` might yield outdated, partial or even no data
|
||||||
|
since the server may not have access to the current state of the room.
|
||||||
|
|
||||||
|
Servers MAY allow unauthenticated access to this API if at least one of
|
||||||
|
the following conditions holds true:
|
||||||
|
|
||||||
|
- The room has a [join rule](#mroomjoin_rules) of `public`, `knock` or
|
||||||
|
`knock_restricted`.
|
||||||
|
- The room has a `world_readable` [history visibility](#room-history-visibility).
|
||||||
|
|
||||||
|
Servers should consider rate limiting federation requests more heavily,
|
||||||
|
if the client is unauthenticated.
|
||||||
|
operationId: getRoomSummary
|
||||||
|
security:
|
||||||
|
- signedRequest: []
|
||||||
|
parameters:
|
||||||
|
- in: path
|
||||||
|
name: roomIdOrAlias
|
||||||
|
description: The room identifier or alias to summarise.
|
||||||
|
required: true
|
||||||
|
example: "#monkeys:matrix.org"
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
- in: query
|
||||||
|
name: via
|
||||||
|
description: |-
|
||||||
|
The servers to attempt to request the summary from when
|
||||||
|
the local server cannot generate it (for instance, because
|
||||||
|
it has no local user in the room).
|
||||||
|
example:
|
||||||
|
- matrix.org
|
||||||
|
- elsewhere.ca
|
||||||
|
schema:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: A summary of the room.
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
description: A summary of the room.
|
||||||
|
allOf:
|
||||||
|
- $ref: ../client-server/definitions/room_summary.yaml
|
||||||
|
- type: object
|
||||||
|
properties:
|
||||||
|
room_type:
|
||||||
|
x-addedInMatrixVersion: # Overrides room_summary.yaml
|
||||||
|
membership:
|
||||||
|
description: |-
|
||||||
|
The membership state of the user if the user is joined to the room. Absent
|
||||||
|
if the API was called unauthenticated.
|
||||||
|
enum:
|
||||||
|
- invite
|
||||||
|
- join
|
||||||
|
- knock
|
||||||
|
- leave
|
||||||
|
- ban
|
||||||
|
type: string
|
||||||
|
required:
|
||||||
|
- guest_can_join
|
||||||
|
- num_joined_members
|
||||||
|
- room_id
|
||||||
|
- world_readable
|
||||||
|
examples:
|
||||||
|
response:
|
||||||
|
value: {
|
||||||
|
room_id: "!ol19s:bleecker.street",
|
||||||
|
avatar_url: "mxc://bleecker.street/CHEDDARandBRIE",
|
||||||
|
guest_can_join: false,
|
||||||
|
name: "CHEESE",
|
||||||
|
num_joined_members: 37,
|
||||||
|
topic: "Tasty tasty cheese",
|
||||||
|
world_readable: true,
|
||||||
|
join_rule: "public",
|
||||||
|
room_type: "m.space",
|
||||||
|
membership: "invite",
|
||||||
|
encryption: "m.megolm.v1.aes-sha2",
|
||||||
|
room_version: "9001",
|
||||||
|
}
|
||||||
|
"404":
|
||||||
|
description: |-
|
||||||
|
The room could not be found.
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: ../client-server/definitions/errors/error.yaml
|
||||||
|
examples:
|
||||||
|
response:
|
||||||
|
value: {
|
||||||
|
"errcode": "M_NOT_FOUND",
|
||||||
|
"error": "Room not found."
|
||||||
|
}
|
||||||
|
servers:
|
||||||
|
- url: "{protocol}://{hostname}{basePath}"
|
||||||
|
variables:
|
||||||
|
protocol:
|
||||||
|
enum:
|
||||||
|
- http
|
||||||
|
- https
|
||||||
|
default: https
|
||||||
|
hostname:
|
||||||
|
default: localhost:8008
|
||||||
|
basePath:
|
||||||
|
default: /_matrix/client/v1
|
||||||
|
components:
|
||||||
|
securitySchemes:
|
||||||
|
accessTokenQuery:
|
||||||
|
$ref: definitions/security.yaml#/accessTokenQuery
|
||||||
|
accessTokenBearer:
|
||||||
|
$ref: definitions/security.yaml#/accessTokenBearer
|
||||||
|
|
@ -102,15 +102,10 @@ paths:
|
||||||
* The room's [`m.room.history_visibility`](#room-history-visibility) is set to `world_readable`.
|
* The room's [`m.room.history_visibility`](#room-history-visibility) is set to `world_readable`.
|
||||||
items:
|
items:
|
||||||
allOf:
|
allOf:
|
||||||
- $ref: definitions/public_rooms_chunk.yaml
|
- $ref: definitions/room_summary.yaml
|
||||||
- type: object
|
- type: object
|
||||||
title: SpaceHierarchyRoomsChunk
|
title: SpaceHierarchyRoomsChunk
|
||||||
properties:
|
properties:
|
||||||
room_type:
|
|
||||||
type: string
|
|
||||||
description: The `type` of room (from
|
|
||||||
[`m.room.create`](/client-server-api/#mroomcreate)),
|
|
||||||
if any.
|
|
||||||
children_state:
|
children_state:
|
||||||
type: array
|
type: array
|
||||||
description: |-
|
description: |-
|
||||||
|
|
@ -130,6 +125,12 @@ paths:
|
||||||
description: The `origin_server_ts` for the event.
|
description: The `origin_server_ts` for the event.
|
||||||
required:
|
required:
|
||||||
- origin_server_ts
|
- origin_server_ts
|
||||||
|
allowed_room_ids:
|
||||||
|
x-addedInMatrixVersion: "1.15" # Extends room_summary.yaml
|
||||||
|
encryption:
|
||||||
|
x-addedInMatrixVersion: "1.15" # Extends room_summary.yaml
|
||||||
|
room_version:
|
||||||
|
x-addedInMatrixVersion: "1.15" # Extends room_summary.yaml
|
||||||
required:
|
required:
|
||||||
- children_state
|
- children_state
|
||||||
next_batch:
|
next_batch:
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,12 @@ paths:
|
||||||
description: |-
|
description: |-
|
||||||
Gets server admin contact and support page of the domain.
|
Gets server admin contact and support page of the domain.
|
||||||
|
|
||||||
Like the [well-known discovery URI](/client-server-api/#well-known-uri),
|
{{% boxes/note %}}
|
||||||
this should be accessed with the hostname of the homeserver by making a
|
Like the [well-known discovery URI](/client-server-api/#well-known-uris),
|
||||||
|
this endpoint should be accessed with the hostname of the homeserver's
|
||||||
|
[server name](/appendices/#server-name) by making a
|
||||||
GET request to `https://hostname/.well-known/matrix/support`.
|
GET request to `https://hostname/.well-known/matrix/support`.
|
||||||
|
{{% /boxes/note %}}
|
||||||
|
|
||||||
Note that this endpoint is not necessarily handled by the homeserver.
|
Note that this endpoint is not necessarily handled by the homeserver.
|
||||||
It may be served by another webserver, used for discovering support
|
It may be served by another webserver, used for discovering support
|
||||||
|
|
|
||||||
|
|
@ -20,10 +20,17 @@ paths:
|
||||||
post:
|
post:
|
||||||
summary: Searches the user directory.
|
summary: Searches the user directory.
|
||||||
description: |-
|
description: |-
|
||||||
Performs a search for users. The homeserver may
|
Performs a search for users. The homeserver may determine which
|
||||||
determine which subset of users are searched, however the homeserver
|
subset of users are searched. However, the homeserver MUST at a
|
||||||
MUST at a minimum consider the users the requesting user shares a
|
minimum consider users who are visible to the requester based
|
||||||
room with and those who reside in public rooms (known to the homeserver).
|
on their membership in rooms known to the homeserver. This means:
|
||||||
|
|
||||||
|
- users that share a room with the requesting user
|
||||||
|
- users who are joined to rooms known to the homeserver that have a
|
||||||
|
`public` [join rule](#mroomjoin_rules)
|
||||||
|
- users who are joined to rooms known to the homeserver that have a
|
||||||
|
`world_readable` [history visibility](#room-history-visibility)
|
||||||
|
|
||||||
The search MUST consider local users to the homeserver, and SHOULD
|
The search MUST consider local users to the homeserver, and SHOULD
|
||||||
query remote users as part of the search.
|
query remote users as part of the search.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,12 @@ paths:
|
||||||
suitably namespaced for each application and reduces the risk of
|
suitably namespaced for each application and reduces the risk of
|
||||||
clashes.
|
clashes.
|
||||||
|
|
||||||
|
{{% boxes/note %}}
|
||||||
|
This endpoint should be accessed with the hostname of the homeserver's
|
||||||
|
[server name](/appendices/#server-name) by making a
|
||||||
|
GET request to `https://hostname/.well-known/matrix/client`.
|
||||||
|
{{% /boxes/note %}}
|
||||||
|
|
||||||
Note that this endpoint is not necessarily handled by the homeserver,
|
Note that this endpoint is not necessarily handled by the homeserver,
|
||||||
but by another webserver, to be used for discovering the homeserver URL.
|
but by another webserver, to be used for discovering the homeserver URL.
|
||||||
operationId: getWellknown
|
operationId: getWellknown
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ paths:
|
||||||
put:
|
put:
|
||||||
summary: Invites a remote user to a room
|
summary: Invites a remote user to a room
|
||||||
description: |-
|
description: |-
|
||||||
Invites a remote user to a room. Once the event has been signed by both the inviting
|
Invites a remote user to a room. Once the event has been signed by both the inviting
|
||||||
homeserver and the invited homeserver, it can be sent to all of the servers in the
|
homeserver and the invited homeserver, it can be sent to all of the servers in the
|
||||||
room by the inviting homeserver.
|
room by the inviting homeserver.
|
||||||
|
|
||||||
|
|
@ -32,6 +32,10 @@ paths:
|
||||||
[room version specification](/rooms) for precise event formats. **The request and response
|
[room version specification](/rooms) for precise event formats. **The request and response
|
||||||
bodies here describe the common event fields in more detail and may be missing other
|
bodies here describe the common event fields in more detail and may be missing other
|
||||||
required fields for a PDU.**
|
required fields for a PDU.**
|
||||||
|
|
||||||
|
Also note that if the remote homeserver is already in the room, it will receive the
|
||||||
|
invite event twice; once through this endpoint, and again through a [federation
|
||||||
|
transaction](/server-server-api/#transactions).
|
||||||
operationId: sendInviteV1
|
operationId: sendInviteV1
|
||||||
security:
|
security:
|
||||||
- signedRequest: []
|
- signedRequest: []
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ paths:
|
||||||
This API is nearly identical to the v1 API with the exception of the request
|
This API is nearly identical to the v1 API with the exception of the request
|
||||||
body being different, and the response format fixed.
|
body being different, and the response format fixed.
|
||||||
|
|
||||||
Invites a remote user to a room. Once the event has been signed by both the inviting
|
Invites a remote user to a room. Once the event has been signed by both the inviting
|
||||||
homeserver and the invited homeserver, it can be sent to all of the servers in the
|
homeserver and the invited homeserver, it can be sent to all of the servers in the
|
||||||
room by the inviting homeserver.
|
room by the inviting homeserver.
|
||||||
|
|
||||||
|
|
@ -36,6 +36,10 @@ paths:
|
||||||
[room version specification](/rooms) for precise event formats. **The request and response
|
[room version specification](/rooms) for precise event formats. **The request and response
|
||||||
bodies here describe the common event fields in more detail and may be missing other
|
bodies here describe the common event fields in more detail and may be missing other
|
||||||
required fields for a PDU.**
|
required fields for a PDU.**
|
||||||
|
|
||||||
|
Also note that if the remote homeserver is already in the room, it will receive the
|
||||||
|
invite event twice; once through this endpoint, and again through a [federation
|
||||||
|
transaction](/server-server-api/#transactions).
|
||||||
operationId: sendInviteV2
|
operationId: sendInviteV2
|
||||||
security:
|
security:
|
||||||
- signedRequest: []
|
- signedRequest: []
|
||||||
|
|
|
||||||
|
|
@ -61,22 +61,10 @@ paths:
|
||||||
room:
|
room:
|
||||||
description: A summary of the room requested.
|
description: A summary of the room requested.
|
||||||
allOf:
|
allOf:
|
||||||
- $ref: ../client-server/definitions/public_rooms_chunk.yaml
|
- $ref: ../client-server/definitions/room_summary.yaml
|
||||||
- type: object
|
- type: object
|
||||||
title: SpaceHierarchyParentRoom
|
title: SpaceHierarchyParentRoom
|
||||||
properties:
|
properties:
|
||||||
room_type:
|
|
||||||
type: string
|
|
||||||
description: The `type` of room (from
|
|
||||||
[`m.room.create`](/client-server-api/#mroomcreate)),
|
|
||||||
if any.
|
|
||||||
allowed_room_ids:
|
|
||||||
type: array
|
|
||||||
items:
|
|
||||||
type: string
|
|
||||||
description: |-
|
|
||||||
If the room is a [restricted room](/server-server-api/#restricted-rooms), these are the room IDs which
|
|
||||||
are specified by the join rules. Empty or omitted otherwise.
|
|
||||||
children_state:
|
children_state:
|
||||||
type: array
|
type: array
|
||||||
description: |-
|
description: |-
|
||||||
|
|
@ -96,6 +84,10 @@ paths:
|
||||||
description: The `origin_server_ts` for the event.
|
description: The `origin_server_ts` for the event.
|
||||||
required:
|
required:
|
||||||
- origin_server_ts
|
- origin_server_ts
|
||||||
|
encryption:
|
||||||
|
x-addedInMatrixVersion: "1.15" # Extends room_summary.yaml
|
||||||
|
room_version:
|
||||||
|
x-addedInMatrixVersion: "1.15" # Extends room_summary.yaml
|
||||||
required:
|
required:
|
||||||
- children_state
|
- children_state
|
||||||
children:
|
children:
|
||||||
|
|
@ -105,22 +97,14 @@ paths:
|
||||||
be excluded.
|
be excluded.
|
||||||
items:
|
items:
|
||||||
allOf:
|
allOf:
|
||||||
- $ref: ../client-server/definitions/public_rooms_chunk.yaml
|
- $ref: ../client-server/definitions/room_summary.yaml
|
||||||
- type: object
|
- type: object
|
||||||
title: SpaceHierarchyChildRoomsChunk
|
title: SpaceHierarchyChildRoomsChunk
|
||||||
properties:
|
properties:
|
||||||
room_type:
|
encryption:
|
||||||
type: string
|
x-addedInMatrixVersion: "1.15" # Extends room_summary.yaml
|
||||||
description: The `type` of room (from
|
room_version:
|
||||||
[`m.room.create`](/client-server-api/#mroomcreate)),
|
x-addedInMatrixVersion: "1.15" # Extends room_summary.yaml
|
||||||
if any.
|
|
||||||
allowed_room_ids:
|
|
||||||
type: array
|
|
||||||
items:
|
|
||||||
type: string
|
|
||||||
description: |-
|
|
||||||
If the room is a [restricted room](/server-server-api/#restricted-rooms), these are the room IDs which
|
|
||||||
are specified by the join rules. Empty or omitted otherwise.
|
|
||||||
inaccessible_children:
|
inaccessible_children:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,12 @@ paths:
|
||||||
Gets information about the delegated server for server-server communication
|
Gets information about the delegated server for server-server communication
|
||||||
between Matrix homeservers. Servers should follow 30x redirects, carefully
|
between Matrix homeservers. Servers should follow 30x redirects, carefully
|
||||||
avoiding redirect loops, and use normal X.509 certificate validation.
|
avoiding redirect loops, and use normal X.509 certificate validation.
|
||||||
|
|
||||||
|
{{% boxes/note %}}
|
||||||
|
This endpoint should be accessed with the hostname of the homeserver's
|
||||||
|
[server name](/appendices/#server-name) by making a
|
||||||
|
GET request to `https://hostname/.well-known/matrix/server`.
|
||||||
|
{{% /boxes/note %}}
|
||||||
operationId: getWellKnown
|
operationId: getWellKnown
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,14 @@
|
||||||
"type": "m.room.topic",
|
"type": "m.room.topic",
|
||||||
"state_key": "",
|
"state_key": "",
|
||||||
"content": {
|
"content": {
|
||||||
"topic": "A room topic"
|
"m.topic": {
|
||||||
|
"m.text": [ {
|
||||||
|
"mimetype": "text/html",
|
||||||
|
"body": "An <em>interesting</em> room topic"
|
||||||
|
}, {
|
||||||
|
"body": "An interesting room topic"
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
"topic": "An interesting room topic"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
type: array
|
||||||
|
description: |-
|
||||||
|
An ordered array of textual representations in different mimetypes.
|
||||||
|
|
||||||
|
Senders SHOULD specify at least one representation and SHOULD always
|
||||||
|
include a plaintext representation.
|
||||||
|
|
||||||
|
Receivers SHOULD use the first representation in the array that
|
||||||
|
they understand.
|
||||||
|
title: TextContentBlock
|
||||||
|
items:
|
||||||
|
type: object
|
||||||
|
title: TextualRepresentation
|
||||||
|
properties:
|
||||||
|
mimetype:
|
||||||
|
type: string
|
||||||
|
description: The mimetype. Defaults to `text/plain` if omitted.
|
||||||
|
example: "text/html"
|
||||||
|
body:
|
||||||
|
type: string
|
||||||
|
description: |-
|
||||||
|
The string content.
|
||||||
|
|
||||||
|
Clients SHOULD validate and sanitize the content as they do
|
||||||
|
for rich content associated with [`msgtype`](/client-server-api/#mroommessage-msgtypes)
|
||||||
|
of [`m.room.message`](/client-server-api/#mroommessage).
|
||||||
|
required:
|
||||||
|
- body
|
||||||
|
|
@ -2,19 +2,40 @@
|
||||||
allOf:
|
allOf:
|
||||||
- $ref: core-event-schema/state_event.yaml
|
- $ref: core-event-schema/state_event.yaml
|
||||||
description: |-
|
description: |-
|
||||||
A topic is a short message detailing what is currently being discussed in the room.
|
A topic is a short message detailing what is currently being discussed
|
||||||
It can also be used as a way to display extra information about the room, which may not
|
in the room. It can also be used as a way to display extra information
|
||||||
be suitable for the room name.
|
about the room, which may not be suitable for the room name. The room
|
||||||
The room topic can also be set when creating a room using `/createRoom` with the `topic` key.'
|
topic can also be set when creating a room using
|
||||||
|
[`/createRoom`](client-server-api/#post_matrixclientv3createroom), either
|
||||||
|
with the `topic` key or by specifying a full event in `initial_state`.
|
||||||
|
|
||||||
If the `topic` property is absent, null, or empty then the topic is unset. In other words,
|
If the `topic` property is absent, null, or empty then the topic is unset. In other words,
|
||||||
an empty `topic` property effectively resets the room to having no topic.
|
an empty `topic` property effectively resets the room to having no topic.
|
||||||
|
|
||||||
|
In order to prevent formatting abuse in room topics, clients SHOULD
|
||||||
|
limit the length of topics during both entry and display, for instance,
|
||||||
|
by capping the number of displayed lines. Additionally, clients SHOULD
|
||||||
|
ignore things like headings and enumerations (or format them as regular
|
||||||
|
text).
|
||||||
properties:
|
properties:
|
||||||
content:
|
content:
|
||||||
properties:
|
properties:
|
||||||
topic:
|
topic:
|
||||||
description: The topic text.
|
description: |-
|
||||||
|
The topic in plain text.
|
||||||
|
|
||||||
|
This SHOULD duplicate the content of the `text/plain`
|
||||||
|
representation in `m.topic` if any exists.
|
||||||
type: string
|
type: string
|
||||||
|
m.topic:
|
||||||
|
type: object
|
||||||
|
title: TopicContentBlock
|
||||||
|
x-addedInMatrixVersion: "1.15"
|
||||||
|
description: |-
|
||||||
|
Textual representation of the room topic in different mimetypes.
|
||||||
|
properties:
|
||||||
|
m.text:
|
||||||
|
$ref: components/m_text_content_block.yaml
|
||||||
required:
|
required:
|
||||||
- topic
|
- topic
|
||||||
type: object
|
type: object
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,35 @@ import yaml
|
||||||
scripts_dir = os.path.dirname(os.path.abspath(__file__))
|
scripts_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
api_dir = os.path.join(os.path.dirname(scripts_dir), "data", "api")
|
api_dir = os.path.join(os.path.dirname(scripts_dir), "data", "api")
|
||||||
|
|
||||||
|
# Finds a Hugo shortcode in a string.
|
||||||
|
#
|
||||||
|
# A shortcode is defined as (newlines and whitespaces for presentation purpose):
|
||||||
|
#
|
||||||
|
# {{%
|
||||||
|
# <zero or more whitespaces>
|
||||||
|
# <name of shortcode>
|
||||||
|
# (optional <one or more whitespaces><list of parameters>)
|
||||||
|
# <zero or more whitespaces>
|
||||||
|
# %}}
|
||||||
|
#
|
||||||
|
# With:
|
||||||
|
#
|
||||||
|
# * <name of shortcode>: any word character and `-` and `/`. `re.ASCII` is used to only match
|
||||||
|
# ASCII characters in the name.
|
||||||
|
# * <list of parameters>: any character except `}`, must not start or end with a
|
||||||
|
# whitespace.
|
||||||
|
shortcode_regex = re.compile(r"""\{\{\% # {{%
|
||||||
|
\s* # zero or more whitespaces
|
||||||
|
(?P<name>[\w/-]+) # name of shortcode
|
||||||
|
(?:\s+(?P<params>[^\s\}][^\}]+[^\s\}]))? # optional list of parameters
|
||||||
|
\s* # zero or more whitespaces
|
||||||
|
\%\}\} # %}}""", re.ASCII | re.VERBOSE)
|
||||||
|
|
||||||
|
# Parses the parameters of a Hugo shortcode.
|
||||||
|
#
|
||||||
|
# For simplicity, this currently only supports the `key="value"` format.
|
||||||
|
shortcode_params_regex = re.compile(r"(?P<key>\w+)=\"(?P<value>[^\"]+)\"", re.ASCII)
|
||||||
|
|
||||||
def prefix_absolute_path_references(text, base_url):
|
def prefix_absolute_path_references(text, base_url):
|
||||||
"""Adds base_url to absolute-path references.
|
"""Adds base_url to absolute-path references.
|
||||||
|
|
||||||
|
|
@ -44,17 +73,90 @@ def prefix_absolute_path_references(text, base_url):
|
||||||
"""
|
"""
|
||||||
return text.replace("](/", "]({}/".format(base_url))
|
return text.replace("](/", "]({}/".format(base_url))
|
||||||
|
|
||||||
def edit_links(node, base_url):
|
def replace_match(match, replacement):
|
||||||
"""Finds description nodes and makes any links in them absolute."""
|
"""Replaces the regex match by the replacement in the text."""
|
||||||
|
return match.string[:match.start()] + replacement + match.string[match.end():]
|
||||||
|
|
||||||
|
def replace_shortcode(shortcode):
|
||||||
|
"""Replaces the shortcode by a Markdown fallback in the text.
|
||||||
|
|
||||||
|
The supported shortcodes are:
|
||||||
|
|
||||||
|
* boxes/note, boxes/rationale, boxes/warning
|
||||||
|
* added-in, changed-in
|
||||||
|
|
||||||
|
All closing tags (`{{ /shortcode }}`) are replaced with the empty string.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if shortcode['name'].startswith("/"):
|
||||||
|
# This is the end of the shortcode, just remove it.
|
||||||
|
return replace_match(shortcode, "")
|
||||||
|
|
||||||
|
# Parse the parameters of the shortcode
|
||||||
|
params = {}
|
||||||
|
if shortcode['params']:
|
||||||
|
for param in shortcode_params_regex.finditer(shortcode['params']):
|
||||||
|
if param['key']:
|
||||||
|
params[param['key']] = param['value']
|
||||||
|
|
||||||
|
match shortcode['name']:
|
||||||
|
case "boxes/note":
|
||||||
|
return replace_match(shortcode, "**NOTE:** ")
|
||||||
|
case "boxes/rationale":
|
||||||
|
return replace_match(shortcode, "**RATIONALE:** ")
|
||||||
|
case "boxes/warning":
|
||||||
|
return replace_match(shortcode, "**WARNING:** ")
|
||||||
|
case "added-in":
|
||||||
|
version = params['v']
|
||||||
|
if not version:
|
||||||
|
raise ValueError("Missing parameter `v` for `added-in` shortcode")
|
||||||
|
|
||||||
|
return replace_match(shortcode, f"**[Added in `v{version}`]** ")
|
||||||
|
case "changed-in":
|
||||||
|
version = params['v']
|
||||||
|
if not version:
|
||||||
|
raise ValueError("Missing parameter `v` for `changed-in` shortcode")
|
||||||
|
|
||||||
|
return replace_match(shortcode, f"**[Changed in `v{version}`]** ")
|
||||||
|
case _:
|
||||||
|
raise ValueError("Unknown shortcode", shortcode['name'])
|
||||||
|
|
||||||
|
|
||||||
|
def find_and_replace_shortcodes(text):
|
||||||
|
"""Finds Hugo shortcodes and replaces them by a Markdown fallback.
|
||||||
|
|
||||||
|
The supported shortcodes are:
|
||||||
|
|
||||||
|
* boxes/note, boxes/rationale, boxes/warning
|
||||||
|
* added-in, changed-in
|
||||||
|
"""
|
||||||
|
# We use a `while` loop with `search` instead of a `for` loop with
|
||||||
|
# `finditer`, because as soon as we start replacing text, the
|
||||||
|
# indices of the match are invalid.
|
||||||
|
while shortcode := shortcode_regex.search(text):
|
||||||
|
text = replace_shortcode(shortcode)
|
||||||
|
|
||||||
|
return text
|
||||||
|
|
||||||
|
def edit_descriptions(node, base_url):
|
||||||
|
"""Finds description nodes and apply fixes to them.
|
||||||
|
|
||||||
|
The fixes that are applied are:
|
||||||
|
|
||||||
|
* Make links absolute
|
||||||
|
* Replace Hugo shortcodes
|
||||||
|
"""
|
||||||
if isinstance(node, dict):
|
if isinstance(node, dict):
|
||||||
for key in node:
|
for key in node:
|
||||||
if isinstance(node[key], str):
|
if isinstance(node[key], str):
|
||||||
node[key] = prefix_absolute_path_references(node[key], base_url)
|
node[key] = prefix_absolute_path_references(node[key], base_url)
|
||||||
|
node[key] = find_and_replace_shortcodes(node[key])
|
||||||
else:
|
else:
|
||||||
edit_links(node[key], base_url)
|
edit_descriptions(node[key], base_url)
|
||||||
elif isinstance(node, list):
|
elif isinstance(node, list):
|
||||||
for item in node:
|
for item in node:
|
||||||
edit_links(item, base_url)
|
edit_descriptions(item, base_url)
|
||||||
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
"dump-openapi.py - assemble the OpenAPI specs into a single JSON file"
|
"dump-openapi.py - assemble the OpenAPI specs into a single JSON file"
|
||||||
|
|
@ -164,7 +266,7 @@ for filename in os.listdir(selected_api_dir):
|
||||||
if untagged != 0:
|
if untagged != 0:
|
||||||
print("{} untagged operations, you may want to look into fixing that.".format(untagged))
|
print("{} untagged operations, you may want to look into fixing that.".format(untagged))
|
||||||
|
|
||||||
edit_links(output, base_url)
|
edit_descriptions(output, base_url)
|
||||||
|
|
||||||
print("Generating %s" % output_file)
|
print("Generating %s" % output_file)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue