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