ruma_client_api/discovery/get_supported_versions.rs
1//! `GET /_matrix/client/versions` ([spec])
2//!
3//! Get the versions of the client-server API supported by this homeserver.
4//!
5//! [spec]: https://spec.matrix.org/latest/client-server-api/#get_matrixclientversions
6
7use std::collections::BTreeMap;
8
9use ruma_common::{
10 api::{auth_scheme::AccessTokenOptional, request, response, SupportedVersions},
11 metadata,
12};
13
14metadata! {
15 method: GET,
16 rate_limited: false,
17 authentication: AccessTokenOptional,
18 path: "/_matrix/client/versions",
19}
20
21/// Request type for the `api_versions` endpoint.
22#[request(error = crate::Error)]
23#[derive(Default)]
24pub struct Request {}
25
26/// Response type for the `api_versions` endpoint.
27#[response(error = crate::Error)]
28pub struct Response {
29 /// A list of Matrix client API protocol versions supported by the homeserver.
30 pub versions: Vec<String>,
31
32 /// Experimental features supported by the server.
33 ///
34 /// Servers can enable some unstable features only for some users, so this
35 /// list might differ when an access token is provided.
36 #[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
37 pub unstable_features: BTreeMap<String, bool>,
38}
39
40impl Request {
41 /// Creates an empty `Request`.
42 pub fn new() -> Self {
43 Self {}
44 }
45}
46
47impl Response {
48 /// Creates a new `Response` with the given `versions`.
49 pub fn new(versions: Vec<String>) -> Self {
50 Self { versions, unstable_features: BTreeMap::new() }
51 }
52
53 /// Convert this `Response` into a [`SupportedVersions`] that can be used with
54 /// `OutgoingRequest::try_into_http_request()`.
55 ///
56 /// Matrix versions that can't be parsed to a `MatrixVersion`, and features with the boolean
57 /// value set to `false` are discarded.
58 pub fn as_supported_versions(&self) -> SupportedVersions {
59 SupportedVersions::from_parts(&self.versions, &self.unstable_features)
60 }
61}