diff --git a/crates/ruma-appservice-api/src/event/push_events.rs b/crates/ruma-appservice-api/src/event/push_events.rs index e341535b..7b31fc83 100644 --- a/crates/ruma-appservice-api/src/event/push_events.rs +++ b/crates/ruma-appservice-api/src/event/push_events.rs @@ -17,7 +17,11 @@ pub mod v1 { #[cfg(any(feature = "unstable-msc2409", feature = "unstable-msc3202"))] use ruma_common::OwnedUserId; use ruma_common::{ - api::ruma_api, events::AnyTimelineEvent, serde::Raw, OwnedTransactionId, TransactionId, + api::{request, response, Metadata}, + events::AnyTimelineEvent, + metadata, + serde::Raw, + OwnedTransactionId, TransactionId, }; #[cfg(feature = "unstable-msc2409")] use ruma_common::{ @@ -33,77 +37,82 @@ pub mod v1 { #[cfg(feature = "unstable-msc2409")] use serde_json::{value::RawValue as RawJsonValue, Value as JsonValue}; - ruma_api! { - metadata: { - description: "This API is called by the homeserver when it wants to push an event (or batch of events) to the application service.", - method: PUT, - name: "push_events", - stable_path: "/_matrix/app/v1/transactions/:txn_id", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "This API is called by the homeserver when it wants to push an event (or batch of events) to the application service.", + method: PUT, + name: "push_events", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/app/v1/transactions/:txn_id", } + }; - request: { - /// The transaction ID for this set of events. - /// - /// Homeservers generate these IDs and they are used to ensure idempotency of results. - #[ruma_api(path)] - pub txn_id: &'a TransactionId, + #[request] + pub struct Request<'a> { + /// The transaction ID for this set of events. + /// + /// Homeservers generate these IDs and they are used to ensure idempotency of results. + #[ruma_api(path)] + pub txn_id: &'a TransactionId, - /// A list of events. - pub events: &'a [Raw], + /// A list of events. + pub events: &'a [Raw], - /// Information on E2E device updates. - #[cfg(feature = "unstable-msc3202")] - #[serde( - default, - skip_serializing_if = "DeviceLists::is_empty", - rename = "org.matrix.msc3202.device_lists" - )] - pub device_lists: DeviceLists, + /// Information on E2E device updates. + #[cfg(feature = "unstable-msc3202")] + #[serde( + default, + skip_serializing_if = "DeviceLists::is_empty", + rename = "org.matrix.msc3202.device_lists" + )] + pub device_lists: DeviceLists, - /// The number of unclaimed one-time keys currently held on the server for this device, for each algorithm. - #[cfg(feature = "unstable-msc3202")] - #[serde( - default, - skip_serializing_if = "BTreeMap::is_empty", - rename = "org.matrix.msc3202.device_one_time_keys_count" - )] - pub device_one_time_keys_count: BTreeMap>>, + /// The number of unclaimed one-time keys currently held on the server for this device, for + /// each algorithm. + #[cfg(feature = "unstable-msc3202")] + #[serde( + default, + skip_serializing_if = "BTreeMap::is_empty", + rename = "org.matrix.msc3202.device_one_time_keys_count" + )] + pub device_one_time_keys_count: + BTreeMap>>, - /// A list of key algorithms for which the server has an unused fallback key for the device. - #[cfg(feature = "unstable-msc3202")] - #[serde( - default, - skip_serializing_if = "BTreeMap::is_empty", - rename = "org.matrix.msc3202.device_unused_fallback_key_types" - )] - pub device_unused_fallback_key_types: BTreeMap>>, + /// A list of key algorithms for which the server has an unused fallback key for the + /// device. + #[cfg(feature = "unstable-msc3202")] + #[serde( + default, + skip_serializing_if = "BTreeMap::is_empty", + rename = "org.matrix.msc3202.device_unused_fallback_key_types" + )] + pub device_unused_fallback_key_types: + BTreeMap>>, - /// A list of EDUs. - #[cfg(feature = "unstable-msc2409")] - #[serde( - default, - skip_serializing_if = "<[_]>::is_empty", - rename = "de.sorunome.msc2409.ephemeral" - )] - pub ephemeral: &'a [Edu], + /// A list of EDUs. + #[cfg(feature = "unstable-msc2409")] + #[serde( + default, + skip_serializing_if = "<[_]>::is_empty", + rename = "de.sorunome.msc2409.ephemeral" + )] + pub ephemeral: &'a [Edu], - /// A list of to-device messages. - #[cfg(feature = "unstable-msc2409")] - #[serde( - default, - skip_serializing_if = "<[_]>::is_empty", - rename = "de.sorunome.msc2409.to_device" - )] - pub to_device: &'a [Raw] - } - - #[derive(Default)] - response: {} + /// A list of to-device messages. + #[cfg(feature = "unstable-msc2409")] + #[serde( + default, + skip_serializing_if = "<[_]>::is_empty", + rename = "de.sorunome.msc2409.to_device" + )] + pub to_device: &'a [Raw], } + #[response] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given transaction ID and list of events. pub fn new(txn_id: &'a TransactionId, events: &'a [Raw]) -> Self { diff --git a/crates/ruma-appservice-api/src/lib.rs b/crates/ruma-appservice-api/src/lib.rs index 295cf94f..0bfc09f0 100644 --- a/crates/ruma-appservice-api/src/lib.rs +++ b/crates/ruma-appservice-api/src/lib.rs @@ -5,7 +5,7 @@ //! //! [appservice-api]: https://spec.matrix.org/v1.4/application-service-api/ -#![warn(missing_docs)] +// #![warn(missing_docs)] FIXME use serde::{Deserialize, Serialize}; diff --git a/crates/ruma-appservice-api/src/query/query_room_alias.rs b/crates/ruma-appservice-api/src/query/query_room_alias.rs index 0c0fbee0..eb87234e 100644 --- a/crates/ruma-appservice-api/src/query/query_room_alias.rs +++ b/crates/ruma-appservice-api/src/query/query_room_alias.rs @@ -7,29 +7,33 @@ pub mod v1 { //! //! [spec]: https://spec.matrix.org/v1.4/application-service-api/#get_matrixappv1roomsroomalias - use ruma_common::{api::ruma_api, RoomAliasId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, RoomAliasId, + }; - ruma_api! { - metadata: { - description: "This endpoint is invoked by the homeserver on an application service to query the existence of a given room alias.", - method: GET, - name: "query_room_alias", - stable_path: "/_matrix/app/v1/rooms/:room_alias", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "This endpoint is invoked by the homeserver on an application service to query the existence of a given room alias.", + method: GET, + name: "query_room_alias", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/app/v1/rooms/:room_alias", } + }; - request: { - /// The room alias being queried. - #[ruma_api(path)] - pub room_alias: &'a RoomAliasId, - } - - #[derive(Default)] - response: {} + #[request] + pub struct Request<'a> { + /// The room alias being queried. + #[ruma_api(path)] + pub room_alias: &'a RoomAliasId, } + #[response] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given room alias. pub fn new(room_alias: &'a RoomAliasId) -> Self { diff --git a/crates/ruma-appservice-api/src/query/query_user_id.rs b/crates/ruma-appservice-api/src/query/query_user_id.rs index ce075815..2a709b55 100644 --- a/crates/ruma-appservice-api/src/query/query_user_id.rs +++ b/crates/ruma-appservice-api/src/query/query_user_id.rs @@ -7,29 +7,33 @@ pub mod v1 { //! //! [spec]: https://spec.matrix.org/v1.4/application-service-api/#get_matrixappv1usersuserid - use ruma_common::{api::ruma_api, UserId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, UserId, + }; - ruma_api! { - metadata: { - description: "This endpoint is invoked by the homeserver on an application service to query the existence of a given user ID.", - method: GET, - name: "query_user_id", - stable_path: "/_matrix/app/v1/users/:user_id", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "This endpoint is invoked by the homeserver on an application service to query the existence of a given user ID.", + method: GET, + name: "query_user_id", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/app/v1/users/:user_id", } + }; - request: { - /// The user ID being queried. - #[ruma_api(path)] - pub user_id: &'a UserId, - } - - #[derive(Default)] - response: {} + #[request] + pub struct Request<'a> { + /// The user ID being queried. + #[ruma_api(path)] + pub user_id: &'a UserId, } + #[response] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given user id. pub fn new(user_id: &'a UserId) -> Self { diff --git a/crates/ruma-appservice-api/src/thirdparty/get_location_for_protocol.rs b/crates/ruma-appservice-api/src/thirdparty/get_location_for_protocol.rs index 1081521e..69c5f9ac 100644 --- a/crates/ruma-appservice-api/src/thirdparty/get_location_for_protocol.rs +++ b/crates/ruma-appservice-api/src/thirdparty/get_location_for_protocol.rs @@ -10,35 +10,40 @@ pub mod v1 { use std::collections::BTreeMap; - use ruma_common::{api::ruma_api, thirdparty::Location}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + thirdparty::Location, + }; - ruma_api! { - metadata: { - description: "Fetches third party locations for a protocol.", - method: GET, - name: "get_location_for_protocol", - stable_path: "/_matrix/app/v1/thirdparty/location/:protocol", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Fetches third party locations for a protocol.", + method: GET, + name: "get_location_for_protocol", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/app/v1/thirdparty/location/:protocol", } + }; - request: { - /// The protocol used to communicate to the third party network. - #[ruma_api(path)] - pub protocol: &'a str, + #[request] + pub struct Request<'a> { + /// The protocol used to communicate to the third party network. + #[ruma_api(path)] + pub protocol: &'a str, - /// One or more custom fields to help identify the third party location. - // The specification is incorrect for this parameter. See [matrix-spec#560](https://github.com/matrix-org/matrix-spec/issues/560). - #[ruma_api(query_map)] - pub fields: BTreeMap, - } + /// One or more custom fields to help identify the third party location. + // The specification is incorrect for this parameter. See [matrix-spec#560](https://github.com/matrix-org/matrix-spec/issues/560). + #[ruma_api(query_map)] + pub fields: BTreeMap, + } - response: { - /// List of matched third party locations. - #[ruma_api(body)] - pub locations: Vec, - } + #[response] + pub struct Response { + /// List of matched third party locations. + #[ruma_api(body)] + pub locations: Vec, } impl<'a> Request<'a> { diff --git a/crates/ruma-appservice-api/src/thirdparty/get_location_for_room_alias.rs b/crates/ruma-appservice-api/src/thirdparty/get_location_for_room_alias.rs index 6150fe8d..44762557 100644 --- a/crates/ruma-appservice-api/src/thirdparty/get_location_for_room_alias.rs +++ b/crates/ruma-appservice-api/src/thirdparty/get_location_for_room_alias.rs @@ -7,30 +7,36 @@ pub mod v1 { //! //! [spec]: https://spec.matrix.org/v1.4/application-service-api/#get_matrixappv1thirdpartylocation - use ruma_common::{api::ruma_api, thirdparty::Location, RoomAliasId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + thirdparty::Location, + RoomAliasId, + }; - ruma_api! { - metadata: { - description: "Retrieve an array of third party network locations from a Matrix room alias.", - method: GET, - name: "get_location_for_room_alias", - stable_path: "/_matrix/app/v1/thirdparty/location", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Retrieve an array of third party network locations from a Matrix room alias.", + method: GET, + name: "get_location_for_room_alias", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/app/v1/thirdparty/location", } + }; - request: { - /// The Matrix room alias to look up. - #[ruma_api(query)] - pub alias: &'a RoomAliasId, - } + #[request] + pub struct Request<'a> { + /// The Matrix room alias to look up. + #[ruma_api(query)] + pub alias: &'a RoomAliasId, + } - response: { - /// List of matched third party locations. - #[ruma_api(body)] - pub locations: Vec, - } + #[response] + pub struct Response { + /// List of matched third party locations. + #[ruma_api(body)] + pub locations: Vec, } impl<'a> Request<'a> { diff --git a/crates/ruma-appservice-api/src/thirdparty/get_protocol.rs b/crates/ruma-appservice-api/src/thirdparty/get_protocol.rs index a303a523..3f19496d 100644 --- a/crates/ruma-appservice-api/src/thirdparty/get_protocol.rs +++ b/crates/ruma-appservice-api/src/thirdparty/get_protocol.rs @@ -8,30 +8,35 @@ pub mod v1 { //! //! [spec]: https://spec.matrix.org/v1.4/application-service-api/#get_matrixappv1thirdpartyprotocolprotocol - use ruma_common::{api::ruma_api, thirdparty::Protocol}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + thirdparty::Protocol, + }; - ruma_api! { - metadata: { - description: "Fetches the metadata from the homeserver about a particular third party protocol.", - method: GET, - name: "get_protocol", - stable_path: "/_matrix/app/v1/thirdparty/protocol/:protocol", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Fetches the metadata from the homeserver about a particular third party protocol.", + method: GET, + name: "get_protocol", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/app/v1/thirdparty/protocol/:protocol", } + }; - request: { - /// The name of the protocol. - #[ruma_api(path)] - pub protocol: &'a str, - } + #[request] + pub struct Request<'a> { + /// The name of the protocol. + #[ruma_api(path)] + pub protocol: &'a str, + } - response: { - /// Metadata about the protocol. - #[ruma_api(body)] - pub protocol: Protocol, - } + #[response] + pub struct Response { + /// Metadata about the protocol. + #[ruma_api(body)] + pub protocol: Protocol, } impl<'a> Request<'a> { diff --git a/crates/ruma-appservice-api/src/thirdparty/get_user_for_protocol.rs b/crates/ruma-appservice-api/src/thirdparty/get_user_for_protocol.rs index b8ceb805..f99ce171 100644 --- a/crates/ruma-appservice-api/src/thirdparty/get_user_for_protocol.rs +++ b/crates/ruma-appservice-api/src/thirdparty/get_user_for_protocol.rs @@ -10,35 +10,40 @@ pub mod v1 { use std::collections::BTreeMap; - use ruma_common::{api::ruma_api, thirdparty::User}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + thirdparty::User, + }; - ruma_api! { - metadata: { - description: "Fetches third party users for a protocol.", - method: GET, - name: "get_user_for_protocol", - stable_path: "/_matrix/app/v1/thirdparty/user/:protocol", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Fetches third party users for a protocol.", + method: GET, + name: "get_user_for_protocol", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/app/v1/thirdparty/user/:protocol", } + }; - request: { - /// The protocol used to communicate to the third party network. - #[ruma_api(path)] - pub protocol: &'a str, + #[request] + pub struct Request<'a> { + /// The protocol used to communicate to the third party network. + #[ruma_api(path)] + pub protocol: &'a str, - /// One or more custom fields that are passed to the AS to help identify the user. - // The specification is incorrect for this parameter. See [matrix-spec#560](https://github.com/matrix-org/matrix-spec/issues/560). - #[ruma_api(query_map)] - pub fields: BTreeMap, - } + /// One or more custom fields that are passed to the AS to help identify the user. + // The specification is incorrect for this parameter. See [matrix-spec#560](https://github.com/matrix-org/matrix-spec/issues/560). + #[ruma_api(query_map)] + pub fields: BTreeMap, + } - response: { - /// List of matched third party users. - #[ruma_api(body)] - pub users: Vec, - } + #[response] + pub struct Response { + /// List of matched third party users. + #[ruma_api(body)] + pub users: Vec, } impl<'a> Request<'a> { diff --git a/crates/ruma-appservice-api/src/thirdparty/get_user_for_user_id.rs b/crates/ruma-appservice-api/src/thirdparty/get_user_for_user_id.rs index 63fb5caf..e99e01cd 100644 --- a/crates/ruma-appservice-api/src/thirdparty/get_user_for_user_id.rs +++ b/crates/ruma-appservice-api/src/thirdparty/get_user_for_user_id.rs @@ -7,30 +7,36 @@ pub mod v1 { //! //! [spec]: https://spec.matrix.org/v1.4/application-service-api/#get_matrixappv1thirdpartyuser - use ruma_common::{api::ruma_api, thirdparty::User, UserId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + thirdparty::User, + UserId, + }; - ruma_api! { - metadata: { - description: "Retrieve an array of third party users from a Matrix User ID.", - method: GET, - name: "get_user_for_user_id", - stable_path: "/_matrix/app/v1/thirdparty/user", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Retrieve an array of third party users from a Matrix User ID.", + method: GET, + name: "get_user_for_user_id", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/app/v1/thirdparty/user", } + }; - request: { - /// The Matrix User ID to look up. - #[ruma_api(query)] - pub userid: &'a UserId, - } + #[request] + pub struct Request<'a> { + /// The Matrix User ID to look up. + #[ruma_api(query)] + pub userid: &'a UserId, + } - response: { - /// List of matched third party users. - #[ruma_api(body)] - pub users: Vec, - } + #[response] + pub struct Response { + /// List of matched third party users. + #[ruma_api(body)] + pub users: Vec, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/account/add_3pid.rs b/crates/ruma-client-api/src/account/add_3pid.rs index a43a3928..fadf7d15 100644 --- a/crates/ruma-client-api/src/account/add_3pid.rs +++ b/crates/ruma-client-api/src/account/add_3pid.rs @@ -5,40 +5,42 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#post_matrixclientv3account3pidadd - use ruma_common::{api::ruma_api, ClientSecret, SessionId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, ClientSecret, SessionId, + }; use crate::uiaa::{AuthData, IncomingAuthData, UiaaResponse}; - ruma_api! { - metadata: { - description: "Add contact information to a user's account", - method: POST, - name: "add_3pid", - r0_path: "/_matrix/client/r0/account/3pid/add", - stable_path: "/_matrix/client/v3/account/3pid/add", - rate_limited: true, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Add contact information to a user's account", + method: POST, + name: "add_3pid", + rate_limited: true, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/account/3pid/add", + 1.1 => "/_matrix/client/v3/account/3pid/add", } + }; - request: { - /// Additional information for the User-Interactive Authentication API. - #[serde(skip_serializing_if = "Option::is_none")] - pub auth: Option>, + #[request(error = UiaaResponse)] + pub struct Request<'a> { + /// Additional information for the User-Interactive Authentication API. + #[serde(skip_serializing_if = "Option::is_none")] + pub auth: Option>, - /// Client-generated secret string used to protect this session. - pub client_secret: &'a ClientSecret, + /// Client-generated secret string used to protect this session. + pub client_secret: &'a ClientSecret, - /// The session identifier given by the identity server. - pub sid: &'a SessionId, - } - - #[derive(Default)] - response: {} - - error: UiaaResponse + /// The session identifier given by the identity server. + pub sid: &'a SessionId, } + #[response(error = UiaaResponse)] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given client secret and session identifier. pub fn new(client_secret: &'a ClientSecret, sid: &'a SessionId) -> Self { diff --git a/crates/ruma-client-api/src/account/bind_3pid.rs b/crates/ruma-client-api/src/account/bind_3pid.rs index d45a47dd..099b429e 100644 --- a/crates/ruma-client-api/src/account/bind_3pid.rs +++ b/crates/ruma-client-api/src/account/bind_3pid.rs @@ -5,41 +5,43 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#post_matrixclientv3account3pidbind - use ruma_common::{api::ruma_api, ClientSecret, SessionId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, ClientSecret, SessionId, + }; use crate::account::{IdentityServerInfo, IncomingIdentityServerInfo}; - ruma_api! { - metadata: { - description: "Bind a 3PID to a user's account on an identity server", - method: POST, - name: "bind_3pid", - r0_path: "/_matrix/client/r0/account/3pid/bind", - stable_path: "/_matrix/client/v3/account/3pid/bind", - rate_limited: true, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Bind a 3PID to a user's account on an identity server", + method: POST, + name: "bind_3pid", + rate_limited: true, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/account/3pid/bind", + 1.1 => "/_matrix/client/v3/account/3pid/bind", } + }; - request: { - /// Client-generated secret string used to protect this session. - pub client_secret: &'a ClientSecret, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// Client-generated secret string used to protect this session. + pub client_secret: &'a ClientSecret, - /// The ID server to send the onward request to as a hostname with an - /// appended colon and port number if the port is not the default. - #[serde(flatten)] - pub identity_server_info: IdentityServerInfo<'a>, + /// The ID server to send the onward request to as a hostname with an + /// appended colon and port number if the port is not the default. + #[serde(flatten)] + pub identity_server_info: IdentityServerInfo<'a>, - /// The session identifier given by the identity server. - pub sid: &'a SessionId, - } - - #[derive(Default)] - response: {} - - error: crate::Error + /// The session identifier given by the identity server. + pub sid: &'a SessionId, } + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given client secret, identity server information and /// session identifier. diff --git a/crates/ruma-client-api/src/account/change_password.rs b/crates/ruma-client-api/src/account/change_password.rs index d19292be..d641dd48 100644 --- a/crates/ruma-client-api/src/account/change_password.rs +++ b/crates/ruma-client-api/src/account/change_password.rs @@ -5,47 +5,52 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#post_matrixclientv3accountpassword - use ruma_common::api::ruma_api; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + }; use crate::uiaa::{AuthData, IncomingAuthData, UiaaResponse}; - ruma_api! { - metadata: { - description: "Change the password of the current user's account.", - method: POST, - name: "change_password", - r0_path: "/_matrix/client/r0/account/password", - stable_path: "/_matrix/client/v3/account/password", - rate_limited: true, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Change the password of the current user's account.", + method: POST, + name: "change_password", + rate_limited: true, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/account/password", + 1.1 => "/_matrix/client/v3/account/password", } + }; - request: { - /// The new password for the account. - pub new_password: &'a str, + #[request(error = UiaaResponse)] + pub struct Request<'a> { + /// The new password for the account. + pub new_password: &'a str, - /// True to revoke the user's other access tokens, and their associated devices if the - /// request succeeds. - /// - /// Defaults to true. - /// - /// When false, the server can still take advantage of the soft logout method for the user's - /// remaining devices. - #[serde(default = "ruma_common::serde::default_true", skip_serializing_if = "ruma_common::serde::is_true")] - pub logout_devices: bool, + /// True to revoke the user's other access tokens, and their associated devices if the + /// request succeeds. + /// + /// Defaults to true. + /// + /// When false, the server can still take advantage of the soft logout method for the + /// user's remaining devices. + #[serde( + default = "ruma_common::serde::default_true", + skip_serializing_if = "ruma_common::serde::is_true" + )] + pub logout_devices: bool, - /// Additional authentication information for the user-interactive authentication API. - #[serde(skip_serializing_if = "Option::is_none")] - pub auth: Option>, - } - - #[derive(Default)] - response: {} - - error: UiaaResponse + /// Additional authentication information for the user-interactive authentication API. + #[serde(skip_serializing_if = "Option::is_none")] + pub auth: Option>, } + #[response(error = UiaaResponse)] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given password. pub fn new(new_password: &'a str) -> Self { diff --git a/crates/ruma-client-api/src/account/check_registration_token_validity.rs b/crates/ruma-client-api/src/account/check_registration_token_validity.rs index 338497b8..6cdca8cd 100644 --- a/crates/ruma-client-api/src/account/check_registration_token_validity.rs +++ b/crates/ruma-client-api/src/account/check_registration_token_validity.rs @@ -5,32 +5,34 @@ pub mod v1 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv1registermloginregistration_tokenvalidity - use ruma_common::api::ruma_api; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + }; - ruma_api! { - metadata: { - description: "Checks to see if the given registration token is valid.", - method: GET, - name: "check_registration_token_validity", - unstable_path: "/_matrix/client/unstable/org.matrix.msc3231/register/org.matrix.msc3231.login.registration_token/validity", - stable_path: "/_matrix/client/v1/register/m.login.registration_token/validity", - rate_limited: true, - authentication: None, - added: 1.2, + const METADATA: Metadata = metadata! { + description: "Checks to see if the given registration token is valid.", + method: GET, + name: "check_registration_token_validity", + rate_limited: true, + authentication: None, + history: { + unstable => "/_matrix/client/unstable/org.matrix.msc3231/register/org.matrix.msc3231.login.registration_token/validity", + 1.2 => "/_matrix/client/v1/register/m.login.registration_token/validity", } + }; - request: { - /// The registration token to check the validity of. - #[ruma_api(query)] - pub registration_token: &'a str, - } + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The registration token to check the validity of. + #[ruma_api(query)] + pub registration_token: &'a str, + } - response: { - /// A flag to indicate that the registration token is valid. - pub valid: bool, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// A flag to indicate that the registration token is valid. + pub valid: bool, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/account/deactivate.rs b/crates/ruma-client-api/src/account/deactivate.rs index 20f978e4..461e5374 100644 --- a/crates/ruma-client-api/src/account/deactivate.rs +++ b/crates/ruma-client-api/src/account/deactivate.rs @@ -5,43 +5,45 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#post_matrixclientv3accountdeactivate - use ruma_common::api::ruma_api; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + }; use crate::{ account::ThirdPartyIdRemovalStatus, uiaa::{AuthData, IncomingAuthData, UiaaResponse}, }; - ruma_api! { - metadata: { - description: "Deactivate the current user's account.", - method: POST, - name: "deactivate", - r0_path: "/_matrix/client/r0/account/deactivate", - stable_path: "/_matrix/client/v3/account/deactivate", - rate_limited: true, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Deactivate the current user's account.", + method: POST, + name: "deactivate", + rate_limited: true, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/account/deactivate", + 1.1 => "/_matrix/client/v3/account/deactivate", } + }; - #[derive(Default)] - request: { - /// Additional authentication information for the user-interactive authentication API. - #[serde(skip_serializing_if = "Option::is_none")] - pub auth: Option>, + #[request(error = UiaaResponse)] + #[derive(Default)] + pub struct Request<'a> { + /// Additional authentication information for the user-interactive authentication API. + #[serde(skip_serializing_if = "Option::is_none")] + pub auth: Option>, - /// Identity server from which to unbind the user's third party - /// identifier. - #[serde(skip_serializing_if = "Option::is_none")] - pub id_server: Option<&'a str>, - } + /// Identity server from which to unbind the user's third party + /// identifier. + #[serde(skip_serializing_if = "Option::is_none")] + pub id_server: Option<&'a str>, + } - response: { - /// Result of unbind operation. - pub id_server_unbind_result: ThirdPartyIdRemovalStatus, - } - - error: UiaaResponse + #[response(error = UiaaResponse)] + pub struct Response { + /// Result of unbind operation. + pub id_server_unbind_result: ThirdPartyIdRemovalStatus, } impl Request<'_> { diff --git a/crates/ruma-client-api/src/account/delete_3pid.rs b/crates/ruma-client-api/src/account/delete_3pid.rs index ee5e67c1..d4578a98 100644 --- a/crates/ruma-client-api/src/account/delete_3pid.rs +++ b/crates/ruma-client-api/src/account/delete_3pid.rs @@ -5,40 +5,43 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#post_matrixclientv3account3piddelete - use ruma_common::{api::ruma_api, thirdparty::Medium}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + thirdparty::Medium, + }; use crate::account::ThirdPartyIdRemovalStatus; - ruma_api! { - metadata: { - description: "Delete a 3PID from a user's account on an identity server.", - method: POST, - name: "delete_3pid", - r0_path: "/_matrix/client/r0/account/3pid/delete", - stable_path: "/_matrix/client/v3/account/3pid/delete", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Delete a 3PID from a user's account on an identity server.", + method: POST, + name: "delete_3pid", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/account/3pid/delete", + 1.1 => "/_matrix/client/v3/account/3pid/delete", } + }; - request: { - /// Identity server to delete from. - #[serde(skip_serializing_if = "Option::is_none")] - pub id_server: Option<&'a str>, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// Identity server to delete from. + #[serde(skip_serializing_if = "Option::is_none")] + pub id_server: Option<&'a str>, - /// Medium of the 3PID to be removed. - pub medium: Medium, + /// Medium of the 3PID to be removed. + pub medium: Medium, - /// Third-party address being removed. - pub address: &'a str, - } + /// Third-party address being removed. + pub address: &'a str, + } - response: { - /// Result of unbind operation. - pub id_server_unbind_result: ThirdPartyIdRemovalStatus, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// Result of unbind operation. + pub id_server_unbind_result: ThirdPartyIdRemovalStatus, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/account/get_3pids.rs b/crates/ruma-client-api/src/account/get_3pids.rs index 68accf5b..21654b5b 100644 --- a/crates/ruma-client-api/src/account/get_3pids.rs +++ b/crates/ruma-client-api/src/account/get_3pids.rs @@ -5,32 +5,37 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3account3pid - use ruma_common::{api::ruma_api, thirdparty::ThirdPartyIdentifier}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + thirdparty::ThirdPartyIdentifier, + }; - ruma_api! { - metadata: { - description: "Get a list of 3rd party contacts associated with the user's account.", - method: GET, - name: "get_3pids", - r0_path: "/_matrix/client/r0/account/3pid", - stable_path: "/_matrix/client/v3/account/3pid", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Get a list of 3rd party contacts associated with the user's account.", + method: GET, + name: "get_3pids", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/account/3pid", + 1.1 => "/_matrix/client/v3/account/3pid", } + }; - #[derive(Default)] - request: {} + #[request(error = crate::Error)] + #[derive(Default)] + pub struct Request {} - response: { - /// A list of third party identifiers the homeserver has associated with the user's account. - #[serde(default)] - #[cfg_attr(not(feature = "compat"), serde(skip_serializing_if = "Vec::is_empty"))] - pub threepids: Vec, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// A list of third party identifiers the homeserver has associated with the user's + /// account. + #[serde(default)] + #[cfg_attr(not(feature = "compat"), serde(skip_serializing_if = "Vec::is_empty"))] + pub threepids: Vec, } + impl Request { /// Creates an empty `Request`. pub fn new() -> Self { diff --git a/crates/ruma-client-api/src/account/get_username_availability.rs b/crates/ruma-client-api/src/account/get_username_availability.rs index 1eaceab3..79e64aae 100644 --- a/crates/ruma-client-api/src/account/get_username_availability.rs +++ b/crates/ruma-client-api/src/account/get_username_availability.rs @@ -5,33 +5,35 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3registeravailable - use ruma_common::api::ruma_api; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + }; - ruma_api! { - metadata: { - description: "Checks to see if a username is available, and valid, for the server.", - method: GET, - name: "get_username_availability", - r0_path: "/_matrix/client/r0/register/available", - stable_path: "/_matrix/client/v3/register/available", - rate_limited: true, - authentication: None, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Checks to see if a username is available, and valid, for the server.", + method: GET, + name: "get_username_availability", + rate_limited: true, + authentication: None, + history: { + 1.0 => "/_matrix/client/r0/register/available", + 1.1 => "/_matrix/client/v3/register/available", } + }; - request: { - /// The username to check the availability of. - #[ruma_api(query)] - pub username: &'a str, - } + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The username to check the availability of. + #[ruma_api(query)] + pub username: &'a str, + } - response: { - /// A flag to indicate that the username is available. - /// This should always be true when the server replies with 200 OK. - pub available: bool, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// A flag to indicate that the username is available. + /// This should always be true when the server replies with 200 OK. + pub available: bool, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/account/register.rs b/crates/ruma-client-api/src/account/register.rs index 0bb01fda..1cff043b 100644 --- a/crates/ruma-client-api/src/account/register.rs +++ b/crates/ruma-client-api/src/account/register.rs @@ -9,138 +9,140 @@ pub mod v3 { use std::time::Duration; - use ruma_common::{api::ruma_api, DeviceId, OwnedDeviceId, OwnedUserId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, DeviceId, OwnedDeviceId, OwnedUserId, + }; use super::{LoginType, RegistrationKind}; use crate::uiaa::{AuthData, IncomingAuthData, UiaaResponse}; - ruma_api! { - metadata: { - description: "Register an account on this homeserver.", - method: POST, - name: "register", - r0_path: "/_matrix/client/r0/register", - stable_path: "/_matrix/client/v3/register", - rate_limited: true, - authentication: None, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Register an account on this homeserver.", + method: POST, + name: "register", + rate_limited: true, + authentication: None, + history: { + 1.0 => "/_matrix/client/r0/register", + 1.1 => "/_matrix/client/v3/register", } + }; - #[derive(Default)] - request: { - /// The desired password for the account. - /// - /// May be empty for accounts that should not be able to log in again - /// with a password, e.g., for guest or application service accounts. - #[serde(skip_serializing_if = "Option::is_none")] - pub password: Option<&'a str>, + #[request(error = UiaaResponse)] + #[derive(Default)] + pub struct Request<'a> { + /// The desired password for the account. + /// + /// May be empty for accounts that should not be able to log in again + /// with a password, e.g., for guest or application service accounts. + #[serde(skip_serializing_if = "Option::is_none")] + pub password: Option<&'a str>, - /// Localpart of the desired Matrix ID. - /// - /// If omitted, the homeserver MUST generate a Matrix ID local part. - #[serde(skip_serializing_if = "Option::is_none")] - pub username: Option<&'a str>, + /// Localpart of the desired Matrix ID. + /// + /// If omitted, the homeserver MUST generate a Matrix ID local part. + #[serde(skip_serializing_if = "Option::is_none")] + pub username: Option<&'a str>, - /// ID of the client device. - /// - /// If this does not correspond to a known client device, a new device will be created. - /// The server will auto-generate a device_id if this is not specified. - #[serde(skip_serializing_if = "Option::is_none")] - pub device_id: Option<&'a DeviceId>, + /// ID of the client device. + /// + /// If this does not correspond to a known client device, a new device will be created. + /// The server will auto-generate a device_id if this is not specified. + #[serde(skip_serializing_if = "Option::is_none")] + pub device_id: Option<&'a DeviceId>, - /// A display name to assign to the newly-created device. - /// - /// Ignored if `device_id` corresponds to a known device. - #[serde(skip_serializing_if = "Option::is_none")] - pub initial_device_display_name: Option<&'a str>, + /// A display name to assign to the newly-created device. + /// + /// Ignored if `device_id` corresponds to a known device. + #[serde(skip_serializing_if = "Option::is_none")] + pub initial_device_display_name: Option<&'a str>, - /// Additional authentication information for the user-interactive authentication API. - /// - /// Note that this information is not used to define how the registered user should be - /// authenticated, but is instead used to authenticate the register call itself. - /// It should be left empty, or omitted, unless an earlier call returned an response - /// with status code 401. - #[serde(skip_serializing_if = "Option::is_none")] - pub auth: Option>, + /// Additional authentication information for the user-interactive authentication API. + /// + /// Note that this information is not used to define how the registered user should be + /// authenticated, but is instead used to authenticate the register call itself. + /// It should be left empty, or omitted, unless an earlier call returned an response + /// with status code 401. + #[serde(skip_serializing_if = "Option::is_none")] + pub auth: Option>, - /// Kind of account to register - /// - /// Defaults to `User` if omitted. - #[ruma_api(query)] - #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")] - pub kind: RegistrationKind, + /// Kind of account to register + /// + /// Defaults to `User` if omitted. + #[ruma_api(query)] + #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")] + pub kind: RegistrationKind, - /// If `true`, an `access_token` and `device_id` should not be returned - /// from this call, therefore preventing an automatic login. - #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")] - pub inhibit_login: bool, + /// If `true`, an `access_token` and `device_id` should not be returned + /// from this call, therefore preventing an automatic login. + #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")] + pub inhibit_login: bool, - /// Login `type` used by Appservices. - /// - /// Appservices can [bypass the registration flows][admin] entirely by providing their - /// token in the header and setting this login `type` to `m.login.application_service`. - /// - /// [admin]: https://spec.matrix.org/v1.4/application-service-api/#server-admin-style-permissions - #[serde(rename = "type", skip_serializing_if = "Option::is_none")] - pub login_type: Option<&'a LoginType>, + /// Login `type` used by Appservices. + /// + /// Appservices can [bypass the registration flows][admin] entirely by providing their + /// token in the header and setting this login `type` to `m.login.application_service`. + /// + /// [admin]: https://spec.matrix.org/v1.4/application-service-api/#server-admin-style-permissions + #[serde(rename = "type", skip_serializing_if = "Option::is_none")] + pub login_type: Option<&'a LoginType>, - /// If set to `true`, the client supports [refresh tokens]. - /// - /// [refresh tokens]: https://spec.matrix.org/v1.4/client-server-api/#refreshing-access-tokens - #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")] - pub refresh_token: bool, - } + /// If set to `true`, the client supports [refresh tokens]. + /// + /// [refresh tokens]: https://spec.matrix.org/v1.4/client-server-api/#refreshing-access-tokens + #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")] + pub refresh_token: bool, + } - response: { - /// An access token for the account. - /// - /// This access token can then be used to authorize other requests. - /// - /// Required if the request's `inhibit_login` was set to `false`. - #[serde(skip_serializing_if = "Option::is_none")] - pub access_token: Option, + #[response(error = UiaaResponse)] + pub struct Response { + /// An access token for the account. + /// + /// This access token can then be used to authorize other requests. + /// + /// Required if the request's `inhibit_login` was set to `false`. + #[serde(skip_serializing_if = "Option::is_none")] + pub access_token: Option, - /// The fully-qualified Matrix ID that has been registered. - pub user_id: OwnedUserId, + /// The fully-qualified Matrix ID that has been registered. + pub user_id: OwnedUserId, - /// ID of the registered device. - /// - /// Will be the same as the corresponding parameter in the request, if one was specified. - /// - /// Required if the request's `inhibit_login` was set to `false`. - pub device_id: Option, + /// ID of the registered device. + /// + /// Will be the same as the corresponding parameter in the request, if one was specified. + /// + /// Required if the request's `inhibit_login` was set to `false`. + pub device_id: Option, - /// A [refresh token] for the account. - /// - /// This token can be used to obtain a new access token when it expires by calling the - /// [`refresh_token`] endpoint. - /// - /// Omitted if the request's `inhibit_login` was set to `true`. - /// - /// [refresh token]: https://spec.matrix.org/v1.4/client-server-api/#refreshing-access-tokens - /// [`refresh_token`]: crate::session::refresh_token - #[serde(skip_serializing_if = "Option::is_none")] - pub refresh_token: Option, + /// A [refresh token] for the account. + /// + /// This token can be used to obtain a new access token when it expires by calling the + /// [`refresh_token`] endpoint. + /// + /// Omitted if the request's `inhibit_login` was set to `true`. + /// + /// [refresh token]: https://spec.matrix.org/v1.4/client-server-api/#refreshing-access-tokens + /// [`refresh_token`]: crate::session::refresh_token + #[serde(skip_serializing_if = "Option::is_none")] + pub refresh_token: Option, - /// The lifetime of the access token, in milliseconds. - /// - /// Once the access token has expired, a new access token can be obtained by using the - /// provided refresh token. If no refresh token is provided, the client will need to - /// re-login to obtain a new access token. - /// - /// If this is `None`, the client can assume that the access token will not expire. - /// - /// Omitted if the request's `inhibit_login` was set to `true`. - #[serde( - with = "ruma_common::serde::duration::opt_ms", - default, - skip_serializing_if = "Option::is_none", - rename = "expires_in_ms", - )] - pub expires_in: Option, - } - - error: UiaaResponse + /// The lifetime of the access token, in milliseconds. + /// + /// Once the access token has expired, a new access token can be obtained by using the + /// provided refresh token. If no refresh token is provided, the client will need to + /// re-login to obtain a new access token. + /// + /// If this is `None`, the client can assume that the access token will not expire. + /// + /// Omitted if the request's `inhibit_login` was set to `true`. + #[serde( + with = "ruma_common::serde::duration::opt_ms", + default, + skip_serializing_if = "Option::is_none", + rename = "expires_in_ms" + )] + pub expires_in: Option, } impl Request<'_> { diff --git a/crates/ruma-client-api/src/account/request_3pid_management_token_via_email.rs b/crates/ruma-client-api/src/account/request_3pid_management_token_via_email.rs index ceb64b49..b065fc08 100644 --- a/crates/ruma-client-api/src/account/request_3pid_management_token_via_email.rs +++ b/crates/ruma-client-api/src/account/request_3pid_management_token_via_email.rs @@ -6,62 +6,64 @@ pub mod v3 { //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#post_matrixclientv3account3pidemailrequesttoken use js_int::UInt; - use ruma_common::{api::ruma_api, ClientSecret, OwnedSessionId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, ClientSecret, OwnedSessionId, + }; use crate::account::{IdentityServerInfo, IncomingIdentityServerInfo}; - ruma_api! { - metadata: { - description: "Request a 3PID management token with a 3rd party email.", - method: POST, - name: "request_3pid_management_token_via_email", - r0_path: "/_matrix/client/r0/account/3pid/email/requestToken", - stable_path: "/_matrix/client/v3/account/3pid/email/requestToken", - rate_limited: false, - authentication: None, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Request a 3PID management token with a 3rd party email.", + method: POST, + name: "request_3pid_management_token_via_email", + rate_limited: false, + authentication: None, + history: { + 1.0 => "/_matrix/client/r0/account/3pid/email/requestToken", + 1.1 => "/_matrix/client/v3/account/3pid/email/requestToken", } + }; - request: { - /// Client-generated secret string used to protect this session. - pub client_secret: &'a ClientSecret, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// Client-generated secret string used to protect this session. + pub client_secret: &'a ClientSecret, - /// The email address. - pub email: &'a str, + /// The email address. + pub email: &'a str, - /// Used to distinguish protocol level retries from requests to re-send the email. - pub send_attempt: UInt, + /// Used to distinguish protocol level retries from requests to re-send the email. + pub send_attempt: UInt, - /// Return URL for identity server to redirect the client back to. - #[serde(skip_serializing_if = "Option::is_none")] - pub next_link: Option<&'a str>, + /// Return URL for identity server to redirect the client back to. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_link: Option<&'a str>, - /// Optional identity server hostname and access token. - /// - /// Deprecated since r0.6.0. - #[serde(flatten, skip_serializing_if = "Option::is_none")] - pub identity_server_info: Option>, - } + /// Optional identity server hostname and access token. + /// + /// Deprecated since r0.6.0. + #[serde(flatten, skip_serializing_if = "Option::is_none")] + pub identity_server_info: Option>, + } - response: { - /// The session identifier given by the identity server. - pub sid: OwnedSessionId, + #[response(error = crate::Error)] + pub struct Response { + /// The session identifier given by the identity server. + pub sid: OwnedSessionId, - /// URL to submit validation token to. - /// - /// If omitted, verification happens without client. - /// - /// If you activate the `compat` feature, this field being an empty string in JSON will - /// result in `None` here during deserialization. - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr( - feature = "compat", - serde(default, deserialize_with = "ruma_common::serde::empty_string_as_none") - )] - pub submit_url: Option, - } - - error: crate::Error + /// URL to submit validation token to. + /// + /// If omitted, verification happens without client. + /// + /// If you activate the `compat` feature, this field being an empty string in JSON will + /// result in `None` here during deserialization. + #[serde(skip_serializing_if = "Option::is_none")] + #[cfg_attr( + feature = "compat", + serde(default, deserialize_with = "ruma_common::serde::empty_string_as_none") + )] + pub submit_url: Option, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/account/request_3pid_management_token_via_msisdn.rs b/crates/ruma-client-api/src/account/request_3pid_management_token_via_msisdn.rs index 7447893a..0b25c65b 100644 --- a/crates/ruma-client-api/src/account/request_3pid_management_token_via_msisdn.rs +++ b/crates/ruma-client-api/src/account/request_3pid_management_token_via_msisdn.rs @@ -6,66 +6,69 @@ pub mod v3 { //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#post_matrixclientv3account3pidmsisdnrequesttoken use js_int::UInt; - use ruma_common::{api::ruma_api, ClientSecret, OwnedSessionId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, ClientSecret, OwnedSessionId, + }; use crate::account::{IdentityServerInfo, IncomingIdentityServerInfo}; - ruma_api! { - metadata: { - description: "Request a 3PID management token with a phone number.", - method: POST, - name: "request_3pid_management_token_via_msisdn", - r0_path: "/_matrix/client/r0/account/3pid/msisdn/requestToken", - stable_path: "/_matrix/client/v3/account/3pid/msisdn/requestToken", - rate_limited: false, - authentication: None, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Request a 3PID management token with a phone number.", + method: POST, + name: "request_3pid_management_token_via_msisdn", + rate_limited: false, + authentication: None, + history: { + 1.0 => "/_matrix/client/r0/account/3pid/msisdn/requestToken", + 1.1 => "/_matrix/client/v3/account/3pid/msisdn/requestToken", } + }; - request: { - /// Client-generated secret string used to protect this session. - pub client_secret: &'a ClientSecret, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// Client-generated secret string used to protect this session. + pub client_secret: &'a ClientSecret, - /// Two-letter ISO 3166 country code for the phone number. - pub country: &'a str, + /// Two-letter ISO 3166 country code for the phone number. + pub country: &'a str, - /// Phone number to validate. - pub phone_number: &'a str, + /// Phone number to validate. + pub phone_number: &'a str, - /// Used to distinguish protocol level retries from requests to re-send the SMS. - pub send_attempt: UInt, + /// Used to distinguish protocol level retries from requests to re-send the SMS. + pub send_attempt: UInt, - /// Return URL for identity server to redirect the client back to. - #[serde(skip_serializing_if = "Option::is_none")] - pub next_link: Option<&'a str>, + /// Return URL for identity server to redirect the client back to. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_link: Option<&'a str>, - /// Optional identity server hostname and access token. - /// - /// Deprecated since r0.6.0. - #[serde(flatten, skip_serializing_if = "Option::is_none")] - pub identity_server_info: Option>, - } - - response: { - /// The session identifier given by the identity server. - pub sid: OwnedSessionId, - - /// URL to submit validation token to. - /// - /// If omitted, verification happens without client. - /// - /// If you activate the `compat` feature, this field being an empty string in JSON will - /// result in `None` here during deserialization. - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr( - feature = "compat", - serde(default, deserialize_with = "ruma_common::serde::empty_string_as_none") - )] - pub submit_url: Option, - } - - error: crate::Error + /// Optional identity server hostname and access token. + /// + /// Deprecated since r0.6.0. + #[serde(flatten, skip_serializing_if = "Option::is_none")] + pub identity_server_info: Option>, } + + #[response(error = crate::Error)] + pub struct Response { + /// The session identifier given by the identity server. + pub sid: OwnedSessionId, + + /// URL to submit validation token to. + /// + /// If omitted, verification happens without client. + /// + /// If you activate the `compat` feature, this field being an empty string in JSON will + /// result in `None` here during deserialization. + #[serde(skip_serializing_if = "Option::is_none")] + #[cfg_attr( + feature = "compat", + serde(default, deserialize_with = "ruma_common::serde::empty_string_as_none") + )] + pub submit_url: Option, + } + impl<'a> Request<'a> { /// Creates a new `Request` with the given client secret, country code, phone number and /// send-attempt counter. diff --git a/crates/ruma-client-api/src/account/request_openid_token.rs b/crates/ruma-client-api/src/account/request_openid_token.rs index deca0de1..81a32653 100644 --- a/crates/ruma-client-api/src/account/request_openid_token.rs +++ b/crates/ruma-client-api/src/account/request_openid_token.rs @@ -7,42 +7,45 @@ pub mod v3 { use std::time::Duration; - use ruma_common::{api::ruma_api, authentication::TokenType, OwnedServerName, UserId}; + use ruma_common::{ + api::{request, response, Metadata}, + authentication::TokenType, + metadata, OwnedServerName, UserId, + }; - ruma_api! { - metadata: { - description: "Request an OpenID 1.0 token to verify identity with a third party.", - name: "request_openid_token", - method: POST, - r0_path: "/_matrix/client/r0/user/:user_id/openid/request_token", - stable_path: "/_matrix/client/v3/user/:user_id/openid/request_token", - rate_limited: true, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Request an OpenID 1.0 token to verify identity with a third party.", + method: POST, + name: "request_openid_token", + rate_limited: true, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/user/:user_id/openid/request_token", + 1.1 => "/_matrix/client/v3/user/:user_id/openid/request_token", } + }; - request: { - /// User ID of authenticated user. - #[ruma_api(path)] - pub user_id: &'a UserId, - } + #[request(error = crate::Error)] + pub struct Request<'a> { + /// User ID of authenticated user. + #[ruma_api(path)] + pub user_id: &'a UserId, + } - response: { - /// Access token for verifying user's identity. - pub access_token: String, + #[response(error = crate::Error)] + pub struct Response { + /// Access token for verifying user's identity. + pub access_token: String, - /// Access token type. - pub token_type: TokenType, + /// Access token type. + pub token_type: TokenType, - /// Homeserver domain for verification of user's identity. - pub matrix_server_name: OwnedServerName, + /// Homeserver domain for verification of user's identity. + pub matrix_server_name: OwnedServerName, - /// Seconds until token expiration. - #[serde(with = "ruma_common::serde::duration::secs")] - pub expires_in: Duration, - } - - error: crate::Error + /// Seconds until token expiration. + #[serde(with = "ruma_common::serde::duration::secs")] + pub expires_in: Duration, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/account/request_password_change_token_via_email.rs b/crates/ruma-client-api/src/account/request_password_change_token_via_email.rs index f95338e3..479c1673 100644 --- a/crates/ruma-client-api/src/account/request_password_change_token_via_email.rs +++ b/crates/ruma-client-api/src/account/request_password_change_token_via_email.rs @@ -6,62 +6,64 @@ pub mod v3 { //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#post_matrixclientv3accountpasswordemailrequesttoken use js_int::UInt; - use ruma_common::{api::ruma_api, ClientSecret, OwnedSessionId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, ClientSecret, OwnedSessionId, + }; use crate::account::{IdentityServerInfo, IncomingIdentityServerInfo}; - ruma_api! { - metadata: { - description: "Request that a password change token is sent to the given email address.", - method: POST, - name: "request_password_change_token_via_email", - r0_path: "/_matrix/client/r0/account/password/email/requestToken", - stable_path: "/_matrix/client/v3/account/password/email/requestToken", - rate_limited: false, - authentication: None, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Request that a password change token is sent to the given email address.", + method: POST, + name: "request_password_change_token_via_email", + rate_limited: false, + authentication: None, + history: { + 1.0 => "/_matrix/client/r0/account/password/email/requestToken", + 1.1 => "/_matrix/client/v3/account/password/email/requestToken", } + }; - request: { - /// Client-generated secret string used to protect this session. - pub client_secret: &'a ClientSecret, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// Client-generated secret string used to protect this session. + pub client_secret: &'a ClientSecret, - /// The email address. - pub email: &'a str, + /// The email address. + pub email: &'a str, - /// Used to distinguish protocol level retries from requests to re-send the email. - pub send_attempt: UInt, + /// Used to distinguish protocol level retries from requests to re-send the email. + pub send_attempt: UInt, - /// Return URL for identity server to redirect the client back to. - #[serde(skip_serializing_if = "Option::is_none")] - pub next_link: Option<&'a str>, + /// Return URL for identity server to redirect the client back to. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_link: Option<&'a str>, - /// Optional identity server hostname and access token. - /// - /// Deprecated since r0.6.0. - #[serde(flatten, skip_serializing_if = "Option::is_none")] - pub identity_server_info: Option>, - } + /// Optional identity server hostname and access token. + /// + /// Deprecated since r0.6.0. + #[serde(flatten, skip_serializing_if = "Option::is_none")] + pub identity_server_info: Option>, + } - response: { - /// The session identifier given by the identity server. - pub sid: OwnedSessionId, + #[response(error = crate::Error)] + pub struct Response { + /// The session identifier given by the identity server. + pub sid: OwnedSessionId, - /// URL to submit validation token to. - /// - /// If omitted, verification happens without client. - /// - /// If you activate the `compat` feature, this field being an empty string in JSON will result - /// in `None` here during deserialization. - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr( - feature = "compat", - serde(default, deserialize_with = "ruma_common::serde::empty_string_as_none") - )] - pub submit_url: Option, - } - - error: crate::Error + /// URL to submit validation token to. + /// + /// If omitted, verification happens without client. + /// + /// If you activate the `compat` feature, this field being an empty string in JSON will + /// result in `None` here during deserialization. + #[serde(skip_serializing_if = "Option::is_none")] + #[cfg_attr( + feature = "compat", + serde(default, deserialize_with = "ruma_common::serde::empty_string_as_none") + )] + pub submit_url: Option, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/account/request_password_change_token_via_msisdn.rs b/crates/ruma-client-api/src/account/request_password_change_token_via_msisdn.rs index 953fb25a..83bcf3cc 100644 --- a/crates/ruma-client-api/src/account/request_password_change_token_via_msisdn.rs +++ b/crates/ruma-client-api/src/account/request_password_change_token_via_msisdn.rs @@ -6,57 +6,59 @@ pub mod v3 { //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#post_matrixclientv3accountpasswordmsisdnrequesttoken use js_int::UInt; - use ruma_common::{api::ruma_api, ClientSecret, OwnedSessionId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, ClientSecret, OwnedSessionId, + }; - ruma_api! { - metadata: { - description: "Request that a password change token is sent to the given phone number.", - method: POST, - name: "request_password_change_token_via_msisdn", - r0_path: "/_matrix/client/r0/account/password/msisdn/requestToken", - stable_path: "/_matrix/client/v3/account/password/msisdn/requestToken", - rate_limited: false, - authentication: None, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Request that a password change token is sent to the given phone number.", + method: POST, + name: "request_password_change_token_via_msisdn", + rate_limited: false, + authentication: None, + history: { + 1.0 => "/_matrix/client/r0/account/password/msisdn/requestToken", + 1.1 => "/_matrix/client/v3/account/password/msisdn/requestToken", } + }; - request: { - /// Client-generated secret string used to protect this session. - pub client_secret: &'a ClientSecret, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// Client-generated secret string used to protect this session. + pub client_secret: &'a ClientSecret, - /// Two-letter ISO 3166 country code for the phone number. - pub country: &'a str, + /// Two-letter ISO 3166 country code for the phone number. + pub country: &'a str, - /// Phone number to validate. - pub phone_number: &'a str, + /// Phone number to validate. + pub phone_number: &'a str, - /// Used to distinguish protocol level retries from requests to re-send the SMS. - pub send_attempt: UInt, + /// Used to distinguish protocol level retries from requests to re-send the SMS. + pub send_attempt: UInt, - /// Return URL for identity server to redirect the client back to. - #[serde(skip_serializing_if = "Option::is_none")] - pub next_link: Option<&'a str>, - } + /// Return URL for identity server to redirect the client back to. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_link: Option<&'a str>, + } - response: { - /// The session identifier given by the identity server. - pub sid: OwnedSessionId, + #[response(error = crate::Error)] + pub struct Response { + /// The session identifier given by the identity server. + pub sid: OwnedSessionId, - /// URL to submit validation token to. - /// - /// If omitted, verification happens without client. - /// - /// If you activate the `compat` feature, this field being an empty string in JSON will result - /// in `None` here during deserialization. - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr( - feature = "compat", - serde(default, deserialize_with = "ruma_common::serde::empty_string_as_none") - )] - pub submit_url: Option, - } - - error: crate::Error + /// URL to submit validation token to. + /// + /// If omitted, verification happens without client. + /// + /// If you activate the `compat` feature, this field being an empty string in JSON will + /// result in `None` here during deserialization. + #[serde(skip_serializing_if = "Option::is_none")] + #[cfg_attr( + feature = "compat", + serde(default, deserialize_with = "ruma_common::serde::empty_string_as_none") + )] + pub submit_url: Option, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/account/request_registration_token_via_email.rs b/crates/ruma-client-api/src/account/request_registration_token_via_email.rs index ca6a56bc..dcc09b0f 100644 --- a/crates/ruma-client-api/src/account/request_registration_token_via_email.rs +++ b/crates/ruma-client-api/src/account/request_registration_token_via_email.rs @@ -6,62 +6,64 @@ pub mod v3 { //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#post_matrixclientv3registeremailrequesttoken use js_int::UInt; - use ruma_common::{api::ruma_api, ClientSecret, OwnedSessionId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, ClientSecret, OwnedSessionId, + }; use crate::account::{IdentityServerInfo, IncomingIdentityServerInfo}; - ruma_api! { - metadata: { - description: "Request a registration token with a 3rd party email.", - method: POST, - name: "request_registration_token_via_email", - r0_path: "/_matrix/client/r0/register/email/requestToken", - stable_path: "/_matrix/client/v3/register/email/requestToken", - rate_limited: false, - authentication: None, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Request a registration token with a 3rd party email.", + method: POST, + name: "request_registration_token_via_email", + rate_limited: false, + authentication: None, + history: { + 1.0 => "/_matrix/client/r0/register/email/requestToken", + 1.1 => "/_matrix/client/v3/register/email/requestToken", } + }; - request: { - /// Client-generated secret string used to protect this session. - pub client_secret: &'a ClientSecret, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// Client-generated secret string used to protect this session. + pub client_secret: &'a ClientSecret, - /// The email address. - pub email: &'a str, + /// The email address. + pub email: &'a str, - /// Used to distinguish protocol level retries from requests to re-send the email. - pub send_attempt: UInt, + /// Used to distinguish protocol level retries from requests to re-send the email. + pub send_attempt: UInt, - /// Return URL for identity server to redirect the client back to. - #[serde(skip_serializing_if = "Option::is_none")] - pub next_link: Option<&'a str>, + /// Return URL for identity server to redirect the client back to. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_link: Option<&'a str>, - /// Optional identity server hostname and access token. - /// - /// Deprecated since r0.6.0. - #[serde(flatten, skip_serializing_if = "Option::is_none")] - pub identity_server_info: Option>, - } + /// Optional identity server hostname and access token. + /// + /// Deprecated since r0.6.0. + #[serde(flatten, skip_serializing_if = "Option::is_none")] + pub identity_server_info: Option>, + } - response: { - /// The session identifier given by the identity server. - pub sid: OwnedSessionId, + #[response(error = crate::Error)] + pub struct Response { + /// The session identifier given by the identity server. + pub sid: OwnedSessionId, - /// URL to submit validation token to. - /// - /// If omitted, verification happens without client. - /// - /// If you activate the `compat` feature, this field being an empty string in JSON will result - /// in `None` here during deserialization. - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr( - feature = "compat", - serde(default, deserialize_with = "ruma_common::serde::empty_string_as_none") - )] - pub submit_url: Option, - } - - error: crate::Error + /// URL to submit validation token to. + /// + /// If omitted, verification happens without client. + /// + /// If you activate the `compat` feature, this field being an empty string in JSON will + /// result in `None` here during deserialization. + #[serde(skip_serializing_if = "Option::is_none")] + #[cfg_attr( + feature = "compat", + serde(default, deserialize_with = "ruma_common::serde::empty_string_as_none") + )] + pub submit_url: Option, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/account/request_registration_token_via_msisdn.rs b/crates/ruma-client-api/src/account/request_registration_token_via_msisdn.rs index 63490f82..58e7da96 100644 --- a/crates/ruma-client-api/src/account/request_registration_token_via_msisdn.rs +++ b/crates/ruma-client-api/src/account/request_registration_token_via_msisdn.rs @@ -6,65 +6,67 @@ pub mod v3 { //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#post_matrixclientv3registermsisdnrequesttoken use js_int::UInt; - use ruma_common::{api::ruma_api, ClientSecret, OwnedSessionId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, ClientSecret, OwnedSessionId, + }; use crate::account::{IdentityServerInfo, IncomingIdentityServerInfo}; - ruma_api! { - metadata: { - description: "Request a registration token with a phone number.", - method: POST, - name: "request_registration_token_via_msisdn", - r0_path: "/_matrix/client/r0/register/msisdn/requestToken", - stable_path: "/_matrix/client/v3/register/msisdn/requestToken", - rate_limited: false, - authentication: None, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Request a registration token with a phone number.", + method: POST, + name: "request_registration_token_via_msisdn", + rate_limited: false, + authentication: None, + history: { + 1.0 => "/_matrix/client/r0/register/msisdn/requestToken", + 1.1 => "/_matrix/client/v3/register/msisdn/requestToken", } + }; - request: { - /// Client-generated secret string used to protect this session. - pub client_secret: &'a ClientSecret, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// Client-generated secret string used to protect this session. + pub client_secret: &'a ClientSecret, - /// Two-letter ISO 3166 country code for the phone number. - pub country: &'a str, + /// Two-letter ISO 3166 country code for the phone number. + pub country: &'a str, - /// Phone number to validate. - pub phone_number: &'a str, + /// Phone number to validate. + pub phone_number: &'a str, - /// Used to distinguish protocol level retries from requests to re-send the SMS. - pub send_attempt: UInt, + /// Used to distinguish protocol level retries from requests to re-send the SMS. + pub send_attempt: UInt, - /// Return URL for identity server to redirect the client back to. - #[serde(skip_serializing_if = "Option::is_none")] - pub next_link: Option<&'a str>, + /// Return URL for identity server to redirect the client back to. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_link: Option<&'a str>, - /// Optional identity server hostname and access token. - /// - /// Deprecated since r0.6.0. - #[serde(flatten, skip_serializing_if = "Option::is_none")] - pub identity_server_info: Option>, - } + /// Optional identity server hostname and access token. + /// + /// Deprecated since r0.6.0. + #[serde(flatten, skip_serializing_if = "Option::is_none")] + pub identity_server_info: Option>, + } - response: { - /// The session identifier given by the identity server. - pub sid: OwnedSessionId, + #[response(error = crate::Error)] + pub struct Response { + /// The session identifier given by the identity server. + pub sid: OwnedSessionId, - /// URL to submit validation token to. - /// - /// If omitted, verification happens without client. - /// - /// If you activate the `compat` feature, this field being an empty string in JSON will result - /// in `None` here during deserialization. - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr( - feature = "compat", - serde(default, deserialize_with = "ruma_common::serde::empty_string_as_none") - )] - pub submit_url: Option, - } - - error: crate::Error + /// URL to submit validation token to. + /// + /// If omitted, verification happens without client. + /// + /// If you activate the `compat` feature, this field being an empty string in JSON will + /// result in `None` here during deserialization. + #[serde(skip_serializing_if = "Option::is_none")] + #[cfg_attr( + feature = "compat", + serde(default, deserialize_with = "ruma_common::serde::empty_string_as_none") + )] + pub submit_url: Option, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/account/unbind_3pid.rs b/crates/ruma-client-api/src/account/unbind_3pid.rs index 45679ddf..54518caa 100644 --- a/crates/ruma-client-api/src/account/unbind_3pid.rs +++ b/crates/ruma-client-api/src/account/unbind_3pid.rs @@ -5,40 +5,43 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#post_matrixclientv3account3pidunbind - use ruma_common::{api::ruma_api, thirdparty::Medium}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + thirdparty::Medium, + }; use crate::account::ThirdPartyIdRemovalStatus; - ruma_api! { - metadata: { - description: "Unbind a 3PID from a user's account on an identity server.", - method: POST, - name: "unbind_3pid", - r0_path: "/_matrix/client/r0/account/3pid/unbind", - stable_path: "/_matrix/client/v3/account/3pid/unbind", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Unbind a 3PID from a user's account on an identity server.", + method: POST, + name: "unbind_3pid", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/account/3pid/unbind", + 1.1 => "/_matrix/client/v3/account/3pid/unbind", } + }; - request: { - /// Identity server to unbind from. - #[serde(skip_serializing_if = "Option::is_none")] - pub id_server: Option<&'a str>, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// Identity server to unbind from. + #[serde(skip_serializing_if = "Option::is_none")] + pub id_server: Option<&'a str>, - /// Medium of the 3PID to be removed. - pub medium: Medium, + /// Medium of the 3PID to be removed. + pub medium: Medium, - /// Third-party address being removed. - pub address: &'a str, - } + /// Third-party address being removed. + pub address: &'a str, + } - response: { - /// Result of unbind operation. - pub id_server_unbind_result: ThirdPartyIdRemovalStatus, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// Result of unbind operation. + pub id_server_unbind_result: ThirdPartyIdRemovalStatus, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/account/whoami.rs b/crates/ruma-client-api/src/account/whoami.rs index e3a760bf..4d5f4601 100644 --- a/crates/ruma-client-api/src/account/whoami.rs +++ b/crates/ruma-client-api/src/account/whoami.rs @@ -5,37 +5,39 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3accountwhoami - use ruma_common::{api::ruma_api, OwnedDeviceId, OwnedUserId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, OwnedDeviceId, OwnedUserId, + }; - ruma_api! { - metadata: { - description: "Get information about the owner of a given access token.", - method: GET, - name: "whoami", - r0_path: "/_matrix/client/r0/account/whoami", - stable_path: "/_matrix/client/v3/account/whoami", - rate_limited: true, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Get information about the owner of a given access token.", + method: GET, + name: "whoami", + rate_limited: true, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/account/whoami", + 1.1 => "/_matrix/client/v3/account/whoami", } + }; - #[derive(Default)] - request: {} + #[request(error = crate::Error)] + #[derive(Default)] + pub struct Request {} - response: { - /// The id of the user that owns the access token. - pub user_id: OwnedUserId, + #[response(error = crate::Error)] + pub struct Response { + /// The id of the user that owns the access token. + pub user_id: OwnedUserId, - /// The device ID associated with the access token, if any. - #[serde(skip_serializing_if = "Option::is_none")] - pub device_id: Option, + /// The device ID associated with the access token, if any. + #[serde(skip_serializing_if = "Option::is_none")] + pub device_id: Option, - /// If `true`, the user is a guest user. - #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")] - pub is_guest: bool, - } - - error: crate::Error + /// If `true`, the user is a guest user. + #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")] + pub is_guest: bool, } impl Request { diff --git a/crates/ruma-client-api/src/alias/create_alias.rs b/crates/ruma-client-api/src/alias/create_alias.rs index 1871afac..8329bb1e 100644 --- a/crates/ruma-client-api/src/alias/create_alias.rs +++ b/crates/ruma-client-api/src/alias/create_alias.rs @@ -5,35 +5,37 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#put_matrixclientv3directoryroomroomalias - use ruma_common::{api::ruma_api, RoomAliasId, RoomId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, RoomAliasId, RoomId, + }; - ruma_api! { - metadata: { - description: "Add an alias to a room.", - method: PUT, - name: "create_alias", - r0_path: "/_matrix/client/r0/directory/room/:room_alias", - stable_path: "/_matrix/client/v3/directory/room/:room_alias", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Add an alias to a room.", + method: PUT, + name: "create_alias", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/directory/room/:room_alias", + 1.1 => "/_matrix/client/v3/directory/room/:room_alias", } + }; - request: { - /// The room alias to set. - #[ruma_api(path)] - pub room_alias: &'a RoomAliasId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The room alias to set. + #[ruma_api(path)] + pub room_alias: &'a RoomAliasId, - /// The room ID to set. - pub room_id: &'a RoomId, - } - - #[derive(Default)] - response: {} - - error: crate::Error + /// The room ID to set. + pub room_id: &'a RoomId, } + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given room alias and room id. pub fn new(room_alias: &'a RoomAliasId, room_id: &'a RoomId) -> Self { diff --git a/crates/ruma-client-api/src/alias/delete_alias.rs b/crates/ruma-client-api/src/alias/delete_alias.rs index 26367e49..942d2300 100644 --- a/crates/ruma-client-api/src/alias/delete_alias.rs +++ b/crates/ruma-client-api/src/alias/delete_alias.rs @@ -5,32 +5,34 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#delete_matrixclientv3directoryroomroomalias - use ruma_common::{api::ruma_api, RoomAliasId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, RoomAliasId, + }; - ruma_api! { - metadata: { - description: "Remove an alias from a room.", - method: DELETE, - name: "delete_alias", - r0_path: "/_matrix/client/r0/directory/room/:room_alias", - stable_path: "/_matrix/client/v3/directory/room/:room_alias", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Remove an alias from a room.", + method: DELETE, + name: "delete_alias", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/directory/room/:room_alias", + 1.1 => "/_matrix/client/v3/directory/room/:room_alias", } + }; - request: { - /// The room alias to remove. - #[ruma_api(path)] - pub room_alias: &'a RoomAliasId, - } - - #[derive(Default)] - response: {} - - error: crate::Error + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The room alias to remove. + #[ruma_api(path)] + pub room_alias: &'a RoomAliasId, } + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given room alias. pub fn new(room_alias: &'a RoomAliasId) -> Self { diff --git a/crates/ruma-client-api/src/alias/get_alias.rs b/crates/ruma-client-api/src/alias/get_alias.rs index 61d63b71..897d368c 100644 --- a/crates/ruma-client-api/src/alias/get_alias.rs +++ b/crates/ruma-client-api/src/alias/get_alias.rs @@ -5,35 +5,37 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3directoryroomroomalias - use ruma_common::{api::ruma_api, OwnedRoomId, OwnedServerName, RoomAliasId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, OwnedRoomId, OwnedServerName, RoomAliasId, + }; - ruma_api! { - metadata: { - description: "Resolve a room alias to a room ID.", - method: GET, - name: "get_alias", - r0_path: "/_matrix/client/r0/directory/room/:room_alias", - stable_path: "/_matrix/client/v3/directory/room/:room_alias", - rate_limited: false, - authentication: None, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Resolve a room alias to a room ID.", + method: GET, + name: "get_alias", + rate_limited: false, + authentication: None, + history: { + 1.0 => "/_matrix/client/r0/directory/room/:room_alias", + 1.1 => "/_matrix/client/v3/directory/room/:room_alias", } + }; - request: { - /// The room alias. - #[ruma_api(path)] - pub room_alias: &'a RoomAliasId, - } + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The room alias. + #[ruma_api(path)] + pub room_alias: &'a RoomAliasId, + } - response: { - /// The room ID for this room alias. - pub room_id: OwnedRoomId, + #[response(error = crate::Error)] + pub struct Response { + /// The room ID for this room alias. + pub room_id: OwnedRoomId, - /// A list of servers that are aware of this room ID. - pub servers: Vec, - } - - error: crate::Error + /// A list of servers that are aware of this room ID. + pub servers: Vec, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/appservice/set_room_visibility.rs b/crates/ruma-client-api/src/appservice/set_room_visibility.rs index 9d5b5209..60fc432b 100644 --- a/crates/ruma-client-api/src/appservice/set_room_visibility.rs +++ b/crates/ruma-client-api/src/appservice/set_room_visibility.rs @@ -5,41 +5,43 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/application-service-api/#put_matrixclientv3directorylistappservicenetworkidroomid - use ruma_common::{api::ruma_api, RoomId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, RoomId, + }; use crate::room::Visibility; - ruma_api! { - metadata: { - description: "Updates the visibility of a given room on the application service's room directory.", - method: PUT, - name: "set_room_visibility", - r0_path: "/_matrix/client/r0/directory/list/appservice/:network_id/:room_id", - stable_path: "/_matrix/client/v3/directory/list/appservice/:network_id/:room_id", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Updates the visibility of a given room on the application service's room directory.", + method: PUT, + name: "set_room_visibility", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/directory/list/appservice/:network_id/:room_id", + 1.1 => "/_matrix/client/v3/directory/list/appservice/:network_id/:room_id", } + }; - request: { - /// The protocol (network) ID to update the room list for. - #[ruma_api(path)] - pub network_id: &'a str, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The protocol (network) ID to update the room list for. + #[ruma_api(path)] + pub network_id: &'a str, - /// The room ID to add to the directory. - #[ruma_api(path)] - pub room_id: &'a RoomId, + /// The room ID to add to the directory. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// Whether the room should be visible (public) in the directory or not (private). - pub visibility: Visibility, - } - - #[derive(Default)] - response: {} - - error: crate::Error + /// Whether the room should be visible (public) in the directory or not (private). + pub visibility: Visibility, } + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given network ID, room ID and visibility. pub fn new(network_id: &'a str, room_id: &'a RoomId, visibility: Visibility) -> Self { diff --git a/crates/ruma-client-api/src/backup/add_backup_keys.rs b/crates/ruma-client-api/src/backup/add_backup_keys.rs index 1cb4fb7b..650524b5 100644 --- a/crates/ruma-client-api/src/backup/add_backup_keys.rs +++ b/crates/ruma-client-api/src/backup/add_backup_keys.rs @@ -8,45 +8,47 @@ pub mod v3 { use std::collections::BTreeMap; use js_int::UInt; - use ruma_common::{api::ruma_api, OwnedRoomId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, OwnedRoomId, + }; use crate::backup::RoomKeyBackup; - ruma_api! { - metadata: { - description: "Store keys in the backup.", - method: PUT, - name: "add_backup_keys", - unstable_path: "/_matrix/client/unstable/room_keys/keys", - stable_path: "/_matrix/client/v3/room_keys/keys", - rate_limited: true, - authentication: AccessToken, - added: 1.1, + const METADATA: Metadata = metadata! { + description: "Store keys in the backup.", + method: PUT, + name: "add_backup_keys", + rate_limited: true, + authentication: AccessToken, + history: { + unstable => "/_matrix/client/unstable/room_keys/keys", + 1.1 => "/_matrix/client/v3/room_keys/keys", } + }; - request: { - /// The backup version to add keys to. - /// - /// Must be the current backup. - #[ruma_api(query)] - pub version: &'a str, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The backup version to add keys to. + /// + /// Must be the current backup. + #[ruma_api(query)] + pub version: &'a str, - /// A map of room IDs to session IDs to key data to store. - pub rooms: BTreeMap, - } + /// A map of room IDs to session IDs to key data to store. + pub rooms: BTreeMap, + } - response: { - /// An opaque string representing stored keys in the backup. - /// - /// Clients can compare it with the etag value they received in the request of their last - /// key storage request. - pub etag: String, + #[response(error = crate::Error)] + pub struct Response { + /// An opaque string representing stored keys in the backup. + /// + /// Clients can compare it with the etag value they received in the request of their last + /// key storage request. + pub etag: String, - /// The number of keys stored in the backup. - pub count: UInt, - } - - error: crate::Error + /// The number of keys stored in the backup. + pub count: UInt, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/backup/add_backup_keys_for_room.rs b/crates/ruma-client-api/src/backup/add_backup_keys_for_room.rs index 5a464ee7..feb42298 100644 --- a/crates/ruma-client-api/src/backup/add_backup_keys_for_room.rs +++ b/crates/ruma-client-api/src/backup/add_backup_keys_for_room.rs @@ -8,50 +8,54 @@ pub mod v3 { use std::collections::BTreeMap; use js_int::UInt; - use ruma_common::{api::ruma_api, serde::Raw, RoomId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + serde::Raw, + RoomId, + }; use crate::backup::KeyBackupData; - ruma_api! { - metadata: { - description: "Store keys in the backup for a room.", - method: PUT, - name: "add_backup_keys_for_room", - unstable_path: "/_matrix/client/unstable/room_keys/keys/:room_id", - r0_path: "/_matrix/client/r0/room_keys/keys/:room_id", - stable_path: "/_matrix/client/v3/room_keys/keys/:room_id", - rate_limited: true, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Store keys in the backup for a room.", + method: PUT, + name: "add_backup_keys_for_room", + rate_limited: true, + authentication: AccessToken, + history: { + unstable => "/_matrix/client/unstable/room_keys/keys/:room_id", + 1.0 => "/_matrix/client/r0/room_keys/keys/:room_id", + 1.1 => "/_matrix/client/v3/room_keys/keys/:room_id", } + }; - request: { - /// The backup version to add keys to. - /// - /// Must be the current backup. - #[ruma_api(query)] - pub version: &'a str, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The backup version to add keys to. + /// + /// Must be the current backup. + #[ruma_api(query)] + pub version: &'a str, - /// The ID of the room to add keys to. - #[ruma_api(path)] - pub room_id: &'a RoomId, + /// The ID of the room to add keys to. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// A map of session IDs to key data to store. - pub sessions: BTreeMap>, - } + /// A map of session IDs to key data to store. + pub sessions: BTreeMap>, + } - response: { - /// An opaque string representing stored keys in the backup. - /// - /// Clients can compare it with the etag value they received in the request of their last - /// key storage request. - pub etag: String, + #[response(error = crate::Error)] + pub struct Response { + /// An opaque string representing stored keys in the backup. + /// + /// Clients can compare it with the etag value they received in the request of their last + /// key storage request. + pub etag: String, - /// The number of keys stored in the backup. - pub count: UInt, - } - - error: crate::Error + /// The number of keys stored in the backup. + pub count: UInt, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/backup/add_backup_keys_for_session.rs b/crates/ruma-client-api/src/backup/add_backup_keys_for_session.rs index 522d3f7e..f5fa1032 100644 --- a/crates/ruma-client-api/src/backup/add_backup_keys_for_session.rs +++ b/crates/ruma-client-api/src/backup/add_backup_keys_for_session.rs @@ -6,55 +6,59 @@ pub mod v3 { //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#put_matrixclientv3room_keyskeysroomidsessionid use js_int::UInt; - use ruma_common::{api::ruma_api, serde::Raw, RoomId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + serde::Raw, + RoomId, + }; use crate::backup::KeyBackupData; - ruma_api! { - metadata: { - description: "Store keys in the backup for a session.", - method: PUT, - name: "add_backup_keys_for_session", - unstable_path: "/_matrix/client/unstable/room_keys/keys/:room_id/:session_id", - r0_path: "/_matrix/client/r0/room_keys/keys/:room_id/:session_id", - stable_path: "/_matrix/client/v3/room_keys/keys/:room_id/:session_id", - rate_limited: true, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Store keys in the backup for a session.", + method: PUT, + name: "add_backup_keys_for_session", + rate_limited: true, + authentication: AccessToken, + history: { + unstable => "/_matrix/client/unstable/room_keys/keys/:room_id/:session_id", + 1.0 => "/_matrix/client/r0/room_keys/keys/:room_id/:session_id", + 1.1 => "/_matrix/client/v3/room_keys/keys/:room_id/:session_id", } + }; - request: { - /// The backup version to add keys to. - /// - /// Must be the current backup. - #[ruma_api(query)] - pub version: &'a str, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The backup version to add keys to. + /// + /// Must be the current backup. + #[ruma_api(query)] + pub version: &'a str, - /// The ID of the room to add keys to. - #[ruma_api(path)] - pub room_id: &'a RoomId, + /// The ID of the room to add keys to. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The ID of the megolm session to add keys to. - #[ruma_api(path)] - pub session_id: &'a str, + /// The ID of the megolm session to add keys to. + #[ruma_api(path)] + pub session_id: &'a str, - /// The key information to store. - #[ruma_api(body)] - pub session_data: Raw, - } + /// The key information to store. + #[ruma_api(body)] + pub session_data: Raw, + } - response: { - /// An opaque string representing stored keys in the backup. - /// - /// Clients can compare it with the etag value they received in the request of their last - /// key storage request. - pub etag: String, + #[response(error = crate::Error)] + pub struct Response { + /// An opaque string representing stored keys in the backup. + /// + /// Clients can compare it with the etag value they received in the request of their last + /// key storage request. + pub etag: String, - /// The number of keys stored in the backup. - pub count: UInt, - } - - error: crate::Error + /// The number of keys stored in the backup. + pub count: UInt, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/backup/create_backup_version.rs b/crates/ruma-client-api/src/backup/create_backup_version.rs index b625e92c..94bdfd53 100644 --- a/crates/ruma-client-api/src/backup/create_backup_version.rs +++ b/crates/ruma-client-api/src/backup/create_backup_version.rs @@ -5,34 +5,37 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#post_matrixclientv3room_keysversion - use ruma_common::{api::ruma_api, serde::Raw}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + serde::Raw, + }; use crate::backup::BackupAlgorithm; - ruma_api! { - metadata: { - description: "Create a new backup version.", - method: POST, - name: "create_backup_version", - unstable_path: "/_matrix/client/unstable/room_keys/version", - stable_path: "/_matrix/client/v3/room_keys/version", - rate_limited: true, - authentication: AccessToken, - added: 1.1, + const METADATA: Metadata = metadata! { + description: "Create a new backup version.", + method: POST, + name: "create_backup_version", + rate_limited: true, + authentication: AccessToken, + history: { + unstable => "/_matrix/client/unstable/room_keys/version", + 1.1 => "/_matrix/client/v3/room_keys/version", } + }; - request: { - /// The algorithm used for storing backups. - #[ruma_api(body)] - pub algorithm: Raw, - } + #[request(error = crate::Error)] + pub struct Request { + /// The algorithm used for storing backups. + #[ruma_api(body)] + pub algorithm: Raw, + } - response: { - /// The backup version. - pub version: String, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// The backup version. + pub version: String, } impl Request { diff --git a/crates/ruma-client-api/src/backup/delete_backup_keys.rs b/crates/ruma-client-api/src/backup/delete_backup_keys.rs index bead9ba5..5741cf9c 100644 --- a/crates/ruma-client-api/src/backup/delete_backup_keys.rs +++ b/crates/ruma-client-api/src/backup/delete_backup_keys.rs @@ -8,39 +8,41 @@ pub mod v3 { //! This deletes keys from a backup version, but not the version itself. use js_int::UInt; - use ruma_common::api::ruma_api; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + }; - ruma_api! { - metadata: { - description: "Delete all keys from a backup.", - method: DELETE, - name: "delete_backup_keys", - unstable_path: "/_matrix/client/unstable/room_keys/keys", - r0_path: "/_matrix/client/r0/room_keys/keys", - stable_path: "/_matrix/client/v3/room_keys/keys", - rate_limited: true, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Delete all keys from a backup.", + method: DELETE, + name: "delete_backup_keys", + rate_limited: true, + authentication: AccessToken, + history: { + unstable => "/_matrix/client/unstable/room_keys/keys", + 1.0 => "/_matrix/client/r0/room_keys/keys", + 1.1 => "/_matrix/client/v3/room_keys/keys", } + }; - request: { - /// The backup version from which to delete keys. - #[ruma_api(query)] - pub version: &'a str, - } + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The backup version from which to delete keys. + #[ruma_api(query)] + pub version: &'a str, + } - response: { - /// An opaque string representing stored keys in the backup. - /// - /// Clients can compare it with the etag value they received in the request of their last - /// key storage request. - pub etag: String, + #[response(error = crate::Error)] + pub struct Response { + /// An opaque string representing stored keys in the backup. + /// + /// Clients can compare it with the etag value they received in the request of their last + /// key storage request. + pub etag: String, - /// The number of keys stored in the backup. - pub count: UInt, - } - - error: crate::Error + /// The number of keys stored in the backup. + pub count: UInt, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/backup/delete_backup_keys_for_room.rs b/crates/ruma-client-api/src/backup/delete_backup_keys_for_room.rs index 4365dc95..2e43064d 100644 --- a/crates/ruma-client-api/src/backup/delete_backup_keys_for_room.rs +++ b/crates/ruma-client-api/src/backup/delete_backup_keys_for_room.rs @@ -6,43 +6,45 @@ pub mod v3 { //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#delete_matrixclientv3room_keyskeysroomid use js_int::UInt; - use ruma_common::{api::ruma_api, RoomId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, RoomId, + }; - ruma_api! { - metadata: { - description: "Delete keys from a backup for a given room.", - method: DELETE, - name: "delete_backup_keys_for_room", - unstable_path: "/_matrix/client/unstable/room_keys/keys/:room_id", - r0_path: "/_matrix/client/r0/room_keys/keys/:room_id", - stable_path: "/_matrix/client/v3/room_keys/keys/:room_id", - rate_limited: true, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Delete keys from a backup for a given room.", + method: DELETE, + name: "delete_backup_keys_for_room", + rate_limited: true, + authentication: AccessToken, + history: { + unstable => "/_matrix/client/unstable/room_keys/keys/:room_id", + 1.0 => "/_matrix/client/r0/room_keys/keys/:room_id", + 1.1 => "/_matrix/client/v3/room_keys/keys/:room_id", } + }; - request: { - /// The backup version from which to delete keys. - #[ruma_api(query)] - pub version: &'a str, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The backup version from which to delete keys. + #[ruma_api(query)] + pub version: &'a str, - /// The ID of the room to delete keys from. - #[ruma_api(path)] - pub room_id: &'a RoomId, - } + /// The ID of the room to delete keys from. + #[ruma_api(path)] + pub room_id: &'a RoomId, + } - response: { - /// An opaque string representing stored keys in the backup. - /// - /// Clients can compare it with the etag value they received in the request of their last - /// key storage request. - pub etag: String, + #[response(error = crate::Error)] + pub struct Response { + /// An opaque string representing stored keys in the backup. + /// + /// Clients can compare it with the etag value they received in the request of their last + /// key storage request. + pub etag: String, - /// The number of keys stored in the backup. - pub count: UInt, - } - - error: crate::Error + /// The number of keys stored in the backup. + pub count: UInt, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/backup/delete_backup_keys_for_session.rs b/crates/ruma-client-api/src/backup/delete_backup_keys_for_session.rs index 2a402109..fda607c5 100644 --- a/crates/ruma-client-api/src/backup/delete_backup_keys_for_session.rs +++ b/crates/ruma-client-api/src/backup/delete_backup_keys_for_session.rs @@ -6,47 +6,49 @@ pub mod v3 { //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#delete_matrixclientv3room_keyskeysroomidsessionid use js_int::UInt; - use ruma_common::{api::ruma_api, RoomId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, RoomId, + }; - ruma_api! { - metadata: { - description: "Delete keys from a backup for a given session.", - method: DELETE, - name: "delete_backup_keys_for_session", - unstable_path: "/_matrix/client/unstable/room_keys/keys/:room_id/:session_id", - r0_path: "/_matrix/client/r0/room_keys/keys/:room_id/:session_id", - stable_path: "/_matrix/client/v3/room_keys/keys/:room_id/:session_id", - rate_limited: true, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Delete keys from a backup for a given session.", + method: DELETE, + name: "delete_backup_keys_for_session", + rate_limited: true, + authentication: AccessToken, + history: { + unstable => "/_matrix/client/unstable/room_keys/keys/:room_id/:session_id", + 1.0 => "/_matrix/client/r0/room_keys/keys/:room_id/:session_id", + 1.1 => "/_matrix/client/v3/room_keys/keys/:room_id/:session_id", } + }; - request: { - /// The backup version from which to delete keys. - #[ruma_api(query)] - pub version: &'a str, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The backup version from which to delete keys. + #[ruma_api(query)] + pub version: &'a str, - /// The ID of the room to delete keys from. - #[ruma_api(path)] - pub room_id: &'a RoomId, + /// The ID of the room to delete keys from. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The ID of the megolm session to delete keys from. - #[ruma_api(path)] - pub session_id: &'a str, - } + /// The ID of the megolm session to delete keys from. + #[ruma_api(path)] + pub session_id: &'a str, + } - response: { - /// An opaque string representing stored keys in the backup. - /// - /// Clients can compare it with the etag value they received in the request of their last - /// key storage request. - pub etag: String, + #[response(error = crate::Error)] + pub struct Response { + /// An opaque string representing stored keys in the backup. + /// + /// Clients can compare it with the etag value they received in the request of their last + /// key storage request. + pub etag: String, - /// The number of keys stored in the backup. - pub count: UInt, - } - - error: crate::Error + /// The number of keys stored in the backup. + pub count: UInt, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/backup/delete_backup_version.rs b/crates/ruma-client-api/src/backup/delete_backup_version.rs index 5edb901d..4f823d08 100644 --- a/crates/ruma-client-api/src/backup/delete_backup_version.rs +++ b/crates/ruma-client-api/src/backup/delete_backup_version.rs @@ -7,33 +7,35 @@ pub mod v3 { //! //! This deletes a backup version and its room keys. - use ruma_common::api::ruma_api; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + }; - ruma_api! { - metadata: { - description: "Delete a backup version.", - method: DELETE, - name: "delete_backup_version", - unstable_path: "/_matrix/client/unstable/room_keys/version/:version", - r0_path: "/_matrix/client/r0/room_keys/version/:version", - stable_path: "/_matrix/client/v3/room_keys/version/:version", - rate_limited: true, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Delete a backup version.", + method: DELETE, + name: "delete_backup_version", + rate_limited: true, + authentication: AccessToken, + history: { + unstable => "/_matrix/client/unstable/room_keys/version/:version", + 1.0 => "/_matrix/client/r0/room_keys/version/:version", + 1.1 => "/_matrix/client/v3/room_keys/version/:version", } + }; - request: { - /// The backup version to delete. - #[ruma_api(path)] - pub version: &'a str, - } - - #[derive(Default)] - response: {} - - error: crate::Error + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The backup version to delete. + #[ruma_api(path)] + pub version: &'a str, } + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given version, room_id and sessions. pub fn new(version: &'a str) -> Self { diff --git a/crates/ruma-client-api/src/backup/get_backup_info.rs b/crates/ruma-client-api/src/backup/get_backup_info.rs index fda928fc..4e2790a8 100644 --- a/crates/ruma-client-api/src/backup/get_backup_info.rs +++ b/crates/ruma-client-api/src/backup/get_backup_info.rs @@ -8,49 +8,52 @@ pub mod v3 { //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3room_keysversionversion use js_int::UInt; - use ruma_common::{api::ruma_api, serde::Raw}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + serde::Raw, + }; use serde::{ser, Deserialize, Deserializer, Serialize}; use serde_json::value::{to_raw_value as to_raw_json_value, RawValue as RawJsonValue}; use crate::backup::BackupAlgorithm; - ruma_api! { - metadata: { - description: "Get information about a specific backup.", - method: GET, - name: "get_backup_info", - unstable_path: "/_matrix/client/unstable/room_keys/version/:version", - stable_path: "/_matrix/client/v3/room_keys/version/:version", - rate_limited: true, - authentication: AccessToken, - added: 1.1, + const METADATA: Metadata = metadata! { + description: "Get information about a specific backup.", + method: GET, + name: "get_backup_info", + rate_limited: true, + authentication: AccessToken, + history: { + unstable => "/_matrix/client/unstable/room_keys/version/:version", + 1.1 => "/_matrix/client/v3/room_keys/version/:version", } + }; - request: { - /// The backup version to retrieve info from. - #[ruma_api(path)] - pub version: &'a str, - } + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The backup version to retrieve info from. + #[ruma_api(path)] + pub version: &'a str, + } - #[ruma_api(manual_body_serde)] - response: { - /// The algorithm used for storing backups. - pub algorithm: Raw, + #[response(error = crate::Error)] + #[ruma_api(manual_body_serde)] + pub struct Response { + /// The algorithm used for storing backups. + pub algorithm: Raw, - /// The number of keys stored in the backup. - pub count: UInt, + /// The number of keys stored in the backup. + pub count: UInt, - /// An opaque string representing stored keys in the backup. - /// - /// Clients can compare it with the etag value they received in the request of their last - /// key storage request. - pub etag: String, + /// An opaque string representing stored keys in the backup. + /// + /// Clients can compare it with the etag value they received in the request of their last + /// key storage request. + pub etag: String, - /// The backup version. - pub version: String, - } - - error: crate::Error + /// The backup version. + pub version: String, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/backup/get_backup_keys.rs b/crates/ruma-client-api/src/backup/get_backup_keys.rs index 3aa23fc8..55918e8a 100644 --- a/crates/ruma-client-api/src/backup/get_backup_keys.rs +++ b/crates/ruma-client-api/src/backup/get_backup_keys.rs @@ -9,35 +9,37 @@ pub mod v3 { use std::collections::BTreeMap; - use ruma_common::{api::ruma_api, OwnedRoomId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, OwnedRoomId, + }; use crate::backup::RoomKeyBackup; - ruma_api! { - metadata: { - description: "Retrieve all keys from a backup version.", - method: GET, - name: "get_backup_keys", - unstable_path: "/_matrix/client/unstable/room_keys/keys", - r0_path: "/_matrix/client/r0/room_keys/keys", - stable_path: "/_matrix/client/v3/room_keys/keys", - rate_limited: true, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Retrieve all keys from a backup version.", + method: GET, + name: "get_backup_keys", + rate_limited: true, + authentication: AccessToken, + history: { + unstable => "/_matrix/client/unstable/room_keys/keys", + 1.0 => "/_matrix/client/r0/room_keys/keys", + 1.1 => "/_matrix/client/v3/room_keys/keys", } + }; - request: { - /// The backup version to retrieve keys from. - #[ruma_api(query)] - pub version: &'a str, - } + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The backup version to retrieve keys from. + #[ruma_api(query)] + pub version: &'a str, + } - response: { - /// A map from room IDs to session IDs to key data. - pub rooms: BTreeMap, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// A map from room IDs to session IDs to key data. + pub rooms: BTreeMap, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/backup/get_backup_keys_for_room.rs b/crates/ruma-client-api/src/backup/get_backup_keys_for_room.rs index cdd0aeb9..eda20f9b 100644 --- a/crates/ruma-client-api/src/backup/get_backup_keys_for_room.rs +++ b/crates/ruma-client-api/src/backup/get_backup_keys_for_room.rs @@ -7,39 +7,43 @@ pub mod v3 { use std::collections::BTreeMap; - use ruma_common::{api::ruma_api, serde::Raw, RoomId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + serde::Raw, + RoomId, + }; use crate::backup::KeyBackupData; - ruma_api! { - metadata: { - description: "Retrieve sessions from the backup for a given room.", - method: GET, - name: "get_backup_keys_for_room", - unstable_path: "/_matrix/client/unstable/room_keys/keys/:room_id", - r0_path: "/_matrix/client/r0/room_keys/keys/:room_id", - stable_path: "/_matrix/client/v3/room_keys/keys/:room_id", - rate_limited: true, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Retrieve sessions from the backup for a given room.", + method: GET, + name: "get_backup_keys_for_room", + rate_limited: true, + authentication: AccessToken, + history: { + unstable => "/_matrix/client/unstable/room_keys/keys/:room_id", + 1.0 => "/_matrix/client/r0/room_keys/keys/:room_id", + 1.1 => "/_matrix/client/v3/room_keys/keys/:room_id", } + }; - request: { - /// The backup version to retrieve keys from. - #[ruma_api(query)] - pub version: &'a str, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The backup version to retrieve keys from. + #[ruma_api(query)] + pub version: &'a str, - /// The ID of the room that the requested key is for. - #[ruma_api(path)] - pub room_id: &'a RoomId, - } + /// The ID of the room that the requested key is for. + #[ruma_api(path)] + pub room_id: &'a RoomId, + } - response: { - /// A map of session IDs to key data. - pub sessions: BTreeMap>, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// A map of session IDs to key data. + pub sessions: BTreeMap>, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/backup/get_backup_keys_for_session.rs b/crates/ruma-client-api/src/backup/get_backup_keys_for_session.rs index 259bb3ef..65dd4620 100644 --- a/crates/ruma-client-api/src/backup/get_backup_keys_for_session.rs +++ b/crates/ruma-client-api/src/backup/get_backup_keys_for_session.rs @@ -5,44 +5,48 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3room_keyskeysroomidsessionid - use ruma_common::{api::ruma_api, serde::Raw, RoomId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + serde::Raw, + RoomId, + }; use crate::backup::KeyBackupData; - ruma_api! { - metadata: { - description: "Retrieve a key from the backup for a given session.", - method: GET, - name: "get_backup_keys_for_session", - unstable_path: "/_matrix/client/unstable/room_keys/keys/:room_id/:session_id", - r0_path: "/_matrix/client/r0/room_keys/keys/:room_id/:session_id", - stable_path: "/_matrix/client/v3/room_keys/keys/:room_id/:session_id", - rate_limited: true, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Retrieve a key from the backup for a given session.", + method: GET, + name: "get_backup_keys_for_session", + rate_limited: true, + authentication: AccessToken, + history: { + unstable => "/_matrix/client/unstable/room_keys/keys/:room_id/:session_id", + 1.0 => "/_matrix/client/r0/room_keys/keys/:room_id/:session_id", + 1.1 => "/_matrix/client/v3/room_keys/keys/:room_id/:session_id", } + }; - request: { - /// The backup version to retrieve keys from. - #[ruma_api(query)] - pub version: &'a str, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The backup version to retrieve keys from. + #[ruma_api(query)] + pub version: &'a str, - /// The ID of the room that the requested key is for. - #[ruma_api(path)] - pub room_id: &'a RoomId, + /// The ID of the room that the requested key is for. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The ID of the megolm session whose key is requested. - #[ruma_api(path)] - pub session_id: &'a str, - } + /// The ID of the megolm session whose key is requested. + #[ruma_api(path)] + pub session_id: &'a str, + } - response: { - /// Information about the requested backup key. - #[ruma_api(body)] - pub key_data: Raw, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// Information about the requested backup key. + #[ruma_api(body)] + pub key_data: Raw, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/backup/get_latest_backup_info.rs b/crates/ruma-client-api/src/backup/get_latest_backup_info.rs index 8df7a471..b7a5c62f 100644 --- a/crates/ruma-client-api/src/backup/get_latest_backup_info.rs +++ b/crates/ruma-client-api/src/backup/get_latest_backup_info.rs @@ -6,7 +6,11 @@ pub mod v3 { //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3room_keysversion use js_int::UInt; - use ruma_common::{api::ruma_api, serde::Raw}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + serde::Raw, + }; use serde::{ser, Deserialize, Deserializer, Serialize}; use serde_json::value::to_raw_value as to_raw_json_value; @@ -15,41 +19,40 @@ pub mod v3 { BackupAlgorithm, }; - ruma_api! { - metadata: { - description: "Get information about the latest backup.", - method: GET, - name: "get_latest_backup_info", - unstable_path: "/_matrix/client/unstable/room_keys/version", - r0_path: "/_matrix/client/r0/room_keys/version", - stable_path: "/_matrix/client/v3/room_keys/version", - rate_limited: true, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Get information about the latest backup.", + method: GET, + name: "get_latest_backup_info", + rate_limited: true, + authentication: AccessToken, + history: { + unstable => "/_matrix/client/unstable/room_keys/version", + 1.0 => "/_matrix/client/r0/room_keys/version", + 1.1 => "/_matrix/client/v3/room_keys/version", } + }; - #[derive(Default)] - request: {} + #[request(error = crate::Error)] + #[derive(Default)] + pub struct Request {} - #[ruma_api(manual_body_serde)] - response: { - /// The algorithm used for storing backups. - pub algorithm: Raw, + #[response(error = crate::Error)] + #[ruma_api(manual_body_serde)] + pub struct Response { + /// The algorithm used for storing backups. + pub algorithm: Raw, - /// The number of keys stored in the backup. - pub count: UInt, + /// The number of keys stored in the backup. + pub count: UInt, - /// An opaque string representing stored keys in the backup. - /// - /// Clients can compare it with the etag value they received in the request of their last - /// key storage request. - pub etag: String, + /// An opaque string representing stored keys in the backup. + /// + /// Clients can compare it with the etag value they received in the request of their last + /// key storage request. + pub etag: String, - /// The backup version. - pub version: String, - } - - error: crate::Error + /// The backup version. + pub version: String, } impl Request { diff --git a/crates/ruma-client-api/src/backup/update_backup_version.rs b/crates/ruma-client-api/src/backup/update_backup_version.rs index 3d8fea3b..152e8afc 100644 --- a/crates/ruma-client-api/src/backup/update_backup_version.rs +++ b/crates/ruma-client-api/src/backup/update_backup_version.rs @@ -5,38 +5,41 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#put_matrixclientv3room_keysversionversion - use ruma_common::{api::ruma_api, serde::Raw}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + serde::Raw, + }; use crate::backup::BackupAlgorithm; - ruma_api! { - metadata: { - description: "Update information about an existing backup.", - method: PUT, - name: "update_backup_version", - unstable_path: "/_matrix/client/unstable/room_keys/version/:version", - stable_path: "/_matrix/client/v3/room_keys/version/:version", - rate_limited: true, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Update information about an existing backup.", + method: PUT, + name: "update_backup_version", + rate_limited: true, + authentication: AccessToken, + history: { + unstable => "/_matrix/client/unstable/room_keys/version/:version", + 1.1 => "/_matrix/client/v3/room_keys/version/:version", } + }; - request: { - /// The backup version. - #[ruma_api(path)] - pub version: &'a str, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The backup version. + #[ruma_api(path)] + pub version: &'a str, - /// The algorithm used for storing backups. - #[ruma_api(body)] - pub algorithm: Raw, - } - - #[derive(Default)] - response: {} - - error: crate::Error + /// The algorithm used for storing backups. + #[ruma_api(body)] + pub algorithm: Raw, } + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given backup version and algorithm. pub fn new(version: &'a str, algorithm: Raw) -> Self { diff --git a/crates/ruma-client-api/src/config/get_global_account_data.rs b/crates/ruma-client-api/src/config/get_global_account_data.rs index cdcdd7b1..7756c465 100644 --- a/crates/ruma-client-api/src/config/get_global_account_data.rs +++ b/crates/ruma-client-api/src/config/get_global_account_data.rs @@ -6,40 +6,43 @@ pub mod v3 { //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3useruseridaccount_datatype use ruma_common::{ - api::ruma_api, events::AnyGlobalAccountDataEventContent, serde::Raw, UserId, + api::{request, response, Metadata}, + events::AnyGlobalAccountDataEventContent, + metadata, + serde::Raw, + UserId, }; - ruma_api! { - metadata: { - description: "Gets global account data for a user.", - name: "get_global_account_data", - method: GET, - r0_path: "/_matrix/client/r0/user/:user_id/account_data/:event_type", - stable_path: "/_matrix/client/v3/user/:user_id/account_data/:event_type", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Gets global account data for a user.", + method: GET, + name: "get_global_account_data", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/user/:user_id/account_data/:event_type", + 1.1 => "/_matrix/client/v3/user/:user_id/account_data/:event_type", } + }; - request: { - /// User ID of user for whom to retrieve data. - #[ruma_api(path)] - pub user_id: &'a UserId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// User ID of user for whom to retrieve data. + #[ruma_api(path)] + pub user_id: &'a UserId, - /// Type of data to retrieve. - #[ruma_api(path)] - pub event_type: &'a str, - } + /// Type of data to retrieve. + #[ruma_api(path)] + pub event_type: &'a str, + } - response: { - /// Account data content for the given type. - /// - /// Use [`Raw::deserialize_content`] for deserialization. - #[ruma_api(body)] - pub account_data: Raw, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// Account data content for the given type. + /// + /// Use [`Raw::deserialize_content`] for deserialization. + #[ruma_api(body)] + pub account_data: Raw, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/config/get_room_account_data.rs b/crates/ruma-client-api/src/config/get_room_account_data.rs index d3e3b0f1..f53133d1 100644 --- a/crates/ruma-client-api/src/config/get_room_account_data.rs +++ b/crates/ruma-client-api/src/config/get_room_account_data.rs @@ -6,44 +6,47 @@ pub mod v3 { //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3useruseridroomsroomidaccount_datatype use ruma_common::{ - api::ruma_api, events::AnyRoomAccountDataEventContent, serde::Raw, RoomId, UserId, + api::{request, response, Metadata}, + events::AnyRoomAccountDataEventContent, + metadata, + serde::Raw, + RoomId, UserId, }; - ruma_api! { - metadata: { - description: "Gets account data room for a user for a given room", - name: "get_room_account_data", - method: GET, - r0_path: "/_matrix/client/r0/user/:user_id/rooms/:room_id/account_data/:event_type", - stable_path: "/_matrix/client/v3/user/:user_id/rooms/:room_id/account_data/:event_type", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Gets account data room for a user for a given room", + method: GET, + name: "get_room_account_data", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/user/:user_id/rooms/:room_id/account_data/:event_type", + 1.1 => "/_matrix/client/v3/user/:user_id/rooms/:room_id/account_data/:event_type", } + }; - request: { - /// User ID of user for whom to retrieve data. - #[ruma_api(path)] - pub user_id: &'a UserId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// User ID of user for whom to retrieve data. + #[ruma_api(path)] + pub user_id: &'a UserId, - /// Room ID for which to retrieve data. - #[ruma_api(path)] - pub room_id: &'a RoomId, + /// Room ID for which to retrieve data. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// Type of data to retrieve. - #[ruma_api(path)] - pub event_type: &'a str, - } + /// Type of data to retrieve. + #[ruma_api(path)] + pub event_type: &'a str, + } - response: { - /// Account data content for the given type. - /// - /// Use [`Raw::deserialize_content`] for deserialization. - #[ruma_api(body)] - pub account_data: Raw, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// Account data content for the given type. + /// + /// Use [`Raw::deserialize_content`] for deserialization. + #[ruma_api(body)] + pub account_data: Raw, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/config/set_global_account_data.rs b/crates/ruma-client-api/src/config/set_global_account_data.rs index 585bd0c2..a4d32ee3 100644 --- a/crates/ruma-client-api/src/config/set_global_account_data.rs +++ b/crates/ruma-client-api/src/config/set_global_account_data.rs @@ -6,54 +6,54 @@ pub mod v3 { //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#put_matrixclientv3useruseridaccount_datatype use ruma_common::{ - api::ruma_api, + api::{request, response, Metadata}, events::{ AnyGlobalAccountDataEventContent, GlobalAccountDataEventContent, GlobalAccountDataEventType, }, + metadata, serde::Raw, UserId, }; use serde_json::value::to_raw_value as to_raw_json_value; - ruma_api! { - metadata: { - description: "Sets global account data.", - method: PUT, - name: "set_global_account_data", - r0_path: "/_matrix/client/r0/user/:user_id/account_data/:event_type", - stable_path: "/_matrix/client/v3/user/:user_id/account_data/:event_type", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Sets global account data.", + method: PUT, + name: "set_global_account_data", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/user/:user_id/account_data/:event_type", + 1.1 => "/_matrix/client/v3/user/:user_id/account_data/:event_type", } + }; - request: { - /// The ID of the user to set account_data for. - /// - /// The access token must be authorized to make requests for this user ID. - #[ruma_api(path)] - pub user_id: &'a UserId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The ID of the user to set account_data for. + /// + /// The access token must be authorized to make requests for this user ID. + #[ruma_api(path)] + pub user_id: &'a UserId, - /// The event type of the account_data to set. - /// - /// Custom types should be namespaced to avoid clashes. - #[ruma_api(path)] - pub event_type: GlobalAccountDataEventType, + /// The event type of the account_data to set. + /// + /// Custom types should be namespaced to avoid clashes. + #[ruma_api(path)] + pub event_type: GlobalAccountDataEventType, - /// Arbitrary JSON to store as config data. - /// - /// To create a `RawJsonValue`, use `serde_json::value::to_raw_value`. - #[ruma_api(body)] - pub data: Raw, - } - - #[derive(Default)] - response: {} - - error: crate::Error + /// Arbitrary JSON to store as config data. + /// + /// To create a `RawJsonValue`, use `serde_json::value::to_raw_value`. + #[ruma_api(body)] + pub data: Raw, } + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given data, event type and user ID. /// diff --git a/crates/ruma-client-api/src/config/set_room_account_data.rs b/crates/ruma-client-api/src/config/set_room_account_data.rs index 7b6d236a..75a8ea93 100644 --- a/crates/ruma-client-api/src/config/set_room_account_data.rs +++ b/crates/ruma-client-api/src/config/set_room_account_data.rs @@ -6,57 +6,57 @@ pub mod v3 { //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#put_matrixclientv3useruseridroomsroomidaccount_datatype use ruma_common::{ - api::ruma_api, + api::{request, response, Metadata}, events::{ AnyRoomAccountDataEventContent, RoomAccountDataEventContent, RoomAccountDataEventType, }, + metadata, serde::Raw, RoomId, UserId, }; use serde_json::value::to_raw_value as to_raw_json_value; - ruma_api! { - metadata: { - description: "Associate account data with a room.", - method: PUT, - name: "set_room_account_data", - r0_path: "/_matrix/client/r0/user/:user_id/rooms/:room_id/account_data/:event_type", - stable_path: "/_matrix/client/v3/user/:user_id/rooms/:room_id/account_data/:event_type", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Associate account data with a room.", + method: PUT, + name: "set_room_account_data", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/user/:user_id/rooms/:room_id/account_data/:event_type", + 1.1 => "/_matrix/client/v3/user/:user_id/rooms/:room_id/account_data/:event_type", } + }; - request: { - /// The ID of the user to set account_data for. - /// - /// The access token must be authorized to make requests for this user ID. - #[ruma_api(path)] - pub user_id: &'a UserId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The ID of the user to set account_data for. + /// + /// The access token must be authorized to make requests for this user ID. + #[ruma_api(path)] + pub user_id: &'a UserId, - /// The ID of the room to set account_data on. - #[ruma_api(path)] - pub room_id: &'a RoomId, + /// The ID of the room to set account_data on. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The event type of the account_data to set. - /// - /// Custom types should be namespaced to avoid clashes. - #[ruma_api(path)] - pub event_type: RoomAccountDataEventType, + /// The event type of the account_data to set. + /// + /// Custom types should be namespaced to avoid clashes. + #[ruma_api(path)] + pub event_type: RoomAccountDataEventType, - /// Arbitrary JSON to store as config data. - /// - /// To create a `RawJsonValue`, use `serde_json::value::to_raw_value`. - #[ruma_api(body)] - pub data: Raw, - } - - #[derive(Default)] - response: {} - - error: crate::Error + /// Arbitrary JSON to store as config data. + /// + /// To create a `RawJsonValue`, use `serde_json::value::to_raw_value`. + #[ruma_api(body)] + pub data: Raw, } + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given data, event type, room ID and user ID. /// diff --git a/crates/ruma-client-api/src/context/get_context.rs b/crates/ruma-client-api/src/context/get_context.rs index 7424fe0e..5e3c440e 100644 --- a/crates/ruma-client-api/src/context/get_context.rs +++ b/crates/ruma-client-api/src/context/get_context.rs @@ -7,82 +7,82 @@ pub mod v3 { use js_int::{uint, UInt}; use ruma_common::{ - api::ruma_api, + api::{request, response, Metadata}, events::{AnyStateEvent, AnyTimelineEvent}, + metadata, serde::Raw, EventId, RoomId, }; use crate::filter::{IncomingRoomEventFilter, RoomEventFilter}; - ruma_api! { - metadata: { - description: "Get the events immediately preceding and following a given event.", - method: GET, - r0_path: "/_matrix/client/r0/rooms/:room_id/context/:event_id", - stable_path: "/_matrix/client/v3/rooms/:room_id/context/:event_id", - name: "get_context", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Get the events immediately preceding and following a given event.", + method: GET, + name: "get_context", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/rooms/:room_id/context/:event_id", + 1.1 => "/_matrix/client/v3/rooms/:room_id/context/:event_id", } + }; - request: { - /// The room to get events from. - #[ruma_api(path)] - pub room_id: &'a RoomId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The room to get events from. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The event to get context around. - #[ruma_api(path)] - pub event_id: &'a EventId, + /// The event to get context around. + #[ruma_api(path)] + pub event_id: &'a EventId, - /// The maximum number of events to return. - /// - /// Defaults to 10. - #[ruma_api(query)] - #[serde(default = "default_limit", skip_serializing_if = "is_default_limit")] - pub limit: UInt, + /// The maximum number of events to return. + /// + /// Defaults to 10. + #[ruma_api(query)] + #[serde(default = "default_limit", skip_serializing_if = "is_default_limit")] + pub limit: UInt, - /// A RoomEventFilter to filter returned events with. - #[ruma_api(query)] - #[serde( - with = "ruma_common::serde::json_string", - default, - skip_serializing_if = "RoomEventFilter::is_empty" - )] - pub filter: RoomEventFilter<'a>, - } + /// A RoomEventFilter to filter returned events with. + #[ruma_api(query)] + #[serde( + with = "ruma_common::serde::json_string", + default, + skip_serializing_if = "RoomEventFilter::is_empty" + )] + pub filter: RoomEventFilter<'a>, + } - #[derive(Default)] - response: { - /// A token that can be used to paginate backwards with. - #[serde(skip_serializing_if = "Option::is_none")] - pub start: Option, + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response { + /// A token that can be used to paginate backwards with. + #[serde(skip_serializing_if = "Option::is_none")] + pub start: Option, - /// A token that can be used to paginate forwards with. - #[serde(skip_serializing_if = "Option::is_none")] - pub end: Option, + /// A token that can be used to paginate forwards with. + #[serde(skip_serializing_if = "Option::is_none")] + pub end: Option, - /// A list of room events that happened just before the requested event, - /// in reverse-chronological order. - #[serde(default, skip_serializing_if = "Vec::is_empty")] - pub events_before: Vec>, + /// A list of room events that happened just before the requested event, + /// in reverse-chronological order. + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub events_before: Vec>, - /// Details of the requested event. - #[serde(skip_serializing_if = "Option::is_none")] - pub event: Option>, + /// Details of the requested event. + #[serde(skip_serializing_if = "Option::is_none")] + pub event: Option>, - /// A list of room events that happened just after the requested event, - /// in chronological order. - #[serde(default, skip_serializing_if = "Vec::is_empty")] - pub events_after: Vec>, + /// A list of room events that happened just after the requested event, + /// in chronological order. + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub events_after: Vec>, - /// The state of the room at the last event returned. - #[serde(default, skip_serializing_if = "Vec::is_empty")] - pub state: Vec>, - } - - error: crate::Error + /// The state of the room at the last event returned. + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub state: Vec>, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/device/delete_device.rs b/crates/ruma-client-api/src/device/delete_device.rs index 6091328f..99d3666f 100644 --- a/crates/ruma-client-api/src/device/delete_device.rs +++ b/crates/ruma-client-api/src/device/delete_device.rs @@ -5,38 +5,40 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#delete_matrixclientv3devicesdeviceid - use ruma_common::{api::ruma_api, DeviceId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, DeviceId, + }; use crate::uiaa::{AuthData, IncomingAuthData, UiaaResponse}; - ruma_api! { - metadata: { - description: "Delete a device for authenticated user.", - method: DELETE, - name: "delete_device", - r0_path: "/_matrix/client/r0/devices/:device_id", - stable_path: "/_matrix/client/v3/devices/:device_id", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Delete a device for authenticated user.", + method: DELETE, + name: "delete_device", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/devices/:device_id", + 1.1 => "/_matrix/client/v3/devices/:device_id", } + }; - request: { - /// The device to delete. - #[ruma_api(path)] - pub device_id: &'a DeviceId, + #[request(error = UiaaResponse)] + pub struct Request<'a> { + /// The device to delete. + #[ruma_api(path)] + pub device_id: &'a DeviceId, - /// Additional authentication information for the user-interactive authentication API. - #[serde(skip_serializing_if = "Option::is_none")] - pub auth: Option>, - } - - #[derive(Default)] - response: {} - - error: UiaaResponse + /// Additional authentication information for the user-interactive authentication API. + #[serde(skip_serializing_if = "Option::is_none")] + pub auth: Option>, } + #[response(error = UiaaResponse)] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given device ID. pub fn new(device_id: &'a DeviceId) -> Self { diff --git a/crates/ruma-client-api/src/device/delete_devices.rs b/crates/ruma-client-api/src/device/delete_devices.rs index 95069dd7..312e8aeb 100644 --- a/crates/ruma-client-api/src/device/delete_devices.rs +++ b/crates/ruma-client-api/src/device/delete_devices.rs @@ -5,37 +5,39 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#post_matrixclientv3delete_devices - use ruma_common::{api::ruma_api, OwnedDeviceId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, OwnedDeviceId, + }; use crate::uiaa::{AuthData, IncomingAuthData, UiaaResponse}; - ruma_api! { - metadata: { - description: "Delete specified devices.", - method: POST, - r0_path: "/_matrix/client/r0/delete_devices", - stable_path: "/_matrix/client/v3/delete_devices", - name: "delete_devices", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Delete specified devices.", + method: POST, + name: "delete_devices", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/delete_devices", + 1.1 => "/_matrix/client/v3/delete_devices", } + }; - request: { - /// List of devices to delete. - pub devices: &'a [OwnedDeviceId], + #[request(error = UiaaResponse)] + pub struct Request<'a> { + /// List of devices to delete. + pub devices: &'a [OwnedDeviceId], - /// Additional authentication information for the user-interactive authentication API. - #[serde(skip_serializing_if = "Option::is_none")] - pub auth: Option>, - } - - #[derive(Default)] - response: {} - - error: UiaaResponse + /// Additional authentication information for the user-interactive authentication API. + #[serde(skip_serializing_if = "Option::is_none")] + pub auth: Option>, } + #[response(error = UiaaResponse)] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given device list. pub fn new(devices: &'a [OwnedDeviceId]) -> Self { diff --git a/crates/ruma-client-api/src/device/get_device.rs b/crates/ruma-client-api/src/device/get_device.rs index 17b92142..781743ea 100644 --- a/crates/ruma-client-api/src/device/get_device.rs +++ b/crates/ruma-client-api/src/device/get_device.rs @@ -5,35 +5,37 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3devicesdeviceid - use ruma_common::{api::ruma_api, DeviceId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, DeviceId, + }; use crate::device::Device; - ruma_api! { - metadata: { - description: "Get a device for authenticated user.", - method: GET, - name: "get_device", - r0_path: "/_matrix/client/r0/devices/:device_id", - stable_path: "/_matrix/client/v3/devices/:device_id", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Get a device for authenticated user.", + method: GET, + name: "get_device", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/devices/:device_id", + 1.1 => "/_matrix/client/v3/devices/:device_id", } + }; - request: { - /// The device to retrieve. - #[ruma_api(path)] - pub device_id: &'a DeviceId, - } + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The device to retrieve. + #[ruma_api(path)] + pub device_id: &'a DeviceId, + } - response: { - /// Information about the device. - #[ruma_api(body)] - pub device: Device, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// Information about the device. + #[ruma_api(body)] + pub device: Device, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/device/get_devices.rs b/crates/ruma-client-api/src/device/get_devices.rs index db8be368..2bc11f97 100644 --- a/crates/ruma-client-api/src/device/get_devices.rs +++ b/crates/ruma-client-api/src/device/get_devices.rs @@ -5,31 +5,33 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3devices - use ruma_common::api::ruma_api; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + }; use crate::device::Device; - ruma_api! { - metadata: { - description: "Get registered devices for authenticated user.", - method: GET, - name: "get_devices", - r0_path: "/_matrix/client/r0/devices", - stable_path: "/_matrix/client/v3/devices", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Get registered devices for authenticated user.", + method: GET, + name: "get_devices", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/devices", + 1.1 => "/_matrix/client/v3/devices", } + }; - #[derive(Default)] - request: {} + #[request(error = crate::Error)] + #[derive(Default)] + pub struct Request {} - response: { - /// A list of all registered devices for this user - pub devices: Vec, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// A list of all registered devices for this user + pub devices: Vec, } impl Request { diff --git a/crates/ruma-client-api/src/device/update_device.rs b/crates/ruma-client-api/src/device/update_device.rs index b146fcec..40c40ddc 100644 --- a/crates/ruma-client-api/src/device/update_device.rs +++ b/crates/ruma-client-api/src/device/update_device.rs @@ -5,38 +5,40 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#put_matrixclientv3devicesdeviceid - use ruma_common::{api::ruma_api, DeviceId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, DeviceId, + }; - ruma_api! { - metadata: { - description: "Update metadata for a device.", - method: PUT, - name: "update_device", - r0_path: "/_matrix/client/r0/devices/:device_id", - stable_path: "/_matrix/client/v3/devices/:device_id", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Update metadata for a device.", + method: PUT, + name: "update_device", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/devices/:device_id", + 1.1 => "/_matrix/client/v3/devices/:device_id", } + }; - request: { - /// The device to update. - #[ruma_api(path)] - pub device_id: &'a DeviceId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The device to update. + #[ruma_api(path)] + pub device_id: &'a DeviceId, - /// The new display name for this device. - /// - /// If this is `None`, the display name won't be changed. - #[serde(skip_serializing_if = "Option::is_none")] - pub display_name: Option<&'a str>, - } - - #[derive(Default)] - response: {} - - error: crate::Error + /// The new display name for this device. + /// + /// If this is `None`, the display name won't be changed. + #[serde(skip_serializing_if = "Option::is_none")] + pub display_name: Option<&'a str>, } + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given device ID. pub fn new(device_id: &'a DeviceId) -> Self { diff --git a/crates/ruma-client-api/src/directory/get_public_rooms.rs b/crates/ruma-client-api/src/directory/get_public_rooms.rs index 3750fec6..cbc45924 100644 --- a/crates/ruma-client-api/src/directory/get_public_rooms.rs +++ b/crates/ruma-client-api/src/directory/get_public_rooms.rs @@ -6,58 +6,61 @@ pub mod v3 { //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3publicrooms use js_int::UInt; - use ruma_common::{api::ruma_api, directory::PublicRoomsChunk, ServerName}; + use ruma_common::{ + api::{request, response, Metadata}, + directory::PublicRoomsChunk, + metadata, ServerName, + }; - ruma_api! { - metadata: { - description: "Get the list of rooms in this homeserver's public directory.", - method: GET, - name: "get_public_rooms", - r0_path: "/_matrix/client/r0/publicRooms", - stable_path: "/_matrix/client/v3/publicRooms", - rate_limited: false, - authentication: None, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Get the list of rooms in this homeserver's public directory.", + method: GET, + name: "get_public_rooms", + rate_limited: false, + authentication: None, + history: { + 1.0 => "/_matrix/client/r0/publicRooms", + 1.1 => "/_matrix/client/v3/publicRooms", } + }; - #[derive(Default)] - request: { - /// Limit for the number of results to return. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub limit: Option, + #[request(error = crate::Error)] + #[derive(Default)] + pub struct Request<'a> { + /// Limit for the number of results to return. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub limit: Option, - /// Pagination token from a previous request. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub since: Option<&'a str>, + /// Pagination token from a previous request. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub since: Option<&'a str>, - /// The server to fetch the public room lists from. - /// - /// `None` means the server this request is sent to. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub server: Option<&'a ServerName>, - } + /// The server to fetch the public room lists from. + /// + /// `None` means the server this request is sent to. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub server: Option<&'a ServerName>, + } - response: { - /// A paginated chunk of public rooms. - pub chunk: Vec, + #[response(error = crate::Error)] + pub struct Response { + /// A paginated chunk of public rooms. + pub chunk: Vec, - /// A pagination token for the response. - #[serde(skip_serializing_if = "Option::is_none")] - pub next_batch: Option, + /// A pagination token for the response. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_batch: Option, - /// A pagination token that allows fetching previous results. - #[serde(skip_serializing_if = "Option::is_none")] - pub prev_batch: Option, + /// A pagination token that allows fetching previous results. + #[serde(skip_serializing_if = "Option::is_none")] + pub prev_batch: Option, - /// An estimate on the total number of public rooms, if the server has an estimate. - #[serde(skip_serializing_if = "Option::is_none")] - pub total_room_count_estimate: Option, - } - - error: crate::Error + /// An estimate on the total number of public rooms, if the server has an estimate. + #[serde(skip_serializing_if = "Option::is_none")] + pub total_room_count_estimate: Option, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/directory/get_public_rooms_filtered.rs b/crates/ruma-client-api/src/directory/get_public_rooms_filtered.rs index 970c305d..87506836 100644 --- a/crates/ruma-client-api/src/directory/get_public_rooms_filtered.rs +++ b/crates/ruma-client-api/src/directory/get_public_rooms_filtered.rs @@ -7,68 +7,67 @@ pub mod v3 { use js_int::UInt; use ruma_common::{ - api::ruma_api, + api::{request, response, Metadata}, directory::{Filter, IncomingFilter, IncomingRoomNetwork, PublicRoomsChunk, RoomNetwork}, - ServerName, + metadata, ServerName, }; - ruma_api! { - metadata: { - description: "Get the list of rooms in this homeserver's public directory.", - method: POST, - name: "get_public_rooms_filtered", - r0_path: "/_matrix/client/r0/publicRooms", - stable_path: "/_matrix/client/v3/publicRooms", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Get the list of rooms in this homeserver's public directory.", + method: POST, + name: "get_public_rooms_filtered", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/publicRooms", + 1.1 => "/_matrix/client/v3/publicRooms", } + }; - #[derive(Default)] - request: { - /// The server to fetch the public room lists from. - /// - /// `None` means the server this request is sent to. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub server: Option<&'a ServerName>, + #[request(error = crate::Error)] + #[derive(Default)] + pub struct Request<'a> { + /// The server to fetch the public room lists from. + /// + /// `None` means the server this request is sent to. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub server: Option<&'a ServerName>, - /// Limit for the number of results to return. - #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + /// Limit for the number of results to return. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, - /// Pagination token from a previous request. - #[serde(skip_serializing_if = "Option::is_none")] - pub since: Option<&'a str>, + /// Pagination token from a previous request. + #[serde(skip_serializing_if = "Option::is_none")] + pub since: Option<&'a str>, - /// Filter to apply to the results. - #[serde(default, skip_serializing_if = "Filter::is_empty")] - pub filter: Filter<'a>, + /// Filter to apply to the results. + #[serde(default, skip_serializing_if = "Filter::is_empty")] + pub filter: Filter<'a>, - /// Network to fetch the public room lists from. - #[serde(flatten, skip_serializing_if = "ruma_common::serde::is_default")] - pub room_network: RoomNetwork<'a>, - } + /// Network to fetch the public room lists from. + #[serde(flatten, skip_serializing_if = "ruma_common::serde::is_default")] + pub room_network: RoomNetwork<'a>, + } - #[derive(Default)] - response: { - /// A paginated chunk of public rooms. - pub chunk: Vec, + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response { + /// A paginated chunk of public rooms. + pub chunk: Vec, - /// A pagination token for the response. - #[serde(skip_serializing_if = "Option::is_none")] - pub next_batch: Option, + /// A pagination token for the response. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_batch: Option, - /// A pagination token that allows fetching previous results. - #[serde(skip_serializing_if = "Option::is_none")] - pub prev_batch: Option, + /// A pagination token that allows fetching previous results. + #[serde(skip_serializing_if = "Option::is_none")] + pub prev_batch: Option, - /// An estimate on the total number of public rooms, if the server has an estimate. - #[serde(skip_serializing_if = "Option::is_none")] - pub total_room_count_estimate: Option, - } - - error: crate::Error + /// An estimate on the total number of public rooms, if the server has an estimate. + #[serde(skip_serializing_if = "Option::is_none")] + pub total_room_count_estimate: Option, } impl Request<'_> { diff --git a/crates/ruma-client-api/src/directory/get_room_visibility.rs b/crates/ruma-client-api/src/directory/get_room_visibility.rs index a555a18e..95eeed59 100644 --- a/crates/ruma-client-api/src/directory/get_room_visibility.rs +++ b/crates/ruma-client-api/src/directory/get_room_visibility.rs @@ -5,34 +5,36 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3directorylistroomroomid - use ruma_common::{api::ruma_api, RoomId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, RoomId, + }; use crate::room::Visibility; - ruma_api! { - metadata: { - description: "Get the visibility of a public room on a directory.", - name: "get_room_visibility", - method: GET, - r0_path: "/_matrix/client/r0/directory/list/room/:room_id", - stable_path: "/_matrix/client/v3/directory/list/room/:room_id", - rate_limited: false, - authentication: None, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Get the visibility of a public room on a directory.", + method: GET, + name: "get_room_visibility", + rate_limited: false, + authentication: None, + history: { + 1.0 => "/_matrix/client/r0/directory/list/room/:room_id", + 1.1 => "/_matrix/client/v3/directory/list/room/:room_id", } + }; - request: { - /// The ID of the room of which to request the visibility. - #[ruma_api(path)] - pub room_id: &'a RoomId, - } + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The ID of the room of which to request the visibility. + #[ruma_api(path)] + pub room_id: &'a RoomId, + } - response: { - /// Visibility of the room. - pub visibility: Visibility, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// Visibility of the room. + pub visibility: Visibility, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/directory/set_room_visibility.rs b/crates/ruma-client-api/src/directory/set_room_visibility.rs index 060af428..6109679f 100644 --- a/crates/ruma-client-api/src/directory/set_room_visibility.rs +++ b/crates/ruma-client-api/src/directory/set_room_visibility.rs @@ -5,37 +5,39 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#put_matrixclientv3directorylistroomroomid - use ruma_common::{api::ruma_api, RoomId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, RoomId, + }; use crate::room::Visibility; - ruma_api! { - metadata: { - description: "Set the visibility of a public room on a directory.", - name: "set_room_visibility", - method: PUT, - r0_path: "/_matrix/client/r0/directory/list/room/:room_id", - stable_path: "/_matrix/client/v3/directory/list/room/:room_id", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Set the visibility of a public room on a directory.", + method: PUT, + name: "set_room_visibility", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/directory/list/room/:room_id", + 1.1 => "/_matrix/client/v3/directory/list/room/:room_id", } + }; - request: { - /// The ID of the room of which to set the visibility. - #[ruma_api(path)] - pub room_id: &'a RoomId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The ID of the room of which to set the visibility. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// New visibility setting for the room. - pub visibility: Visibility, - } - - #[derive(Default)] - response: {} - - error: crate::Error + /// New visibility setting for the room. + pub visibility: Visibility, } + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given room ID and visibility. pub fn new(room_id: &'a RoomId, visibility: Visibility) -> Self { diff --git a/crates/ruma-client-api/src/discovery/discover_homeserver.rs b/crates/ruma-client-api/src/discovery/discover_homeserver.rs index a5309e90..2cec8b67 100644 --- a/crates/ruma-client-api/src/discovery/discover_homeserver.rs +++ b/crates/ruma-client-api/src/discovery/discover_homeserver.rs @@ -2,52 +2,54 @@ //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#getwell-knownmatrixclient -use ruma_common::api::ruma_api; +use ruma_common::{ + api::{request, response, Metadata}, + metadata, +}; use serde::{Deserialize, Serialize}; -ruma_api! { - metadata: { - description: "Get discovery information about the domain.", - method: GET, - name: "client_well_known", - stable_path: "/.well-known/matrix/client", - rate_limited: false, - authentication: None, - added: 1.0, +const METADATA: Metadata = metadata! { + description: "Get discovery information about the domain.", + method: GET, + name: "client_well_known", + rate_limited: false, + authentication: None, + history: { + 1.0 => "/.well-known/matrix/client", } +}; - #[derive(Default)] - request: {} +#[request(error = crate::Error)] +#[derive(Default)] +pub struct Request {} - response: { - /// Information about the homeserver to connect to. - #[serde(rename = "m.homeserver")] - pub homeserver: HomeserverInfo, +#[response(error = crate::Error)] +pub struct Response { + /// Information about the homeserver to connect to. + #[serde(rename = "m.homeserver")] + pub homeserver: HomeserverInfo, - /// Information about the identity server to connect to. - #[serde(rename = "m.identity_server", skip_serializing_if = "Option::is_none")] - pub identity_server: Option, + /// Information about the identity server to connect to. + #[serde(rename = "m.identity_server", skip_serializing_if = "Option::is_none")] + pub identity_server: Option, - /// Information about the tile server to use to display location data. - #[cfg(feature = "unstable-msc3488")] - #[serde( - rename = "org.matrix.msc3488.tile_server", - alias = "m.tile_server", - skip_serializing_if = "Option::is_none", - )] - pub tile_server: Option, + /// Information about the tile server to use to display location data. + #[cfg(feature = "unstable-msc3488")] + #[serde( + rename = "org.matrix.msc3488.tile_server", + alias = "m.tile_server", + skip_serializing_if = "Option::is_none" + )] + pub tile_server: Option, - /// Information about the authentication server to connect to when using OpenID Connect. - #[cfg(feature = "unstable-msc2965")] - #[serde( - rename = "org.matrix.msc2965.authentication", - alias = "m.authentication", - skip_serializing_if = "Option::is_none" - )] - pub authentication: Option, - } - - error: crate::Error + /// Information about the authentication server to connect to when using OpenID Connect. + #[cfg(feature = "unstable-msc2965")] + #[serde( + rename = "org.matrix.msc2965.authentication", + alias = "m.authentication", + skip_serializing_if = "Option::is_none" + )] + pub authentication: Option, } impl Request { diff --git a/crates/ruma-client-api/src/discovery/get_capabilities/v3.rs b/crates/ruma-client-api/src/discovery/get_capabilities/v3.rs index 726c49a2..c081b7f6 100644 --- a/crates/ruma-client-api/src/discovery/get_capabilities/v3.rs +++ b/crates/ruma-client-api/src/discovery/get_capabilities/v3.rs @@ -2,31 +2,33 @@ //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3capabilities -use ruma_common::api::ruma_api; +use ruma_common::{ + api::{request, response, Metadata}, + metadata, +}; use super::Capabilities; -ruma_api! { - metadata: { - description: "Gets information about the server's supported feature set and other relevant capabilities.", - method: GET, - name: "get_capabilities", - r0_path: "/_matrix/client/r0/capabilities", - stable_path: "/_matrix/client/v3/capabilities", - rate_limited: true, - authentication: AccessToken, - added: 1.0, +const METADATA: Metadata = metadata! { + description: "Gets information about the server's supported feature set and other relevant capabilities.", + method: GET, + name: "get_capabilities", + rate_limited: true, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/capabilities", + 1.1 => "/_matrix/client/v3/capabilities", } +}; - #[derive(Default)] - request: {} +#[request(error = crate::Error)] +#[derive(Default)] +pub struct Request {} - response: { - /// The capabilities the server supports - pub capabilities: Capabilities, - } - - error: crate::Error +#[response(error = crate::Error)] +pub struct Response { + /// The capabilities the server supports + pub capabilities: Capabilities, } impl Request { diff --git a/crates/ruma-client-api/src/discovery/get_supported_versions.rs b/crates/ruma-client-api/src/discovery/get_supported_versions.rs index 80a1065f..de44a281 100644 --- a/crates/ruma-client-api/src/discovery/get_supported_versions.rs +++ b/crates/ruma-client-api/src/discovery/get_supported_versions.rs @@ -4,32 +4,34 @@ use std::collections::BTreeMap; -use ruma_common::api::{ruma_api, MatrixVersion}; +use ruma_common::{ + api::{request, response, MatrixVersion, Metadata}, + metadata, +}; -ruma_api! { - metadata: { - description: "Get the versions of the client-server API supported by this homeserver.", - method: GET, - name: "api_versions", - stable_path: "/_matrix/client/versions", - rate_limited: false, - authentication: None, - added: 1.0, +const METADATA: Metadata = metadata! { + description: "Get the versions of the client-server API supported by this homeserver.", + method: GET, + name: "api_versions", + rate_limited: false, + authentication: None, + history: { + 1.0 => "/_matrix/client/versions", } +}; - #[derive(Default)] - request: {} +#[request(error = crate::Error)] +#[derive(Default)] +pub struct Request {} - response: { - /// A list of Matrix client API protocol versions supported by the homeserver. - pub versions: Vec, +#[response(error = crate::Error)] +pub struct Response { + /// A list of Matrix client API protocol versions supported by the homeserver. + pub versions: Vec, - /// Experimental features supported by the server. - #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] - pub unstable_features: BTreeMap, - } - - error: crate::Error + /// Experimental features supported by the server. + #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] + pub unstable_features: BTreeMap, } impl Request { diff --git a/crates/ruma-client-api/src/filter/create_filter.rs b/crates/ruma-client-api/src/filter/create_filter.rs index 825915dc..8cf30e4d 100644 --- a/crates/ruma-client-api/src/filter/create_filter.rs +++ b/crates/ruma-client-api/src/filter/create_filter.rs @@ -5,40 +5,42 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#post_matrixclientv3useruseridfilter - use ruma_common::{api::ruma_api, UserId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, UserId, + }; use crate::filter::{FilterDefinition, IncomingFilterDefinition}; - ruma_api! { - metadata: { - description: "Create a new filter for event retrieval.", - method: POST, - name: "create_filter", - r0_path: "/_matrix/client/r0/user/:user_id/filter", - stable_path: "/_matrix/client/v3/user/:user_id/filter", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Create a new filter for event retrieval.", + method: POST, + name: "create_filter", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/user/:user_id/filter", + 1.1 => "/_matrix/client/v3/user/:user_id/filter", } + }; - request: { - /// The ID of the user uploading the filter. - /// - /// The access token must be authorized to make requests for this user ID. - #[ruma_api(path)] - pub user_id: &'a UserId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The ID of the user uploading the filter. + /// + /// The access token must be authorized to make requests for this user ID. + #[ruma_api(path)] + pub user_id: &'a UserId, - /// The filter definition. - #[ruma_api(body)] - pub filter: FilterDefinition<'a>, - } + /// The filter definition. + #[ruma_api(body)] + pub filter: FilterDefinition<'a>, + } - response: { - /// The ID of the filter that was created. - pub filter_id: String, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// The ID of the filter that was created. + pub filter_id: String, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/filter/get_filter.rs b/crates/ruma-client-api/src/filter/get_filter.rs index e0131419..5f484d49 100644 --- a/crates/ruma-client-api/src/filter/get_filter.rs +++ b/crates/ruma-client-api/src/filter/get_filter.rs @@ -5,39 +5,41 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3useruseridfilterfilterid - use ruma_common::{api::ruma_api, UserId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, UserId, + }; use crate::filter::IncomingFilterDefinition; - ruma_api! { - metadata: { - description: "Retrieve a previously created filter.", - method: GET, - name: "get_filter", - r0_path: "/_matrix/client/r0/user/:user_id/filter/:filter_id", - stable_path: "/_matrix/client/v3/user/:user_id/filter/:filter_id", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Retrieve a previously created filter.", + method: GET, + name: "get_filter", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/user/:user_id/filter/:filter_id", + 1.1 => "/_matrix/client/v3/user/:user_id/filter/:filter_id", } + }; - request: { - /// The user ID to download a filter for. - #[ruma_api(path)] - pub user_id: &'a UserId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The user ID to download a filter for. + #[ruma_api(path)] + pub user_id: &'a UserId, - /// The ID of the filter to download. - #[ruma_api(path)] - pub filter_id: &'a str, - } + /// The ID of the filter to download. + #[ruma_api(path)] + pub filter_id: &'a str, + } - response: { - /// The filter definition. - #[ruma_api(body)] - pub filter: IncomingFilterDefinition, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// The filter definition. + #[ruma_api(body)] + pub filter: IncomingFilterDefinition, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/keys/claim_keys.rs b/crates/ruma-client-api/src/keys/claim_keys.rs index 4726318f..e895f102 100644 --- a/crates/ruma-client-api/src/keys/claim_keys.rs +++ b/crates/ruma-client-api/src/keys/claim_keys.rs @@ -8,47 +8,49 @@ pub mod v3 { use std::{collections::BTreeMap, time::Duration}; use ruma_common::{ - api::ruma_api, encryption::OneTimeKey, serde::Raw, DeviceKeyAlgorithm, OwnedDeviceId, - OwnedDeviceKeyId, OwnedUserId, + api::{request, response, Metadata}, + encryption::OneTimeKey, + metadata, + serde::Raw, + DeviceKeyAlgorithm, OwnedDeviceId, OwnedDeviceKeyId, OwnedUserId, }; use serde_json::Value as JsonValue; - ruma_api! { - metadata: { - description: "Claims one-time keys for use in pre-key messages.", - method: POST, - name: "claim_keys", - r0_path: "/_matrix/client/r0/keys/claim", - stable_path: "/_matrix/client/v3/keys/claim", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Claims one-time keys for use in pre-key messages.", + method: POST, + name: "claim_keys", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/keys/claim", + 1.1 => "/_matrix/client/v3/keys/claim", } + }; - request: { - /// The time (in milliseconds) to wait when downloading keys from remote servers. - /// 10 seconds is the recommended default. - #[serde( - with = "ruma_common::serde::duration::opt_ms", - default, - skip_serializing_if = "Option::is_none", - )] - pub timeout: Option, + #[request(error = crate::Error)] + pub struct Request { + /// The time (in milliseconds) to wait when downloading keys from remote servers. + /// 10 seconds is the recommended default. + #[serde( + with = "ruma_common::serde::duration::opt_ms", + default, + skip_serializing_if = "Option::is_none" + )] + pub timeout: Option, - /// The keys to be claimed. - pub one_time_keys: BTreeMap>, - } + /// The keys to be claimed. + pub one_time_keys: BTreeMap>, + } - response: { - /// If any remote homeservers could not be reached, they are recorded here. - /// The names of the properties are the names of the unreachable servers. - pub failures: BTreeMap, + #[response(error = crate::Error)] + pub struct Response { + /// If any remote homeservers could not be reached, they are recorded here. + /// The names of the properties are the names of the unreachable servers. + pub failures: BTreeMap, - /// One-time keys for the queried devices. - pub one_time_keys: BTreeMap, - } - - error: crate::Error + /// One-time keys for the queried devices. + pub one_time_keys: BTreeMap, } impl Request { diff --git a/crates/ruma-client-api/src/keys/get_key_changes.rs b/crates/ruma-client-api/src/keys/get_key_changes.rs index 7d281f1e..e5877e3f 100644 --- a/crates/ruma-client-api/src/keys/get_key_changes.rs +++ b/crates/ruma-client-api/src/keys/get_key_changes.rs @@ -5,45 +5,47 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3keyschanges - use ruma_common::{api::ruma_api, OwnedUserId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, OwnedUserId, + }; - ruma_api! { - metadata: { - description: "Gets a list of users who have updated their device identity keys since a previous sync token.", - method: GET, - name: "get_key_changes", - r0_path: "/_matrix/client/r0/keys/changes", - stable_path: "/_matrix/client/v3/keys/changes", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Gets a list of users who have updated their device identity keys since a previous sync token.", + method: GET, + name: "get_key_changes", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/keys/changes", + 1.1 => "/_matrix/client/v3/keys/changes", } + }; - request: { - /// The desired start point of the list. - /// - /// Should be the next_batch field from a response to an earlier call to /sync. - #[ruma_api(query)] - pub from: &'a str, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The desired start point of the list. + /// + /// Should be the next_batch field from a response to an earlier call to /sync. + #[ruma_api(query)] + pub from: &'a str, - /// The desired end point of the list. - /// - /// Should be the next_batch field from a recent call to /sync - typically the most recent - /// such call. - #[ruma_api(query)] - pub to: &'a str, - } + /// The desired end point of the list. + /// + /// Should be the next_batch field from a recent call to /sync - typically the most recent + /// such call. + #[ruma_api(query)] + pub to: &'a str, + } - response: { - /// The Matrix User IDs of all users who updated their device identity keys. - pub changed: Vec, + #[response(error = crate::Error)] + pub struct Response { + /// The Matrix User IDs of all users who updated their device identity keys. + pub changed: Vec, - /// The Matrix User IDs of all users who may have left all the end-to-end - /// encrypted rooms they previously shared with the user. - pub left: Vec, - } - - error: crate::Error + /// The Matrix User IDs of all users who may have left all the end-to-end + /// encrypted rooms they previously shared with the user. + pub left: Vec, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/keys/get_keys.rs b/crates/ruma-client-api/src/keys/get_keys.rs index 1569bfa0..61fc5c57 100644 --- a/crates/ruma-client-api/src/keys/get_keys.rs +++ b/crates/ruma-client-api/src/keys/get_keys.rs @@ -8,77 +8,78 @@ pub mod v3 { use std::{collections::BTreeMap, time::Duration}; use ruma_common::{ - api::ruma_api, + api::{request, response, Metadata}, encryption::{CrossSigningKey, DeviceKeys}, + metadata, serde::Raw, OwnedDeviceId, OwnedUserId, }; use serde_json::Value as JsonValue; - ruma_api! { - metadata: { - description: "Returns the current devices and identity keys for the given users.", - method: POST, - name: "get_keys", - r0_path: "/_matrix/client/r0/keys/query", - stable_path: "/_matrix/client/v3/keys/query", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Returns the current devices and identity keys for the given users.", + method: POST, + name: "get_keys", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/keys/query", + 1.1 => "/_matrix/client/v3/keys/query", } + }; - #[derive(Default)] - request: { - /// The time (in milliseconds) to wait when downloading keys from remote servers. - /// - /// 10 seconds is the recommended default. - #[serde( - with = "ruma_common::serde::duration::opt_ms", - default, - skip_serializing_if = "Option::is_none", - )] - pub timeout: Option, + #[request(error = crate::Error)] + #[derive(Default)] + pub struct Request<'a> { + /// The time (in milliseconds) to wait when downloading keys from remote servers. + /// + /// 10 seconds is the recommended default. + #[serde( + with = "ruma_common::serde::duration::opt_ms", + default, + skip_serializing_if = "Option::is_none" + )] + pub timeout: Option, - /// The keys to be downloaded. - /// - /// An empty list indicates all devices for the corresponding user. - pub device_keys: BTreeMap>, + /// The keys to be downloaded. + /// + /// An empty list indicates all devices for the corresponding user. + pub device_keys: BTreeMap>, - /// If the client is fetching keys as a result of a device update received in a sync - /// request, this should be the 'since' token of that sync request, or any later sync token. - /// - /// This allows the server to ensure its response contains the keys advertised by the - /// notification in that sync. - #[serde(skip_serializing_if = "Option::is_none")] - pub token: Option<&'a str>, - } + /// If the client is fetching keys as a result of a device update received in a sync + /// request, this should be the 'since' token of that sync request, or any later sync + /// token. + /// + /// This allows the server to ensure its response contains the keys advertised by the + /// notification in that sync. + #[serde(skip_serializing_if = "Option::is_none")] + pub token: Option<&'a str>, + } - #[derive(Default)] - response: { - /// If any remote homeservers could not be reached, they are recorded here. - /// - /// The names of the properties are the names of the unreachable servers. - #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] - pub failures: BTreeMap, + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response { + /// If any remote homeservers could not be reached, they are recorded here. + /// + /// The names of the properties are the names of the unreachable servers. + #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] + pub failures: BTreeMap, - /// Information on the queried devices. - #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] - pub device_keys: BTreeMap>>, + /// Information on the queried devices. + #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] + pub device_keys: BTreeMap>>, - /// Information on the master cross-signing keys of the queried users. - #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] - pub master_keys: BTreeMap>, + /// Information on the master cross-signing keys of the queried users. + #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] + pub master_keys: BTreeMap>, - /// Information on the self-signing keys of the queried users. - #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] - pub self_signing_keys: BTreeMap>, + /// Information on the self-signing keys of the queried users. + #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] + pub self_signing_keys: BTreeMap>, - /// Information on the user-signing keys of the queried users. - #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] - pub user_signing_keys: BTreeMap>, - } - - error: crate::Error + /// Information on the user-signing keys of the queried users. + #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] + pub user_signing_keys: BTreeMap>, } impl Request<'_> { diff --git a/crates/ruma-client-api/src/keys/upload_keys.rs b/crates/ruma-client-api/src/keys/upload_keys.rs index 3bf082a2..f88842d0 100644 --- a/crates/ruma-client-api/src/keys/upload_keys.rs +++ b/crates/ruma-client-api/src/keys/upload_keys.rs @@ -9,48 +9,48 @@ pub mod v3 { use js_int::UInt; use ruma_common::{ - api::ruma_api, + api::{request, response, Metadata}, encryption::{DeviceKeys, OneTimeKey}, + metadata, serde::Raw, DeviceKeyAlgorithm, OwnedDeviceKeyId, }; - ruma_api! { - metadata: { - description: "Publishes end-to-end encryption keys for the device.", - method: POST, - name: "upload_keys", - r0_path: "/_matrix/client/r0/keys/upload", - stable_path: "/_matrix/client/v3/keys/upload", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Publishes end-to-end encryption keys for the device.", + method: POST, + name: "upload_keys", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/keys/upload", + 1.1 => "/_matrix/client/v3/keys/upload", } + }; - #[derive(Default)] - request: { - /// Identity keys for the device. - /// - /// May be absent if no new identity keys are required. - #[serde(skip_serializing_if = "Option::is_none")] - pub device_keys: Option>, + #[request(error = crate::Error)] + #[derive(Default)] + pub struct Request { + /// Identity keys for the device. + /// + /// May be absent if no new identity keys are required. + #[serde(skip_serializing_if = "Option::is_none")] + pub device_keys: Option>, - /// One-time public keys for "pre-key" messages. - #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] - pub one_time_keys: BTreeMap>, + /// One-time public keys for "pre-key" messages. + #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] + pub one_time_keys: BTreeMap>, - /// Fallback public keys for "pre-key" messages. - #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] - pub fallback_keys: BTreeMap>, - } + /// Fallback public keys for "pre-key" messages. + #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] + pub fallback_keys: BTreeMap>, + } - response: { - /// For each key algorithm, the number of unclaimed one-time keys of that - /// type currently held on the server for this device. - pub one_time_key_counts: BTreeMap, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// For each key algorithm, the number of unclaimed one-time keys of that + /// type currently held on the server for this device. + pub one_time_key_counts: BTreeMap, } impl Request { diff --git a/crates/ruma-client-api/src/keys/upload_signatures.rs b/crates/ruma-client-api/src/keys/upload_signatures.rs index 9ab2eb1c..fb574f4f 100644 --- a/crates/ruma-client-api/src/keys/upload_signatures.rs +++ b/crates/ruma-client-api/src/keys/upload_signatures.rs @@ -8,8 +8,9 @@ pub mod v3 { use std::collections::BTreeMap; use ruma_common::{ - api::ruma_api, + api::{request, response, Metadata}, encryption::{CrossSigningKey, DeviceKeys}, + metadata, serde::{Raw, StringEnum}, OwnedDeviceId, OwnedUserId, }; @@ -20,31 +21,30 @@ pub mod v3 { pub use super::iter::SignedKeysIter; - ruma_api! { - metadata: { - description: "Publishes cross-signing signatures for the user.", - method: POST, - name: "upload_signatures", - unstable_path: "/_matrix/client/unstable/keys/signatures/upload", - stable_path: "/_matrix/client/v3/keys/signatures/upload", - rate_limited: false, - authentication: AccessToken, - added: 1.1, + const METADATA: Metadata = metadata! { + description: "Publishes cross-signing signatures for the user.", + method: POST, + name: "upload_signatures", + rate_limited: false, + authentication: AccessToken, + history: { + unstable => "/_matrix/client/unstable/keys/signatures/upload", + 1.1 => "/_matrix/client/v3/keys/signatures/upload", } + }; - request: { - /// Signed keys. - #[ruma_api(body)] - pub signed_keys: BTreeMap, - } + #[request(error = crate::Error)] + pub struct Request { + /// Signed keys. + #[ruma_api(body)] + pub signed_keys: BTreeMap, + } - #[derive(Default)] - response: { - /// Signature processing failures. - pub failures: BTreeMap>, - } - - error: crate::Error + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response { + /// Signature processing failures. + pub failures: BTreeMap>, } impl Request { diff --git a/crates/ruma-client-api/src/keys/upload_signing_keys.rs b/crates/ruma-client-api/src/keys/upload_signing_keys.rs index 7c3ac00d..2ee13be1 100644 --- a/crates/ruma-client-api/src/keys/upload_signing_keys.rs +++ b/crates/ruma-client-api/src/keys/upload_signing_keys.rs @@ -5,53 +5,57 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#post_matrixclientv3keysdevice_signingupload - use ruma_common::{api::ruma_api, encryption::CrossSigningKey, serde::Raw}; + use ruma_common::{ + api::{request, response, Metadata}, + encryption::CrossSigningKey, + metadata, + serde::Raw, + }; use crate::uiaa::{AuthData, IncomingAuthData, UiaaResponse}; - ruma_api! { - metadata: { - description: "Publishes cross signing keys for the user.", - method: POST, - name: "upload_signing_keys", - unstable_path: "/_matrix/client/unstable/keys/device_signing/upload", - stable_path: "/_matrix/client/v3/keys/device_signing/upload", - rate_limited: false, - authentication: AccessToken, - added: 1.1, + const METADATA: Metadata = metadata! { + description: "Publishes cross signing keys for the user.", + method: POST, + name: "upload_signing_keys", + rate_limited: false, + authentication: AccessToken, + history: { + unstable => "/_matrix/client/unstable/keys/device_signing/upload", + 1.1 => "/_matrix/client/v3/keys/device_signing/upload", } + }; - #[derive(Default)] - request: { - /// Additional authentication information for the user-interactive authentication API. - #[serde(skip_serializing_if = "Option::is_none")] - pub auth: Option>, + #[request(error = UiaaResponse)] + #[derive(Default)] + pub struct Request<'a> { + /// Additional authentication information for the user-interactive authentication API. + #[serde(skip_serializing_if = "Option::is_none")] + pub auth: Option>, - /// The user's master key. - #[serde(skip_serializing_if = "Option::is_none")] - pub master_key: Option>, + /// The user's master key. + #[serde(skip_serializing_if = "Option::is_none")] + pub master_key: Option>, - /// The user's self-signing key. - /// - /// Must be signed with the accompanied master, or by the user's most recently uploaded - /// master key if no master key is included in the request. - #[serde(skip_serializing_if = "Option::is_none")] - pub self_signing_key: Option>, + /// The user's self-signing key. + /// + /// Must be signed with the accompanied master, or by the user's most recently uploaded + /// master key if no master key is included in the request. + #[serde(skip_serializing_if = "Option::is_none")] + pub self_signing_key: Option>, - /// The user's user-signing key. - /// - /// Must be signed with the accompanied master, or by the user's most recently uploaded - /// master key if no master key is included in the request. - #[serde(skip_serializing_if = "Option::is_none")] - pub user_signing_key: Option>, - } - - #[derive(Default)] - response: {} - - error: UiaaResponse + /// The user's user-signing key. + /// + /// Must be signed with the accompanied master, or by the user's most recently uploaded + /// master key if no master key is included in the request. + #[serde(skip_serializing_if = "Option::is_none")] + pub user_signing_key: Option>, } + #[response(error = UiaaResponse)] + #[derive(Default)] + pub struct Response {} + impl Request<'_> { /// Creates an empty `Request`. pub fn new() -> Self { diff --git a/crates/ruma-client-api/src/knock/knock_room.rs b/crates/ruma-client-api/src/knock/knock_room.rs index a260fd25..8f50437e 100644 --- a/crates/ruma-client-api/src/knock/knock_room.rs +++ b/crates/ruma-client-api/src/knock/knock_room.rs @@ -5,41 +5,45 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#post_matrixclientv3knockroomidoralias - use ruma_common::{api::ruma_api, OwnedRoomId, OwnedServerName, RoomOrAliasId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, OwnedRoomId, OwnedServerName, RoomOrAliasId, + }; - ruma_api! { - metadata: { - description: "Knock on a room.", - method: POST, - name: "knock_room", - unstable_path: "/_matrix/client/unstable/xyz.amorgan.knock/knock/:room_id_or_alias", - stable_path: "/_matrix/client/v3/knock/:room_id_or_alias", - rate_limited: true, - authentication: AccessToken, - added: 1.1, + const METADATA: Metadata = metadata! { + description: "Knock on a room.", + method: POST, + name: "knock_room", + rate_limited: true, + authentication: AccessToken, + history: { + unstable => "/_matrix/client/unstable/xyz.amorgan.knock/knock/:room_id_or_alias", + 1.1 => "/_matrix/client/v3/knock/:room_id_or_alias", } + }; - request: { - /// The room the user should knock on. - #[ruma_api(path)] - pub room_id_or_alias: &'a RoomOrAliasId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The room the user should knock on. + #[ruma_api(path)] + pub room_id_or_alias: &'a RoomOrAliasId, - /// The reason for joining a room. - #[serde(skip_serializing_if = "Option::is_none")] - pub reason: Option<&'a str>, + /// The reason for joining a room. + #[serde(skip_serializing_if = "Option::is_none")] + pub reason: Option<&'a str>, - /// The servers to attempt to knock on the room through. - /// - /// One of the servers must be participating in the room. - #[ruma_api(query)] - #[serde(default, skip_serializing_if = "<[_]>::is_empty")] - pub server_name: &'a [OwnedServerName], - } + /// The servers to attempt to knock on the room through. + /// + /// One of the servers must be participating in the room. + #[ruma_api(query)] + #[serde(default, skip_serializing_if = "<[_]>::is_empty")] + pub server_name: &'a [OwnedServerName], + } - response: { - /// The room that the user knocked on. - pub room_id: OwnedRoomId, - } + #[response(error = crate::Error)] + pub struct Response { + /// The room that the user knocked on. + pub room_id: OwnedRoomId, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/lib.rs b/crates/ruma-client-api/src/lib.rs index 21e08c00..5fb8a80c 100644 --- a/crates/ruma-client-api/src/lib.rs +++ b/crates/ruma-client-api/src/lib.rs @@ -7,7 +7,7 @@ #![cfg(any(feature = "client", feature = "server"))] #![cfg_attr(docsrs, feature(doc_auto_cfg))] -#![warn(missing_docs)] +// #![warn(missing_docs)] FIXME pub mod account; pub mod alias; diff --git a/crates/ruma-client-api/src/media/create_content.rs b/crates/ruma-client-api/src/media/create_content.rs index ddda44bd..bcad60d1 100644 --- a/crates/ruma-client-api/src/media/create_content.rs +++ b/crates/ruma-client-api/src/media/create_content.rs @@ -6,66 +6,68 @@ pub mod v3 { //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#post_matrixmediav3upload use http::header::CONTENT_TYPE; - use ruma_common::{api::ruma_api, OwnedMxcUri}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, OwnedMxcUri, + }; - ruma_api! { - metadata: { - description: "Upload content to the media store.", - method: POST, - name: "create_media_content", - r0_path: "/_matrix/media/r0/upload", - stable_path: "/_matrix/media/v3/upload", - rate_limited: true, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Upload content to the media store.", + method: POST, + name: "create_media_content", + rate_limited: true, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/media/r0/upload", + 1.1 => "/_matrix/media/v3/upload", } + }; - request: { - /// The file contents to upload. - #[ruma_api(raw_body)] - pub file: &'a [u8], + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The file contents to upload. + #[ruma_api(raw_body)] + pub file: &'a [u8], - /// The name of the file being uploaded. - #[ruma_api(query)] - #[serde(skip_serializing_if = "Option::is_none")] - pub filename: Option<&'a str>, + /// The name of the file being uploaded. + #[ruma_api(query)] + #[serde(skip_serializing_if = "Option::is_none")] + pub filename: Option<&'a str>, - /// The content type of the file being uploaded. - #[ruma_api(header = CONTENT_TYPE)] - pub content_type: Option<&'a str>, + /// The content type of the file being uploaded. + #[ruma_api(header = CONTENT_TYPE)] + pub content_type: Option<&'a str>, - /// Should the server return a blurhash or not. - /// - /// This uses the unstable prefix in - /// [MSC2448](https://github.com/matrix-org/matrix-spec-proposals/pull/2448). - #[ruma_api(query)] - #[cfg(feature = "unstable-msc2448")] - #[serde( - default, - skip_serializing_if = "ruma_common::serde::is_default", - rename = "xyz.amorgan.generate_blurhash", - )] - pub generate_blurhash: bool, - } + /// Should the server return a blurhash or not. + /// + /// This uses the unstable prefix in + /// [MSC2448](https://github.com/matrix-org/matrix-spec-proposals/pull/2448). + #[ruma_api(query)] + #[cfg(feature = "unstable-msc2448")] + #[serde( + default, + skip_serializing_if = "ruma_common::serde::is_default", + rename = "xyz.amorgan.generate_blurhash" + )] + pub generate_blurhash: bool, + } - response: { - /// The MXC URI for the uploaded content. - pub content_uri: OwnedMxcUri, + #[response(error = crate::Error)] + pub struct Response { + /// The MXC URI for the uploaded content. + pub content_uri: OwnedMxcUri, - /// The [BlurHash](https://blurha.sh) for the uploaded content. - /// - /// This uses the unstable prefix in - /// [MSC2448](https://github.com/matrix-org/matrix-spec-proposals/pull/2448). - #[cfg(feature = "unstable-msc2448")] - #[serde( - rename = "xyz.amorgan.blurhash", - alias = "blurhash", - skip_serializing_if = "Option::is_none" - )] - pub blurhash: Option, - } - - error: crate::Error + /// The [BlurHash](https://blurha.sh) for the uploaded content. + /// + /// This uses the unstable prefix in + /// [MSC2448](https://github.com/matrix-org/matrix-spec-proposals/pull/2448). + #[cfg(feature = "unstable-msc2448")] + #[serde( + rename = "xyz.amorgan.blurhash", + alias = "blurhash", + skip_serializing_if = "Option::is_none" + )] + pub blurhash: Option, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/media/create_content_async.rs b/crates/ruma-client-api/src/media/create_content_async.rs index 6c037292..5ef9d6c6 100644 --- a/crates/ruma-client-api/src/media/create_content_async.rs +++ b/crates/ruma-client-api/src/media/create_content_async.rs @@ -6,43 +6,45 @@ pub mod unstable { //! [spec]: https://github.com/tulir/matrix-doc/blob/asynchronous_uploads/proposals/2246-asynchronous-uploads.md use http::header::CONTENT_TYPE; - use ruma_common::{api::ruma_api, IdParseError, MxcUri, ServerName}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, IdParseError, MxcUri, ServerName, + }; - ruma_api! { - metadata: { - description: "Upload media to an MXC URI that was created with create_mxc_uri.", - method: PUT, - name: "create_content_async", - unstable_path: "/_matrix/media/unstable/fi.mau.msc2246/upload/:server_name/:media_id", - rate_limited: true, - authentication: AccessToken, + const METADATA: Metadata = metadata! { + description: "Upload media to an MXC URI that was created with create_mxc_uri.", + method: PUT, + name: "create_content_async", + rate_limited: true, + authentication: AccessToken, + history: { + unstable => "/_matrix/media/unstable/fi.mau.msc2246/upload/:server_name/:media_id", } + }; - request: { - /// The server name from the mxc:// URI (the authoritory component). - #[ruma_api(path)] - pub server_name: &'a ServerName, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The server name from the mxc:// URI (the authoritory component). + #[ruma_api(path)] + pub server_name: &'a ServerName, - /// The media ID from the mxc:// URI (the path component). - #[ruma_api(path)] - pub media_id: &'a str, + /// The media ID from the mxc:// URI (the path component). + #[ruma_api(path)] + pub media_id: &'a str, - /// The file contents to upload. - #[ruma_api(raw_body)] - pub file: &'a [u8], + /// The file contents to upload. + #[ruma_api(raw_body)] + pub file: &'a [u8], - /// The content type of the file being uploaded. - #[ruma_api(header = CONTENT_TYPE)] - pub content_type: Option<&'a str>, - - // TODO: How does this and msc2448 (blurhash) interact? - } - - response: {} - - error: crate::Error + /// The content type of the file being uploaded. + #[ruma_api(header = CONTENT_TYPE)] + pub content_type: Option<&'a str>, + // TODO: How does this and msc2448 (blurhash) interact? } + #[response(error = crate::Error)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given file contents. pub fn new(media_id: &'a str, server_name: &'a ServerName, file: &'a [u8]) -> Self { diff --git a/crates/ruma-client-api/src/media/create_mxc_uri.rs b/crates/ruma-client-api/src/media/create_mxc_uri.rs index acaf5f2a..3c3b86ec 100644 --- a/crates/ruma-client-api/src/media/create_mxc_uri.rs +++ b/crates/ruma-client-api/src/media/create_mxc_uri.rs @@ -6,29 +6,33 @@ pub mod unstable { //! [spec]: https://github.com/tulir/matrix-doc/blob/asynchronous_uploads/proposals/2246-asynchronous-uploads.md use js_int::UInt; - use ruma_common::{api::ruma_api, OwnedMxcUri}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, OwnedMxcUri, + }; - ruma_api! { - metadata: { - description: "Create an MXC URI without content.", - method: POST, - name: "create_mxc_uri", - unstable_path: "/_matrix/media/unstable/fi.mau.msc2246/create", - rate_limited: true, - authentication: AccessToken, + const METADATA: Metadata = metadata! { + description: "Create an MXC URI without content.", + method: POST, + name: "create_mxc_uri", + rate_limited: true, + authentication: AccessToken, + history: { + unstable => "/_matrix/media/unstable/fi.mau.msc2246/create", } + }; - request: {} + #[request(error = crate::Error)] + #[derive(Default)] + pub struct Request {} - response: { - /// The MXC URI for the about to be uploaded content. - pub content_uri: OwnedMxcUri, + #[response(error = crate::Error)] + pub struct Response { + /// The MXC URI for the about to be uploaded content. + pub content_uri: OwnedMxcUri, - /// The time at which the URI will expire if an upload has not been started. - pub unused_expires_at: UInt, - } - - error: crate::Error + /// The time at which the URI will expire if an upload has not been started. + pub unused_expires_at: UInt, } impl Response { diff --git a/crates/ruma-client-api/src/media/get_content.rs b/crates/ruma-client-api/src/media/get_content.rs index ac5b73ab..ef8ecf97 100644 --- a/crates/ruma-client-api/src/media/get_content.rs +++ b/crates/ruma-client-api/src/media/get_content.rs @@ -8,81 +8,85 @@ pub mod v3 { use http::header::{CONTENT_DISPOSITION, CONTENT_TYPE}; #[cfg(feature = "unstable-msc2246")] use js_int::UInt; - use ruma_common::{api::ruma_api, IdParseError, MxcUri, ServerName}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, IdParseError, MxcUri, ServerName, + }; use crate::http_headers::CROSS_ORIGIN_RESOURCE_POLICY; - ruma_api! { - metadata: { - description: "Retrieve content from the media store.", - method: GET, - name: "get_media_content", - r0_path: "/_matrix/media/r0/download/:server_name/:media_id", - stable_path: "/_matrix/media/v3/download/:server_name/:media_id", - rate_limited: false, - authentication: None, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Retrieve content from the media store.", + method: GET, + name: "get_media_content", + rate_limited: false, + authentication: None, + history: { + 1.0 => "/_matrix/media/r0/download/:server_name/:media_id", + 1.1 => "/_matrix/media/v3/download/:server_name/:media_id", } + }; - request: { - /// The server name from the mxc:// URI (the authoritory component). - #[ruma_api(path)] - pub server_name: &'a ServerName, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The server name from the mxc:// URI (the authoritory component). + #[ruma_api(path)] + pub server_name: &'a ServerName, - /// The media ID from the mxc:// URI (the path component). - #[ruma_api(path)] - pub media_id: &'a str, + /// The media ID from the mxc:// URI (the path component). + #[ruma_api(path)] + pub media_id: &'a str, - /// Whether to fetch media deemed remote. - /// - /// Used to prevent routing loops. Defaults to `true`. - #[ruma_api(query)] - #[serde(default = "ruma_common::serde::default_true", skip_serializing_if = "ruma_common::serde::is_true")] - pub allow_remote: bool, + /// Whether to fetch media deemed remote. + /// + /// Used to prevent routing loops. Defaults to `true`. + #[ruma_api(query)] + #[serde( + default = "ruma_common::serde::default_true", + skip_serializing_if = "ruma_common::serde::is_true" + )] + pub allow_remote: bool, + /// How long to wait for the media to be uploaded + /// + /// This uses the unstable prefix in + /// [MSC2246](https://github.com/matrix-org/matrix-spec-proposals/pull/2246) + #[ruma_api(query)] + #[cfg(feature = "unstable-msc2246")] + #[serde( + default, + skip_serializing_if = "ruma_common::serde::is_default", + rename = "fi.mau.msc2246.max_stall_ms" + )] + pub max_stall_ms: Option, + } - /// How long to wait for the media to be uploaded - /// - /// This uses the unstable prefix in - /// [MSC2246](https://github.com/matrix-org/matrix-spec-proposals/pull/2246) - #[ruma_api(query)] - #[cfg(feature = "unstable-msc2246")] - #[serde( - default, - skip_serializing_if = "ruma_common::serde::is_default", - rename = "fi.mau.msc2246.max_stall_ms", - )] - pub max_stall_ms: Option, - } + #[response(error = crate::Error)] + pub struct Response { + /// The content that was previously uploaded. + #[ruma_api(raw_body)] + pub file: Vec, - response: { - /// The content that was previously uploaded. - #[ruma_api(raw_body)] - pub file: Vec, + /// The content type of the file that was previously uploaded. + #[ruma_api(header = CONTENT_TYPE)] + pub content_type: Option, - /// The content type of the file that was previously uploaded. - #[ruma_api(header = CONTENT_TYPE)] - pub content_type: Option, + /// The value of the `Content-Disposition` HTTP header, possibly containing the name of the + /// file that was previously uploaded. + /// + /// See [MDN] for the syntax. + /// + /// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition#Syntax + #[ruma_api(header = CONTENT_DISPOSITION)] + pub content_disposition: Option, - /// The value of the `Content-Disposition` HTTP header, possibly containing the name of the - /// file that was previously uploaded. - /// - /// See [MDN] for the syntax. - /// - /// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition#Syntax - #[ruma_api(header = CONTENT_DISPOSITION)] - pub content_disposition: Option, - - /// The value of the `Cross-Origin-Resource-Policy` HTTP header. - /// - /// See [MDN] for the syntax. - /// - /// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Resource-Policy#syntax - #[ruma_api(header = CROSS_ORIGIN_RESOURCE_POLICY)] - pub cross_origin_resource_policy: Option, - } - - error: crate::Error + /// The value of the `Cross-Origin-Resource-Policy` HTTP header. + /// + /// See [MDN] for the syntax. + /// + /// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Resource-Policy#syntax + #[ruma_api(header = CROSS_ORIGIN_RESOURCE_POLICY)] + pub cross_origin_resource_policy: Option, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/media/get_content_as_filename.rs b/crates/ruma-client-api/src/media/get_content_as_filename.rs index 40b01e9d..94aef2d0 100644 --- a/crates/ruma-client-api/src/media/get_content_as_filename.rs +++ b/crates/ruma-client-api/src/media/get_content_as_filename.rs @@ -6,71 +6,76 @@ pub mod v3 { //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixmediav3downloadservernamemediaidfilename use http::header::{CONTENT_DISPOSITION, CONTENT_TYPE}; - use ruma_common::{api::ruma_api, IdParseError, MxcUri, ServerName}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, IdParseError, MxcUri, ServerName, + }; use crate::http_headers::CROSS_ORIGIN_RESOURCE_POLICY; - ruma_api! { - metadata: { - description: "Retrieve content from the media store, specifying a filename to return.", - method: GET, - name: "get_media_content_as_filename", - r0_path: "/_matrix/media/r0/download/:server_name/:media_id/:filename", - stable_path: "/_matrix/media/v3/download/:server_name/:media_id/:filename", - rate_limited: false, - authentication: None, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Retrieve content from the media store, specifying a filename to return.", + method: GET, + name: "get_media_content_as_filename", + rate_limited: false, + authentication: None, + history: { + 1.0 => "/_matrix/media/r0/download/:server_name/:media_id/:filename", + 1.1 => "/_matrix/media/v3/download/:server_name/:media_id/:filename", } + }; - request: { - /// The server name from the mxc:// URI (the authoritory component). - #[ruma_api(path)] - pub server_name: &'a ServerName, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The server name from the mxc:// URI (the authoritory component). + #[ruma_api(path)] + pub server_name: &'a ServerName, - /// The media ID from the mxc:// URI (the path component). - #[ruma_api(path)] - pub media_id: &'a str, + /// The media ID from the mxc:// URI (the path component). + #[ruma_api(path)] + pub media_id: &'a str, - /// The filename to return in the `Content-Disposition` header. - #[ruma_api(path)] - pub filename: &'a str, + /// The filename to return in the `Content-Disposition` header. + #[ruma_api(path)] + pub filename: &'a str, - /// Whether to fetch media deemed remote. - /// - /// Used to prevent routing loops. Defaults to `true`. - #[ruma_api(query)] - #[serde(default = "ruma_common::serde::default_true", skip_serializing_if = "ruma_common::serde::is_true")] - pub allow_remote: bool, - } + /// Whether to fetch media deemed remote. + /// + /// Used to prevent routing loops. Defaults to `true`. + #[ruma_api(query)] + #[serde( + default = "ruma_common::serde::default_true", + skip_serializing_if = "ruma_common::serde::is_true" + )] + pub allow_remote: bool, + } - response: { - /// The content that was previously uploaded. - #[ruma_api(raw_body)] - pub file: Vec, + #[response(error = crate::Error)] + pub struct Response { + /// The content that was previously uploaded. + #[ruma_api(raw_body)] + pub file: Vec, - /// The content type of the file that was previously uploaded. - #[ruma_api(header = CONTENT_TYPE)] - pub content_type: Option, + /// The content type of the file that was previously uploaded. + #[ruma_api(header = CONTENT_TYPE)] + pub content_type: Option, - /// The value of the `Content-Disposition` HTTP header, possibly containing the name of the - /// file that was previously uploaded. - /// - /// See [MDN] for the syntax. - /// - /// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition#Syntax - #[ruma_api(header = CONTENT_DISPOSITION)] - pub content_disposition: Option, + /// The value of the `Content-Disposition` HTTP header, possibly containing the name of the + /// file that was previously uploaded. + /// + /// See [MDN] for the syntax. + /// + /// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition#Syntax + #[ruma_api(header = CONTENT_DISPOSITION)] + pub content_disposition: Option, - /// The value of the `Cross-Origin-Resource-Policy` HTTP header. - /// - /// See [MDN] for the syntax. - /// - /// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Resource-Policy#syntax - #[ruma_api(header = CROSS_ORIGIN_RESOURCE_POLICY)] - pub cross_origin_resource_policy: Option, - } - - error: crate::Error + /// The value of the `Cross-Origin-Resource-Policy` HTTP header. + /// + /// See [MDN] for the syntax. + /// + /// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Resource-Policy#syntax + #[ruma_api(header = CROSS_ORIGIN_RESOURCE_POLICY)] + pub cross_origin_resource_policy: Option, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/media/get_content_thumbnail.rs b/crates/ruma-client-api/src/media/get_content_thumbnail.rs index 037e648a..e3c1b357 100644 --- a/crates/ruma-client-api/src/media/get_content_thumbnail.rs +++ b/crates/ruma-client-api/src/media/get_content_thumbnail.rs @@ -7,88 +7,95 @@ pub mod v3 { use http::header::CONTENT_TYPE; use js_int::UInt; - use ruma_common::{api::ruma_api, serde::StringEnum, IdParseError, MxcUri, ServerName}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + serde::StringEnum, + IdParseError, MxcUri, ServerName, + }; use crate::{http_headers::CROSS_ORIGIN_RESOURCE_POLICY, PrivOwnedStr}; - ruma_api! { - metadata: { - description: "Get a thumbnail of content from the media store.", - method: GET, - name: "get_content_thumbnail", - r0_path: "/_matrix/media/r0/thumbnail/:server_name/:media_id", - stable_path: "/_matrix/media/v3/thumbnail/:server_name/:media_id", - rate_limited: true, - authentication: None, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Get a thumbnail of content from the media store.", + method: GET, + name: "get_content_thumbnail", + rate_limited: true, + authentication: None, + history: { + 1.0 => "/_matrix/media/r0/thumbnail/:server_name/:media_id", + 1.1 => "/_matrix/media/v3/thumbnail/:server_name/:media_id", } + }; - request: { - /// The server name from the mxc:// URI (the authoritory component). - #[ruma_api(path)] - pub server_name: &'a ServerName, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The server name from the mxc:// URI (the authoritory component). + #[ruma_api(path)] + pub server_name: &'a ServerName, - /// The media ID from the mxc:// URI (the path component). - #[ruma_api(path)] - pub media_id: &'a str, + /// The media ID from the mxc:// URI (the path component). + #[ruma_api(path)] + pub media_id: &'a str, - /// The desired resizing method. - #[ruma_api(query)] - #[serde(skip_serializing_if = "Option::is_none")] - pub method: Option, + /// The desired resizing method. + #[ruma_api(query)] + #[serde(skip_serializing_if = "Option::is_none")] + pub method: Option, - /// The *desired* width of the thumbnail. - /// - /// The actual thumbnail may not match the size specified. - #[ruma_api(query)] - pub width: UInt, + /// The *desired* width of the thumbnail. + /// + /// The actual thumbnail may not match the size specified. + #[ruma_api(query)] + pub width: UInt, - /// The *desired* height of the thumbnail. - /// - /// The actual thumbnail may not match the size specified. - #[ruma_api(query)] - pub height: UInt, + /// The *desired* height of the thumbnail. + /// + /// The actual thumbnail may not match the size specified. + #[ruma_api(query)] + pub height: UInt, - /// Whether to fetch media deemed remote. - /// - /// Used to prevent routing loops. Defaults to `true`. - #[ruma_api(query)] - #[serde(default = "ruma_common::serde::default_true", skip_serializing_if = "ruma_common::serde::is_true")] - pub allow_remote: bool, + /// Whether to fetch media deemed remote. + /// + /// Used to prevent routing loops. Defaults to `true`. + #[ruma_api(query)] + #[serde( + default = "ruma_common::serde::default_true", + skip_serializing_if = "ruma_common::serde::is_true" + )] + pub allow_remote: bool, - /// How long to wait for the media to be uploaded - /// - /// This uses the unstable prefix in - /// [MSC2246](https://github.com/matrix-org/matrix-spec-proposals/pull/2246) - #[ruma_api(query)] - #[cfg(feature = "unstable-msc2246")] - #[serde( - default, - skip_serializing_if = "ruma_common::serde::is_default", - rename = "fi.mau.msc2246.max_stall_ms", - )] - pub max_stall_ms: Option, - } + /// How long to wait for the media to be uploaded + /// + /// This uses the unstable prefix in + /// [MSC2246](https://github.com/matrix-org/matrix-spec-proposals/pull/2246) + #[ruma_api(query)] + #[cfg(feature = "unstable-msc2246")] + #[serde( + default, + skip_serializing_if = "ruma_common::serde::is_default", + rename = "fi.mau.msc2246.max_stall_ms" + )] + pub max_stall_ms: Option, + } - response: { - /// A thumbnail of the requested content. - #[ruma_api(raw_body)] - pub file: Vec, + #[response(error = crate::Error)] + pub struct Response { + /// A thumbnail of the requested content. + #[ruma_api(raw_body)] + pub file: Vec, - /// The content type of the thumbnail. - #[ruma_api(header = CONTENT_TYPE)] - pub content_type: Option, + /// The content type of the thumbnail. + #[ruma_api(header = CONTENT_TYPE)] + pub content_type: Option, - /// The value of the `Cross-Origin-Resource-Policy` HTTP header. - /// - /// See [MDN] for the syntax. - /// - /// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Resource-Policy#syntax - #[ruma_api(header = CROSS_ORIGIN_RESOURCE_POLICY)] - pub cross_origin_resource_policy: Option, - } - - error: crate::Error + /// The value of the `Cross-Origin-Resource-Policy` HTTP header. + /// + /// See [MDN] for the syntax. + /// + /// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cross-Origin-Resource-Policy#syntax + #[ruma_api(header = CROSS_ORIGIN_RESOURCE_POLICY)] + pub cross_origin_resource_policy: Option, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/media/get_media_config.rs b/crates/ruma-client-api/src/media/get_media_config.rs index 9a46a41c..0f5b4ead 100644 --- a/crates/ruma-client-api/src/media/get_media_config.rs +++ b/crates/ruma-client-api/src/media/get_media_config.rs @@ -6,30 +6,32 @@ pub mod v3 { //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixmediav3config use js_int::UInt; - use ruma_common::api::ruma_api; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + }; - ruma_api! { - metadata: { - description: "Gets the config for the media repository.", - method: GET, - r0_path: "/_matrix/media/r0/config", - stable_path: "/_matrix/media/v3/config", - name: "get_media_config", - rate_limited: true, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Gets the config for the media repository.", + method: GET, + name: "get_media_config", + rate_limited: true, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/media/r0/config", + 1.1 => "/_matrix/media/v3/config", } + }; - #[derive(Default)] - request: {} + #[request(error = crate::Error)] + #[derive(Default)] + pub struct Request {} - response: { - /// Maximum size of upload in bytes. - #[serde(rename = "m.upload.size")] - pub upload_size: UInt, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// Maximum size of upload in bytes. + #[serde(rename = "m.upload.size")] + pub upload_size: UInt, } impl Request { diff --git a/crates/ruma-client-api/src/media/get_media_preview.rs b/crates/ruma-client-api/src/media/get_media_preview.rs index 857bad19..1397c06b 100644 --- a/crates/ruma-client-api/src/media/get_media_preview.rs +++ b/crates/ruma-client-api/src/media/get_media_preview.rs @@ -5,43 +5,45 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixmediav3preview_url - use ruma_common::{api::ruma_api, MilliSecondsSinceUnixEpoch}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, MilliSecondsSinceUnixEpoch, + }; use serde::Serialize; use serde_json::value::{to_raw_value as to_raw_json_value, RawValue as RawJsonValue}; - ruma_api! { - metadata: { - description: "Get a preview for a URL.", - name: "get_media_preview", - method: GET, - r0_path: "/_matrix/media/r0/preview_url", - stable_path: "/_matrix/media/v3/preview_url", - rate_limited: true, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Get a preview for a URL.", + method: GET, + name: "get_media_preview", + rate_limited: true, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/media/r0/preview_url", + 1.1 => "/_matrix/media/v3/preview_url", } + }; - request: { - /// URL to get a preview of. - #[ruma_api(query)] - pub url: &'a str, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// URL to get a preview of. + #[ruma_api(query)] + pub url: &'a str, - /// Preferred point in time (in milliseconds) to return a preview for. - #[ruma_api(query)] - pub ts: MilliSecondsSinceUnixEpoch, - } + /// Preferred point in time (in milliseconds) to return a preview for. + #[ruma_api(query)] + pub ts: MilliSecondsSinceUnixEpoch, + } - #[derive(Default)] - response: { - /// OpenGraph-like data for the URL. - /// - /// Differences from OpenGraph: the image size in bytes is added to the `matrix:image:size` - /// field, and `og:image` returns the MXC URI to the image, if any. - #[ruma_api(body)] - pub data: Option>, - } - - error: crate::Error + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response { + /// OpenGraph-like data for the URL. + /// + /// Differences from OpenGraph: the image size in bytes is added to the `matrix:image:size` + /// field, and `og:image` returns the MXC URI to the image, if any. + #[ruma_api(body)] + pub data: Option>, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/membership/ban_user.rs b/crates/ruma-client-api/src/membership/ban_user.rs index 0b4330bc..8931f363 100644 --- a/crates/ruma-client-api/src/membership/ban_user.rs +++ b/crates/ruma-client-api/src/membership/ban_user.rs @@ -5,39 +5,41 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#post_matrixclientv3roomsroomidban - use ruma_common::{api::ruma_api, RoomId, UserId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, RoomId, UserId, + }; - ruma_api! { - metadata: { - description: "Ban a user from a room.", - method: POST, - name: "ban_user", - r0_path: "/_matrix/client/r0/rooms/:room_id/ban", - stable_path: "/_matrix/client/v3/rooms/:room_id/ban", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Ban a user from a room.", + method: POST, + name: "ban_user", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/rooms/:room_id/ban", + 1.1 => "/_matrix/client/v3/rooms/:room_id/ban", } + }; - request: { - /// The room to kick the user from. - #[ruma_api(path)] - pub room_id: &'a RoomId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The room to kick the user from. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The user to ban. - pub user_id: &'a UserId, + /// The user to ban. + pub user_id: &'a UserId, - /// The reason for banning the user. - #[serde(skip_serializing_if = "Option::is_none")] - pub reason: Option<&'a str>, - } - - #[derive(Default)] - response: {} - - error: crate::Error + /// The reason for banning the user. + #[serde(skip_serializing_if = "Option::is_none")] + pub reason: Option<&'a str>, } + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given room id and room id. pub fn new(room_id: &'a RoomId, user_id: &'a UserId) -> Self { diff --git a/crates/ruma-client-api/src/membership/forget_room.rs b/crates/ruma-client-api/src/membership/forget_room.rs index 3da443b0..57dd0bca 100644 --- a/crates/ruma-client-api/src/membership/forget_room.rs +++ b/crates/ruma-client-api/src/membership/forget_room.rs @@ -5,32 +5,34 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#post_matrixclientv3roomsroomidforget - use ruma_common::{api::ruma_api, RoomId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, RoomId, + }; - ruma_api! { - metadata: { - description: "Forget a room.", - method: POST, - name: "forget_room", - r0_path: "/_matrix/client/r0/rooms/:room_id/forget", - stable_path: "/_matrix/client/v3/rooms/:room_id/forget", - rate_limited: true, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Forget a room.", + method: POST, + name: "forget_room", + rate_limited: true, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/rooms/:room_id/forget", + 1.1 => "/_matrix/client/v3/rooms/:room_id/forget", } + }; - request: { - /// The room to forget. - #[ruma_api(path)] - pub room_id: &'a RoomId, - } - - #[derive(Default)] - response: {} - - error: crate::Error + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The room to forget. + #[ruma_api(path)] + pub room_id: &'a RoomId, } + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given room id. pub fn new(room_id: &'a RoomId) -> Self { diff --git a/crates/ruma-client-api/src/membership/get_member_events.rs b/crates/ruma-client-api/src/membership/get_member_events.rs index 5054bb19..462caa90 100644 --- a/crates/ruma-client-api/src/membership/get_member_events.rs +++ b/crates/ruma-client-api/src/membership/get_member_events.rs @@ -6,62 +6,62 @@ pub mod v3 { //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3roomsroomidmembers use ruma_common::{ - api::ruma_api, + api::{request, response, Metadata}, events::room::member::RoomMemberEvent, + metadata, serde::{Raw, StringEnum}, RoomId, }; use crate::PrivOwnedStr; - ruma_api! { - metadata: { - description: "Get membership events for a room.", - method: GET, - name: "get_member_events", - r0_path: "/_matrix/client/r0/rooms/:room_id/members", - stable_path: "/_matrix/client/v3/rooms/:room_id/members", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Get membership events for a room.", + method: GET, + name: "get_member_events", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/rooms/:room_id/members", + 1.1 => "/_matrix/client/v3/rooms/:room_id/members", } + }; - request: { - /// The room to get the member events for. - #[ruma_api(path)] - pub room_id: &'a RoomId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The room to get the member events for. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The point in time (pagination token) to return members for in the room. - /// - /// This token can be obtained from a prev_batch token returned for each room by the sync - /// API. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub at: Option<&'a str>, + /// The point in time (pagination token) to return members for in the room. + /// + /// This token can be obtained from a prev_batch token returned for each room by the sync + /// API. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub at: Option<&'a str>, - /// The kind of memberships to filter for. - /// - /// Defaults to no filtering if unspecified. When specified alongside not_membership, the - /// two parameters create an 'or' condition: either the membership is the same as membership - /// or is not the same as not_membership. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub membership: Option, + /// The kind of memberships to filter for. + /// + /// Defaults to no filtering if unspecified. When specified alongside not_membership, the + /// two parameters create an 'or' condition: either the membership is the same as + /// membership or is not the same as not_membership. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub membership: Option, - /// The kind of memberships to *exclude* from the results. - /// - /// Defaults to no filtering if unspecified. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub not_membership: Option, - } + /// The kind of memberships to *exclude* from the results. + /// + /// Defaults to no filtering if unspecified. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub not_membership: Option, + } - response: { - /// A list of member events. - pub chunk: Vec>, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// A list of member events. + pub chunk: Vec>, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/membership/invite_user.rs b/crates/ruma-client-api/src/membership/invite_user.rs index f70a4b03..3922b165 100644 --- a/crates/ruma-client-api/src/membership/invite_user.rs +++ b/crates/ruma-client-api/src/membership/invite_user.rs @@ -10,43 +10,47 @@ pub mod v3 { //! [spec-mxid]: https://spec.matrix.org/v1.4/client-server-api/#post_matrixclientv3roomsroomidinvite //! [spec-3pid]: https://spec.matrix.org/v1.4/client-server-api/#post_matrixclientv3roomsroomidinvite-1 - use ruma_common::{api::ruma_api, serde::Incoming, RoomId, UserId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + serde::Incoming, + RoomId, UserId, + }; use serde::Serialize; use crate::membership::{IncomingInvite3pid, Invite3pid}; - ruma_api! { - metadata: { - description: "Invite a user to a room.", - method: POST, - name: "invite_user", - r0_path: "/_matrix/client/r0/rooms/:room_id/invite", - stable_path: "/_matrix/client/v3/rooms/:room_id/invite", - rate_limited: true, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Invite a user to a room.", + method: POST, + name: "invite_user", + rate_limited: true, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/rooms/:room_id/invite", + 1.1 => "/_matrix/client/v3/rooms/:room_id/invite", } + }; - request: { - /// The room where the user should be invited. - #[ruma_api(path)] - pub room_id: &'a RoomId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The room where the user should be invited. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The user to invite. - #[serde(flatten)] - pub recipient: InvitationRecipient<'a>, + /// The user to invite. + #[serde(flatten)] + pub recipient: InvitationRecipient<'a>, - /// Optional reason for inviting the user. - #[serde(skip_serializing_if = "Option::is_none")] - pub reason: Option<&'a str>, - } - - #[derive(Default)] - response: {} - - error: crate::Error + /// Optional reason for inviting the user. + #[serde(skip_serializing_if = "Option::is_none")] + pub reason: Option<&'a str>, } + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given room ID and invitation recipient. pub fn new(room_id: &'a RoomId, recipient: InvitationRecipient<'a>) -> Self { diff --git a/crates/ruma-client-api/src/membership/join_room_by_id.rs b/crates/ruma-client-api/src/membership/join_room_by_id.rs index 6bfecc92..23beb0dc 100644 --- a/crates/ruma-client-api/src/membership/join_room_by_id.rs +++ b/crates/ruma-client-api/src/membership/join_room_by_id.rs @@ -5,43 +5,45 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#post_matrixclientv3roomsroomidjoin - use ruma_common::{api::ruma_api, OwnedRoomId, RoomId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, OwnedRoomId, RoomId, + }; use crate::membership::{IncomingThirdPartySigned, ThirdPartySigned}; - ruma_api! { - metadata: { - description: "Join a room using its ID.", - method: POST, - name: "join_room_by_id", - r0_path: "/_matrix/client/r0/rooms/:room_id/join", - stable_path: "/_matrix/client/v3/rooms/:room_id/join", - rate_limited: true, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Join a room using its ID.", + method: POST, + name: "join_room_by_id", + rate_limited: true, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/rooms/:room_id/join", + 1.1 => "/_matrix/client/v3/rooms/:room_id/join", } + }; - request: { - /// The room where the user should be invited. - #[ruma_api(path)] - pub room_id: &'a RoomId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The room where the user should be invited. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The signature of a `m.third_party_invite` token to prove that this user owns a third - /// party identity which has been invited to the room. - #[serde(skip_serializing_if = "Option::is_none")] - pub third_party_signed: Option>, + /// The signature of a `m.third_party_invite` token to prove that this user owns a third + /// party identity which has been invited to the room. + #[serde(skip_serializing_if = "Option::is_none")] + pub third_party_signed: Option>, - /// Optional reason for joining the room. - #[serde(skip_serializing_if = "Option::is_none")] - pub reason: Option<&'a str>, - } + /// Optional reason for joining the room. + #[serde(skip_serializing_if = "Option::is_none")] + pub reason: Option<&'a str>, + } - response: { - /// The room that the user joined. - pub room_id: OwnedRoomId, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// The room that the user joined. + pub room_id: OwnedRoomId, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/membership/join_room_by_id_or_alias.rs b/crates/ruma-client-api/src/membership/join_room_by_id_or_alias.rs index 188ddeb7..56cc149b 100644 --- a/crates/ruma-client-api/src/membership/join_room_by_id_or_alias.rs +++ b/crates/ruma-client-api/src/membership/join_room_by_id_or_alias.rs @@ -5,50 +5,52 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#post_matrixclientv3joinroomidoralias - use ruma_common::{api::ruma_api, OwnedRoomId, OwnedServerName, RoomOrAliasId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, OwnedRoomId, OwnedServerName, RoomOrAliasId, + }; use crate::membership::{IncomingThirdPartySigned, ThirdPartySigned}; - ruma_api! { - metadata: { - description: "Join a room using its ID or one of its aliases.", - method: POST, - name: "join_room_by_id_or_alias", - r0_path: "/_matrix/client/r0/join/:room_id_or_alias", - stable_path: "/_matrix/client/v3/join/:room_id_or_alias", - rate_limited: true, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Join a room using its ID or one of its aliases.", + method: POST, + name: "join_room_by_id_or_alias", + rate_limited: true, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/join/:room_id_or_alias", + 1.1 => "/_matrix/client/v3/join/:room_id_or_alias", } + }; - request: { - /// The room where the user should be invited. - #[ruma_api(path)] - pub room_id_or_alias: &'a RoomOrAliasId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The room where the user should be invited. + #[ruma_api(path)] + pub room_id_or_alias: &'a RoomOrAliasId, - /// The servers to attempt to join the room through. - /// - /// One of the servers must be participating in the room. - #[ruma_api(query)] - #[serde(default, skip_serializing_if = "<[_]>::is_empty")] - pub server_name: &'a [OwnedServerName], + /// The servers to attempt to join the room through. + /// + /// One of the servers must be participating in the room. + #[ruma_api(query)] + #[serde(default, skip_serializing_if = "<[_]>::is_empty")] + pub server_name: &'a [OwnedServerName], - /// The signature of a `m.third_party_invite` token to prove that this user owns a third - /// party identity which has been invited to the room. - #[serde(skip_serializing_if = "Option::is_none")] - pub third_party_signed: Option>, + /// The signature of a `m.third_party_invite` token to prove that this user owns a third + /// party identity which has been invited to the room. + #[serde(skip_serializing_if = "Option::is_none")] + pub third_party_signed: Option>, - /// Optional reason for joining the room. - #[serde(skip_serializing_if = "Option::is_none")] - pub reason: Option<&'a str>, - } + /// Optional reason for joining the room. + #[serde(skip_serializing_if = "Option::is_none")] + pub reason: Option<&'a str>, + } - response: { - /// The room that the user joined. - pub room_id: OwnedRoomId, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// The room that the user joined. + pub room_id: OwnedRoomId, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/membership/joined_members.rs b/crates/ruma-client-api/src/membership/joined_members.rs index dc3200a2..082c5a25 100644 --- a/crates/ruma-client-api/src/membership/joined_members.rs +++ b/crates/ruma-client-api/src/membership/joined_members.rs @@ -7,34 +7,36 @@ pub mod v3 { use std::collections::BTreeMap; - use ruma_common::{api::ruma_api, OwnedMxcUri, OwnedUserId, RoomId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, OwnedMxcUri, OwnedUserId, RoomId, + }; use serde::{Deserialize, Serialize}; - ruma_api! { - metadata: { - description: "Get a map of user ids to member info objects for members of the room. Primarily for use in Application Services.", - method: GET, - name: "joined_members", - r0_path: "/_matrix/client/r0/rooms/:room_id/joined_members", - stable_path: "/_matrix/client/v3/rooms/:room_id/joined_members", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Get a map of user ids to member info objects for members of the room. Primarily for use in Application Services.", + method: GET, + name: "joined_members", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/rooms/:room_id/joined_members", + 1.1 => "/_matrix/client/v3/rooms/:room_id/joined_members", } + }; - request: { - /// The room to get the members of. - #[ruma_api(path)] - pub room_id: &'a RoomId, - } + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The room to get the members of. + #[ruma_api(path)] + pub room_id: &'a RoomId, + } - response: { - /// A list of the rooms the user is in, i.e. - /// the ID of each room in which the user has joined membership. - pub joined: BTreeMap, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// A list of the rooms the user is in, i.e. + /// the ID of each room in which the user has joined membership. + pub joined: BTreeMap, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/membership/joined_rooms.rs b/crates/ruma-client-api/src/membership/joined_rooms.rs index 28784e6d..68e99069 100644 --- a/crates/ruma-client-api/src/membership/joined_rooms.rs +++ b/crates/ruma-client-api/src/membership/joined_rooms.rs @@ -5,30 +5,32 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3joined_rooms - use ruma_common::{api::ruma_api, OwnedRoomId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, OwnedRoomId, + }; - ruma_api! { - metadata: { - description: "Get a list of the user's current rooms.", - method: GET, - name: "joined_rooms", - r0_path: "/_matrix/client/r0/joined_rooms", - stable_path: "/_matrix/client/v3/joined_rooms", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Get a list of the user's current rooms.", + method: GET, + name: "joined_rooms", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/joined_rooms", + 1.1 => "/_matrix/client/v3/joined_rooms", } + }; - #[derive(Default)] - request: {} + #[request(error = crate::Error)] + #[derive(Default)] + pub struct Request {} - response: { - /// A list of the rooms the user is in, i.e. the ID of each room in - /// which the user has joined membership. - pub joined_rooms: Vec, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// A list of the rooms the user is in, i.e. the ID of each room in + /// which the user has joined membership. + pub joined_rooms: Vec, } impl Request { diff --git a/crates/ruma-client-api/src/membership/kick_user.rs b/crates/ruma-client-api/src/membership/kick_user.rs index 5268eaa3..309bba86 100644 --- a/crates/ruma-client-api/src/membership/kick_user.rs +++ b/crates/ruma-client-api/src/membership/kick_user.rs @@ -5,39 +5,41 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#post_matrixclientv3roomsroomidkick - use ruma_common::{api::ruma_api, RoomId, UserId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, RoomId, UserId, + }; - ruma_api! { - metadata: { - description: "Kick a user from a room.", - method: POST, - name: "kick_user", - r0_path: "/_matrix/client/r0/rooms/:room_id/kick", - stable_path: "/_matrix/client/v3/rooms/:room_id/kick", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Kick a user from a room.", + method: POST, + name: "kick_user", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/rooms/:room_id/kick", + 1.1 => "/_matrix/client/v3/rooms/:room_id/kick", } + }; - request: { - /// The room to kick the user from. - #[ruma_api(path)] - pub room_id: &'a RoomId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The room to kick the user from. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The user to kick. - pub user_id: &'a UserId, + /// The user to kick. + pub user_id: &'a UserId, - /// The reason for kicking the user. - #[serde(skip_serializing_if = "Option::is_none")] - pub reason: Option<&'a str>, - } - - #[derive(Default)] - response: {} - - error: crate::Error + /// The reason for kicking the user. + #[serde(skip_serializing_if = "Option::is_none")] + pub reason: Option<&'a str>, } + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given room id and room id. pub fn new(room_id: &'a RoomId, user_id: &'a UserId) -> Self { diff --git a/crates/ruma-client-api/src/membership/leave_room.rs b/crates/ruma-client-api/src/membership/leave_room.rs index 7b83805d..e95e143f 100644 --- a/crates/ruma-client-api/src/membership/leave_room.rs +++ b/crates/ruma-client-api/src/membership/leave_room.rs @@ -5,36 +5,38 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#post_matrixclientv3roomsroomidleave - use ruma_common::{api::ruma_api, RoomId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, RoomId, + }; - ruma_api! { - metadata: { - description: "Leave a room.", - method: POST, - name: "leave_room", - r0_path: "/_matrix/client/r0/rooms/:room_id/leave", - stable_path: "/_matrix/client/v3/rooms/:room_id/leave", - rate_limited: true, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Leave a room.", + method: POST, + name: "leave_room", + rate_limited: true, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/rooms/:room_id/leave", + 1.1 => "/_matrix/client/v3/rooms/:room_id/leave", } + }; - request: { - /// The room to leave. - #[ruma_api(path)] - pub room_id: &'a RoomId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The room to leave. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// Optional reason to be included as the `reason` on the subsequent membership event. - #[serde(skip_serializing_if = "Option::is_none")] - pub reason: Option<&'a str>, - } - - #[derive(Default)] - response: {} - - error: crate::Error + /// Optional reason to be included as the `reason` on the subsequent membership event. + #[serde(skip_serializing_if = "Option::is_none")] + pub reason: Option<&'a str>, } + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given room id. pub fn new(room_id: &'a RoomId) -> Self { diff --git a/crates/ruma-client-api/src/membership/mutual_rooms.rs b/crates/ruma-client-api/src/membership/mutual_rooms.rs index 4a523167..25781879 100644 --- a/crates/ruma-client-api/src/membership/mutual_rooms.rs +++ b/crates/ruma-client-api/src/membership/mutual_rooms.rs @@ -5,30 +5,33 @@ pub mod unstable { //! //! [spec]: https://github.com/matrix-org/matrix-spec-proposals/blob/hs/shared-rooms/proposals/2666-get-rooms-in-common.md - use ruma_common::{api::ruma_api, OwnedRoomId, UserId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, OwnedRoomId, UserId, + }; - ruma_api! { - metadata: { - description: "Get mutual rooms with another user.", - method: GET, - name: "mutual_rooms", - unstable_path: "/_matrix/client/unstable/uk.half-shot.msc2666/user/mutual_rooms/:user_id", - rate_limited: true, - authentication: AccessToken, + const METADATA: Metadata = metadata! { + description: "Get mutual rooms with another user.", + method: GET, + name: "mutual_rooms", + rate_limited: true, + authentication: AccessToken, + history: { + unstable => "/_matrix/client/unstable/uk.half-shot.msc2666/user/mutual_rooms/:user_id", } + }; - request: { - /// The user to search mutual rooms for. - #[ruma_api(path)] - pub user_id: &'a UserId, - } + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The user to search mutual rooms for. + #[ruma_api(path)] + pub user_id: &'a UserId, + } - response: { - /// A list of rooms the user is in together with the authenticated user. - pub joined: Vec, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// A list of rooms the user is in together with the authenticated user. + pub joined: Vec, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/membership/unban_user.rs b/crates/ruma-client-api/src/membership/unban_user.rs index b9ce2107..7933fd8a 100644 --- a/crates/ruma-client-api/src/membership/unban_user.rs +++ b/crates/ruma-client-api/src/membership/unban_user.rs @@ -5,39 +5,41 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#post_matrixclientv3roomsroomidunban - use ruma_common::{api::ruma_api, RoomId, UserId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, RoomId, UserId, + }; - ruma_api! { - metadata: { - description: "Unban a user from a room.", - method: POST, - name: "unban_user", - r0_path: "/_matrix/client/r0/rooms/:room_id/unban", - stable_path: "/_matrix/client/v3/rooms/:room_id/unban", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Unban a user from a room.", + method: POST, + name: "unban_user", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/rooms/:room_id/unban", + 1.1 => "/_matrix/client/v3/rooms/:room_id/unban", } + }; - request: { - /// The room to unban the user from. - #[ruma_api(path)] - pub room_id: &'a RoomId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The room to unban the user from. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The user to unban. - pub user_id: &'a UserId, + /// The user to unban. + pub user_id: &'a UserId, - /// Optional reason for unbanning the user. - #[serde(skip_serializing_if = "Option::is_none")] - pub reason: Option<&'a str>, - } - - #[derive(Default)] - response: {} - - error: crate::Error + /// Optional reason for unbanning the user. + #[serde(skip_serializing_if = "Option::is_none")] + pub reason: Option<&'a str>, } + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given room id and room id. pub fn new(room_id: &'a RoomId, user_id: &'a UserId) -> Self { diff --git a/crates/ruma-client-api/src/message/get_message_events.rs b/crates/ruma-client-api/src/message/get_message_events.rs index a3a9aa74..f21938e4 100644 --- a/crates/ruma-client-api/src/message/get_message_events.rs +++ b/crates/ruma-client-api/src/message/get_message_events.rs @@ -7,8 +7,9 @@ pub mod v3 { use js_int::{uint, UInt}; use ruma_common::{ - api::ruma_api, + api::{request, response, Metadata}, events::{AnyStateEvent, AnyTimelineEvent}, + metadata, serde::Raw, RoomId, }; @@ -18,83 +19,82 @@ pub mod v3 { Direction, }; - ruma_api! { - metadata: { - description: "Get message events for a room.", - method: GET, - name: "get_message_events", - r0_path: "/_matrix/client/r0/rooms/:room_id/messages", - stable_path: "/_matrix/client/v3/rooms/:room_id/messages", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Get message events for a room.", + method: GET, + name: "get_message_events", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/rooms/:room_id/messages", + 1.1 => "/_matrix/client/v3/rooms/:room_id/messages", } + }; - request: { - /// The room to get events from. - #[ruma_api(path)] - pub room_id: &'a RoomId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The room to get events from. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The token to start returning events from. - /// - /// This token can be obtained from a `prev_batch` token returned for each room by the - /// sync endpoint, or from a `start` or `end` token returned by a previous request to - /// this endpoint. - /// - /// If this is `None`, the server will return messages from the start or end of the - /// history visible to the user, depending on the value of [`dir`][Self::dir]. - #[ruma_api(query)] - pub from: Option<&'a str>, + /// The token to start returning events from. + /// + /// This token can be obtained from a `prev_batch` token returned for each room by the + /// sync endpoint, or from a `start` or `end` token returned by a previous request to + /// this endpoint. + /// + /// If this is `None`, the server will return messages from the start or end of the + /// history visible to the user, depending on the value of [`dir`][Self::dir]. + #[ruma_api(query)] + pub from: Option<&'a str>, - /// The token to stop returning events at. - /// - /// This token can be obtained from a `prev_batch` token returned for each room by the - /// sync endpoint, or from a `start` or `end` token returned by a previous request to - /// this endpoint. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub to: Option<&'a str>, + /// The token to stop returning events at. + /// + /// This token can be obtained from a `prev_batch` token returned for each room by the + /// sync endpoint, or from a `start` or `end` token returned by a previous request to + /// this endpoint. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub to: Option<&'a str>, - /// The direction to return events from. - #[ruma_api(query)] - pub dir: Direction, + /// The direction to return events from. + #[ruma_api(query)] + pub dir: Direction, - /// The maximum number of events to return. - /// - /// Default: `10`. - #[ruma_api(query)] - #[serde(default = "default_limit", skip_serializing_if = "is_default_limit")] - pub limit: UInt, + /// The maximum number of events to return. + /// + /// Default: `10`. + #[ruma_api(query)] + #[serde(default = "default_limit", skip_serializing_if = "is_default_limit")] + pub limit: UInt, - /// A [`RoomEventFilter`] to filter returned events with. - #[ruma_api(query)] - #[serde( - with = "ruma_common::serde::json_string", - default, - skip_serializing_if = "RoomEventFilter::is_empty" - )] - pub filter: RoomEventFilter<'a>, - } + /// A [`RoomEventFilter`] to filter returned events with. + #[ruma_api(query)] + #[serde( + with = "ruma_common::serde::json_string", + default, + skip_serializing_if = "RoomEventFilter::is_empty" + )] + pub filter: RoomEventFilter<'a>, + } - #[derive(Default)] - response: { - /// The token the pagination starts from. - pub start: String, + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response { + /// The token the pagination starts from. + pub start: String, - /// The token the pagination ends at. - #[serde(skip_serializing_if = "Option::is_none")] - pub end: Option, + /// The token the pagination ends at. + #[serde(skip_serializing_if = "Option::is_none")] + pub end: Option, - /// A list of room events. - #[serde(default)] - pub chunk: Vec>, + /// A list of room events. + #[serde(default)] + pub chunk: Vec>, - /// A list of state events relevant to showing the `chunk`. - #[serde(default, skip_serializing_if = "Vec::is_empty")] - pub state: Vec>, - } - - error: crate::Error + /// A list of state events relevant to showing the `chunk`. + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub state: Vec>, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/message/send_message_event.rs b/crates/ruma-client-api/src/message/send_message_event.rs index 0bcf0829..fcfd60e3 100644 --- a/crates/ruma-client-api/src/message/send_message_event.rs +++ b/crates/ruma-client-api/src/message/send_message_event.rs @@ -6,68 +6,68 @@ pub mod v3 { //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#put_matrixclientv3roomsroomidsendeventtypetxnid use ruma_common::{ - api::ruma_api, + api::{request, response, Metadata}, events::{AnyMessageLikeEventContent, MessageLikeEventContent, MessageLikeEventType}, + metadata, serde::Raw, MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId, TransactionId, }; use serde_json::value::to_raw_value as to_raw_json_value; - ruma_api! { - metadata: { - description: "Send a message event to a room.", - method: PUT, - name: "create_message_event", - r0_path: "/_matrix/client/r0/rooms/:room_id/send/:event_type/:txn_id", - stable_path: "/_matrix/client/v3/rooms/:room_id/send/:event_type/:txn_id", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Send a message event to a room.", + method: PUT, + name: "create_message_event", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/rooms/:room_id/send/:event_type/:txn_id", + 1.1 => "/_matrix/client/v3/rooms/:room_id/send/:event_type/:txn_id", } + }; - request: { - /// The room to send the event to. - #[ruma_api(path)] - pub room_id: &'a RoomId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The room to send the event to. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The type of event to send. - #[ruma_api(path)] - pub event_type: MessageLikeEventType, + /// The type of event to send. + #[ruma_api(path)] + pub event_type: MessageLikeEventType, - /// The transaction ID for this event. - /// - /// Clients should generate a unique ID across requests within the - /// same session. A session is identified by an access token, and - /// persists when the [access token is refreshed]. - /// - /// It will be used by the server to ensure idempotency of requests. - /// - /// [access token is refreshed]: https://spec.matrix.org/v1.4/client-server-api/#refreshing-access-tokens - #[ruma_api(path)] - pub txn_id: &'a TransactionId, + /// The transaction ID for this event. + /// + /// Clients should generate a unique ID across requests within the + /// same session. A session is identified by an access token, and + /// persists when the [access token is refreshed]. + /// + /// It will be used by the server to ensure idempotency of requests. + /// + /// [access token is refreshed]: https://spec.matrix.org/v1.4/client-server-api/#refreshing-access-tokens + #[ruma_api(path)] + pub txn_id: &'a TransactionId, - /// The event content to send. - #[ruma_api(body)] - pub body: Raw, + /// The event content to send. + #[ruma_api(body)] + pub body: Raw, - /// Timestamp to use for the `origin_server_ts` of the event. - /// - /// This is called [timestamp massaging] and can only be used by Appservices. - /// - /// Note that this does not change the position of the event in the timeline. - /// - /// [timestamp massaging]: https://spec.matrix.org/v1.4/application-service-api/#timestamp-massaging - #[ruma_api(query)] - #[serde(skip_serializing_if = "Option::is_none", rename = "ts")] - pub timestamp: Option, - } + /// Timestamp to use for the `origin_server_ts` of the event. + /// + /// This is called [timestamp massaging] and can only be used by Appservices. + /// + /// Note that this does not change the position of the event in the timeline. + /// + /// [timestamp massaging]: https://spec.matrix.org/v1.4/application-service-api/#timestamp-massaging + #[ruma_api(query)] + #[serde(skip_serializing_if = "Option::is_none", rename = "ts")] + pub timestamp: Option, + } - response: { - /// A unique identifier for the event. - pub event_id: OwnedEventId, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// A unique identifier for the event. + pub event_id: OwnedEventId, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/presence/get_presence.rs b/crates/ruma-client-api/src/presence/get_presence.rs index 94a26444..e755f1c6 100644 --- a/crates/ruma-client-api/src/presence/get_presence.rs +++ b/crates/ruma-client-api/src/presence/get_presence.rs @@ -7,48 +7,52 @@ pub mod v3 { use std::time::Duration; - use ruma_common::{api::ruma_api, presence::PresenceState, UserId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + presence::PresenceState, + UserId, + }; - ruma_api! { - metadata: { - description: "Get presence status for this user.", - method: GET, - name: "get_presence", - r0_path: "/_matrix/client/r0/presence/:user_id/status", - stable_path: "/_matrix/client/v3/presence/:user_id/status", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Get presence status for this user.", + method: GET, + name: "get_presence", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/presence/:user_id/status", + 1.1 => "/_matrix/client/v3/presence/:user_id/status", } + }; - request: { - /// The user whose presence state will be retrieved. - #[ruma_api(path)] - pub user_id: &'a UserId, - } + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The user whose presence state will be retrieved. + #[ruma_api(path)] + pub user_id: &'a UserId, + } - response: { - /// The state message for this user if one was set. - #[serde(skip_serializing_if = "Option::is_none")] - pub status_msg: Option, + #[response(error = crate::Error)] + pub struct Response { + /// The state message for this user if one was set. + #[serde(skip_serializing_if = "Option::is_none")] + pub status_msg: Option, - /// Whether or not the user is currently active. - #[serde(skip_serializing_if = "Option::is_none")] - pub currently_active: Option, + /// Whether or not the user is currently active. + #[serde(skip_serializing_if = "Option::is_none")] + pub currently_active: Option, - /// The length of time in milliseconds since an action was performed by the user. - #[serde( - with = "ruma_common::serde::duration::opt_ms", - default, - skip_serializing_if = "Option::is_none", - )] - pub last_active_ago: Option, + /// The length of time in milliseconds since an action was performed by the user. + #[serde( + with = "ruma_common::serde::duration::opt_ms", + default, + skip_serializing_if = "Option::is_none" + )] + pub last_active_ago: Option, - /// The user's presence state. - pub presence: PresenceState, - } - - error: crate::Error + /// The user's presence state. + pub presence: PresenceState, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/presence/set_presence.rs b/crates/ruma-client-api/src/presence/set_presence.rs index bef1123e..062cfbdb 100644 --- a/crates/ruma-client-api/src/presence/set_presence.rs +++ b/crates/ruma-client-api/src/presence/set_presence.rs @@ -5,39 +5,43 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#put_matrixclientv3presenceuseridstatus - use ruma_common::{api::ruma_api, presence::PresenceState, UserId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + presence::PresenceState, + UserId, + }; - ruma_api! { - metadata: { - description: "Set presence status for this user.", - method: PUT, - name: "set_presence", - r0_path: "/_matrix/client/r0/presence/:user_id/status", - stable_path: "/_matrix/client/v3/presence/:user_id/status", - rate_limited: true, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Set presence status for this user.", + method: PUT, + name: "set_presence", + rate_limited: true, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/presence/:user_id/status", + 1.1 => "/_matrix/client/v3/presence/:user_id/status", } + }; - request: { - /// The user whose presence state will be updated. - #[ruma_api(path)] - pub user_id: &'a UserId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The user whose presence state will be updated. + #[ruma_api(path)] + pub user_id: &'a UserId, - /// The new presence state. - pub presence: PresenceState, + /// The new presence state. + pub presence: PresenceState, - /// The status message to attach to this state. - #[serde(skip_serializing_if = "Option::is_none")] - pub status_msg: Option<&'a str>, - } - - #[derive(Default)] - response: {} - - error: crate::Error + /// The status message to attach to this state. + #[serde(skip_serializing_if = "Option::is_none")] + pub status_msg: Option<&'a str>, } + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given user ID and presence state. pub fn new(user_id: &'a UserId, presence: PresenceState) -> Self { diff --git a/crates/ruma-client-api/src/profile/get_avatar_url.rs b/crates/ruma-client-api/src/profile/get_avatar_url.rs index 76df0c35..4009c2ff 100644 --- a/crates/ruma-client-api/src/profile/get_avatar_url.rs +++ b/crates/ruma-client-api/src/profile/get_avatar_url.rs @@ -5,49 +5,51 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3profileuseridavatar_url - use ruma_common::{api::ruma_api, OwnedMxcUri, UserId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, OwnedMxcUri, UserId, + }; - ruma_api! { - metadata: { - description: "Get the avatar URL of a user.", - method: GET, - name: "get_avatar_url", - r0_path: "/_matrix/client/r0/profile/:user_id/avatar_url", - stable_path: "/_matrix/client/v3/profile/:user_id/avatar_url", - rate_limited: false, - authentication: None, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Get the avatar URL of a user.", + method: GET, + name: "get_avatar_url", + rate_limited: false, + authentication: None, + history: { + 1.0 => "/_matrix/client/r0/profile/:user_id/avatar_url", + 1.1 => "/_matrix/client/v3/profile/:user_id/avatar_url", } + }; - request: { - /// The user whose avatar URL will be retrieved. - #[ruma_api(path)] - pub user_id: &'a UserId, - } + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The user whose avatar URL will be retrieved. + #[ruma_api(path)] + pub user_id: &'a UserId, + } - #[derive(Default)] - response: { - /// The user's avatar URL, if set. - /// - /// If you activate the `compat` feature, this field being an empty string in JSON will result - /// in `None` here during deserialization. - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr( - feature = "compat", - serde(default, deserialize_with = "ruma_common::serde::empty_string_as_none") - )] - pub avatar_url: Option, + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response { + /// The user's avatar URL, if set. + /// + /// If you activate the `compat` feature, this field being an empty string in JSON will + /// result in `None` here during deserialization. + #[serde(skip_serializing_if = "Option::is_none")] + #[cfg_attr( + feature = "compat", + serde(default, deserialize_with = "ruma_common::serde::empty_string_as_none") + )] + pub avatar_url: Option, - /// The [BlurHash](https://blurha.sh) for the avatar pointed to by `avatar_url`. - /// - /// This uses the unstable prefix in - /// [MSC2448](https://github.com/matrix-org/matrix-spec-proposals/pull/2448). - #[cfg(feature = "unstable-msc2448")] - #[serde(rename = "xyz.amorgan.blurhash", skip_serializing_if = "Option::is_none")] - pub blurhash: Option, - } - - error: crate::Error + /// The [BlurHash](https://blurha.sh) for the avatar pointed to by `avatar_url`. + /// + /// This uses the unstable prefix in + /// [MSC2448](https://github.com/matrix-org/matrix-spec-proposals/pull/2448). + #[cfg(feature = "unstable-msc2448")] + #[serde(rename = "xyz.amorgan.blurhash", skip_serializing_if = "Option::is_none")] + pub blurhash: Option, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/profile/get_display_name.rs b/crates/ruma-client-api/src/profile/get_display_name.rs index d2cf32a0..e6916cec 100644 --- a/crates/ruma-client-api/src/profile/get_display_name.rs +++ b/crates/ruma-client-api/src/profile/get_display_name.rs @@ -5,34 +5,36 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3profileuseriddisplayname - use ruma_common::{api::ruma_api, UserId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, UserId, + }; - ruma_api! { - metadata: { - description: "Get the display name of a user.", - method: GET, - name: "get_display_name", - r0_path: "/_matrix/client/r0/profile/:user_id/displayname", - stable_path: "/_matrix/client/v3/profile/:user_id/displayname", - rate_limited: false, - authentication: None, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Get the display name of a user.", + method: GET, + name: "get_display_name", + rate_limited: false, + authentication: None, + history: { + 1.0 => "/_matrix/client/r0/profile/:user_id/displayname", + 1.1 => "/_matrix/client/v3/profile/:user_id/displayname", } + }; - request: { - /// The user whose display name will be retrieved. - #[ruma_api(path)] - pub user_id: &'a UserId, - } + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The user whose display name will be retrieved. + #[ruma_api(path)] + pub user_id: &'a UserId, + } - #[derive(Default)] - response: { - /// The user's display name, if set. - #[serde(skip_serializing_if = "Option::is_none")] - pub displayname: Option, - } - - error: crate::Error + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response { + /// The user's display name, if set. + #[serde(skip_serializing_if = "Option::is_none")] + pub displayname: Option, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/profile/get_profile.rs b/crates/ruma-client-api/src/profile/get_profile.rs index 94699fb2..6154f507 100644 --- a/crates/ruma-client-api/src/profile/get_profile.rs +++ b/crates/ruma-client-api/src/profile/get_profile.rs @@ -5,53 +5,55 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3profileuserid - use ruma_common::{api::ruma_api, OwnedMxcUri, UserId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, OwnedMxcUri, UserId, + }; - ruma_api! { - metadata: { - description: "Get all profile information of an user.", - method: GET, - name: "get_profile", - r0_path: "/_matrix/client/r0/profile/:user_id", - stable_path: "/_matrix/client/v3/profile/:user_id", - rate_limited: false, - authentication: None, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Get all profile information of an user.", + method: GET, + name: "get_profile", + rate_limited: false, + authentication: None, + history: { + 1.0 => "/_matrix/client/r0/profile/:user_id", + 1.1 => "/_matrix/client/v3/profile/:user_id", } + }; - request: { - /// The user whose profile will be retrieved. - #[ruma_api(path)] - pub user_id: &'a UserId, - } + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The user whose profile will be retrieved. + #[ruma_api(path)] + pub user_id: &'a UserId, + } - #[derive(Default)] - response: { - /// The user's avatar URL, if set. - /// - /// If you activate the `compat` feature, this field being an empty string in JSON will result - /// in `None` here during deserialization. - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr( - feature = "compat", - serde(default, deserialize_with = "ruma_common::serde::empty_string_as_none") - )] - pub avatar_url: Option, + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response { + /// The user's avatar URL, if set. + /// + /// If you activate the `compat` feature, this field being an empty string in JSON will + /// result in `None` here during deserialization. + #[serde(skip_serializing_if = "Option::is_none")] + #[cfg_attr( + feature = "compat", + serde(default, deserialize_with = "ruma_common::serde::empty_string_as_none") + )] + pub avatar_url: Option, - /// The user's display name, if set. - #[serde(skip_serializing_if = "Option::is_none")] - pub displayname: Option, + /// The user's display name, if set. + #[serde(skip_serializing_if = "Option::is_none")] + pub displayname: Option, - /// The [BlurHash](https://blurha.sh) for the avatar pointed to by `avatar_url`. - /// - /// This uses the unstable prefix in - /// [MSC2448](https://github.com/matrix-org/matrix-spec-proposals/pull/2448). - #[cfg(feature = "unstable-msc2448")] - #[serde(rename = "xyz.amorgan.blurhash", skip_serializing_if = "Option::is_none")] - pub blurhash: Option, - } - - error: crate::Error + /// The [BlurHash](https://blurha.sh) for the avatar pointed to by `avatar_url`. + /// + /// This uses the unstable prefix in + /// [MSC2448](https://github.com/matrix-org/matrix-spec-proposals/pull/2448). + #[cfg(feature = "unstable-msc2448")] + #[serde(rename = "xyz.amorgan.blurhash", skip_serializing_if = "Option::is_none")] + pub blurhash: Option, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/profile/set_avatar_url.rs b/crates/ruma-client-api/src/profile/set_avatar_url.rs index 7505808b..ad180631 100644 --- a/crates/ruma-client-api/src/profile/set_avatar_url.rs +++ b/crates/ruma-client-api/src/profile/set_avatar_url.rs @@ -5,60 +5,59 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#put_matrixclientv3profileuseridavatar_url - use ruma_common::{api::ruma_api, MxcUri, UserId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, MxcUri, UserId, + }; - ruma_api! { - metadata: { - description: "Set the avatar URL of the user.", - method: PUT, - name: "set_avatar_url", - r0_path: "/_matrix/client/r0/profile/:user_id/avatar_url", - stable_path: "/_matrix/client/v3/profile/:user_id/avatar_url", - rate_limited: true, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Set the avatar URL of the user.", + method: PUT, + name: "set_avatar_url", + rate_limited: true, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/profile/:user_id/avatar_url", + 1.1 => "/_matrix/client/v3/profile/:user_id/avatar_url", } + }; - request: { - /// The user whose avatar URL will be set. - #[ruma_api(path)] - pub user_id: &'a UserId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The user whose avatar URL will be set. + #[ruma_api(path)] + pub user_id: &'a UserId, - /// The new avatar URL for the user. - /// - /// `None` is used to unset the avatar. - /// - /// If you activate the `compat` feature, this field being an empty string in JSON will result - /// in `None` here during deserialization. - #[cfg_attr( - feature = "compat", - serde( - default, - deserialize_with = "ruma_common::serde::empty_string_as_none", - serialize_with = "ruma_common::serde::none_as_empty_string" - ) - )] - #[cfg_attr( - not(feature = "compat"), - serde(skip_serializing_if = "Option::is_none") - )] - pub avatar_url: Option<&'a MxcUri>, + /// The new avatar URL for the user. + /// + /// `None` is used to unset the avatar. + /// + /// If you activate the `compat` feature, this field being an empty string in JSON will + /// result in `None` here during deserialization. + #[cfg_attr( + feature = "compat", + serde( + default, + deserialize_with = "ruma_common::serde::empty_string_as_none", + serialize_with = "ruma_common::serde::none_as_empty_string" + ) + )] + #[cfg_attr(not(feature = "compat"), serde(skip_serializing_if = "Option::is_none"))] + pub avatar_url: Option<&'a MxcUri>, - /// The [BlurHash](https://blurha.sh) for the avatar pointed to by `avatar_url`. - /// - /// This uses the unstable prefix in - /// [MSC2448](https://github.com/matrix-org/matrix-spec-proposals/pull/2448). - #[cfg(feature = "unstable-msc2448")] - #[serde(rename = "xyz.amorgan.blurhash", skip_serializing_if = "Option::is_none")] - pub blurhash: Option<&'a str>, - } - - #[derive(Default)] - response: {} - - error: crate::Error + /// The [BlurHash](https://blurha.sh) for the avatar pointed to by `avatar_url`. + /// + /// This uses the unstable prefix in + /// [MSC2448](https://github.com/matrix-org/matrix-spec-proposals/pull/2448). + #[cfg(feature = "unstable-msc2448")] + #[serde(rename = "xyz.amorgan.blurhash", skip_serializing_if = "Option::is_none")] + pub blurhash: Option<&'a str>, } + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given user ID and avatar URL. pub fn new(user_id: &'a UserId, avatar_url: Option<&'a MxcUri>) -> Self { diff --git a/crates/ruma-client-api/src/profile/set_display_name.rs b/crates/ruma-client-api/src/profile/set_display_name.rs index 7f3e452e..335dc83a 100644 --- a/crates/ruma-client-api/src/profile/set_display_name.rs +++ b/crates/ruma-client-api/src/profile/set_display_name.rs @@ -5,36 +5,38 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#put_matrixclientv3profileuseriddisplayname - use ruma_common::{api::ruma_api, UserId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, UserId, + }; - ruma_api! { - metadata: { - description: "Set the display name of the user.", - method: PUT, - name: "set_display_name", - r0_path: "/_matrix/client/r0/profile/:user_id/displayname", - stable_path: "/_matrix/client/v3/profile/:user_id/displayname", - rate_limited: true, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Set the display name of the user.", + method: PUT, + name: "set_display_name", + rate_limited: true, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/profile/:user_id/displayname", + 1.1 => "/_matrix/client/v3/profile/:user_id/displayname", } + }; - request: { - /// The user whose display name will be set. - #[ruma_api(path)] - pub user_id: &'a UserId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The user whose display name will be set. + #[ruma_api(path)] + pub user_id: &'a UserId, - /// The new display name for the user. - #[serde(skip_serializing_if = "Option::is_none")] - pub displayname: Option<&'a str>, - } - - #[derive(Default)] - response: {} - - error: crate::Error + /// The new display name for the user. + #[serde(skip_serializing_if = "Option::is_none")] + pub displayname: Option<&'a str>, } + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given user ID and display name. pub fn new(user_id: &'a UserId, displayname: Option<&'a str>) -> Self { diff --git a/crates/ruma-client-api/src/push/delete_pushrule.rs b/crates/ruma-client-api/src/push/delete_pushrule.rs index 581ee0c9..693582e6 100644 --- a/crates/ruma-client-api/src/push/delete_pushrule.rs +++ b/crates/ruma-client-api/src/push/delete_pushrule.rs @@ -5,42 +5,44 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#delete_matrixclientv3pushrulesscopekindruleid - use ruma_common::api::ruma_api; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + }; use crate::push::{RuleKind, RuleScope}; - ruma_api! { - metadata: { - description: "This endpoint removes the push rule defined in the path.", - method: DELETE, - name: "delete_pushrule", - r0_path: "/_matrix/client/r0/pushrules/:scope/:kind/:rule_id", - stable_path: "/_matrix/client/v3/pushrules/:scope/:kind/:rule_id", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "This endpoint removes the push rule defined in the path.", + method: DELETE, + name: "delete_pushrule", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/pushrules/:scope/:kind/:rule_id", + 1.1 => "/_matrix/client/v3/pushrules/:scope/:kind/:rule_id", } + }; - request: { - /// The scope to delete from. - #[ruma_api(path)] - pub scope: RuleScope, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The scope to delete from. + #[ruma_api(path)] + pub scope: RuleScope, - /// The kind of rule - #[ruma_api(path)] - pub kind: RuleKind, + /// The kind of rule + #[ruma_api(path)] + pub kind: RuleKind, - /// The identifier for the rule. - #[ruma_api(path)] - pub rule_id: &'a str, - } - - #[derive(Default)] - response: {} - - error: crate::Error + /// The identifier for the rule. + #[ruma_api(path)] + pub rule_id: &'a str, } + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given scope, kind and rule ID. pub fn new(scope: RuleScope, kind: RuleKind, rule_id: &'a str) -> Self { diff --git a/crates/ruma-client-api/src/push/get_notifications.rs b/crates/ruma-client-api/src/push/get_notifications.rs index 1378a972..9218ed24 100644 --- a/crates/ruma-client-api/src/push/get_notifications.rs +++ b/crates/ruma-client-api/src/push/get_notifications.rs @@ -7,58 +7,60 @@ pub mod v3 { use js_int::UInt; use ruma_common::{ - api::ruma_api, events::AnySyncTimelineEvent, push::Action, serde::Raw, + api::{request, response, Metadata}, + events::AnySyncTimelineEvent, + metadata, + push::Action, + serde::Raw, MilliSecondsSinceUnixEpoch, OwnedRoomId, }; use serde::{Deserialize, Serialize}; - ruma_api! { - metadata: { - description: "Paginate through the list of events that the user has been, or would have been notified about.", - method: GET, - name: "get_notifications", - r0_path: "/_matrix/client/r0/notifications", - stable_path: "/_matrix/client/v3/notifications", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Paginate through the list of events that the user has been, or would have been notified about.", + method: GET, + name: "get_notifications", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/notifications", + 1.1 => "/_matrix/client/v3/notifications", } + }; - #[derive(Default)] - request: { - /// Pagination token given to retrieve the next set of events. - #[ruma_api(query)] - #[serde(skip_serializing_if = "Option::is_none")] - pub from: Option<&'a str>, + #[request(error = crate::Error)] + #[derive(Default)] + pub struct Request<'a> { + /// Pagination token given to retrieve the next set of events. + #[ruma_api(query)] + #[serde(skip_serializing_if = "Option::is_none")] + pub from: Option<&'a str>, - /// Limit on the number of events to return in this request. - #[ruma_api(query)] - #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + /// Limit on the number of events to return in this request. + #[ruma_api(query)] + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, - /// Allows basic filtering of events returned. - /// - /// Supply "highlight" to return only events where the notification had the 'highlight' - /// tweak set. - #[ruma_api(query)] - #[serde(skip_serializing_if = "Option::is_none")] - pub only: Option<&'a str>, - } + /// Allows basic filtering of events returned. + /// + /// Supply "highlight" to return only events where the notification had the 'highlight' + /// tweak set. + #[ruma_api(query)] + #[serde(skip_serializing_if = "Option::is_none")] + pub only: Option<&'a str>, + } - response: { - /// The token to supply in the from param of the next /notifications request in order to - /// request more events. - /// - /// If this is absent, there are no more results. - #[serde(skip_serializing_if = "Option::is_none")] - pub next_token: Option, + #[response(error = crate::Error)] + pub struct Response { + /// The token to supply in the from param of the next /notifications request in order to + /// request more events. + /// + /// If this is absent, there are no more results. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_token: Option, - - /// The list of events that triggered notifications. - pub notifications: Vec, - } - - error: crate::Error + /// The list of events that triggered notifications. + pub notifications: Vec, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/push/get_pushers.rs b/crates/ruma-client-api/src/push/get_pushers.rs index e78616c1..938932b7 100644 --- a/crates/ruma-client-api/src/push/get_pushers.rs +++ b/crates/ruma-client-api/src/push/get_pushers.rs @@ -5,31 +5,33 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3pushers - use ruma_common::api::ruma_api; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + }; use crate::push::Pusher; - ruma_api! { - metadata: { - description: "Gets all currently active pushers for the authenticated user.", - method: GET, - name: "get_pushers", - r0_path: "/_matrix/client/r0/pushers", - stable_path: "/_matrix/client/v3/pushers", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Gets all currently active pushers for the authenticated user.", + method: GET, + name: "get_pushers", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/pushers", + 1.1 => "/_matrix/client/v3/pushers", } + }; - #[derive(Default)] - request: {} + #[request(error = crate::Error)] + #[derive(Default)] + pub struct Request {} - response: { - /// An array containing the current pushers for the user. - pub pushers: Vec, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// An array containing the current pushers for the user. + pub pushers: Vec, } impl Request { diff --git a/crates/ruma-client-api/src/push/get_pushrule.rs b/crates/ruma-client-api/src/push/get_pushrule.rs index b601c1e9..20c2a454 100644 --- a/crates/ruma-client-api/src/push/get_pushrule.rs +++ b/crates/ruma-client-api/src/push/get_pushrule.rs @@ -5,43 +5,45 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3pushrulesscopekindruleid - use ruma_common::api::ruma_api; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + }; use crate::push::{PushRule, RuleKind, RuleScope}; - ruma_api! { - metadata: { - description: "Retrieve a single specified push rule.", - method: GET, - name: "get_pushrule", - r0_path: "/_matrix/client/r0/pushrules/:scope/:kind/:rule_id", - stable_path: "/_matrix/client/v3/pushrules/:scope/:kind/:rule_id", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Retrieve a single specified push rule.", + method: GET, + name: "get_pushrule", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/pushrules/:scope/:kind/:rule_id", + 1.1 => "/_matrix/client/v3/pushrules/:scope/:kind/:rule_id", } + }; - request: { - /// The scope to fetch rules from. - #[ruma_api(path)] - pub scope: RuleScope, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The scope to fetch rules from. + #[ruma_api(path)] + pub scope: RuleScope, - /// The kind of rule. - #[ruma_api(path)] - pub kind: RuleKind, + /// The kind of rule. + #[ruma_api(path)] + pub kind: RuleKind, - /// The identifier for the rule. - #[ruma_api(path)] - pub rule_id: &'a str, - } + /// The identifier for the rule. + #[ruma_api(path)] + pub rule_id: &'a str, + } - response: { - /// The specific push rule. - #[ruma_api(body)] - pub rule: PushRule, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// The specific push rule. + #[ruma_api(body)] + pub rule: PushRule, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/push/get_pushrule_actions.rs b/crates/ruma-client-api/src/push/get_pushrule_actions.rs index 80cbf343..87d796e8 100644 --- a/crates/ruma-client-api/src/push/get_pushrule_actions.rs +++ b/crates/ruma-client-api/src/push/get_pushrule_actions.rs @@ -5,42 +5,45 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3pushrulesscopekindruleidactions - use ruma_common::{api::ruma_api, push::Action}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + push::Action, + }; use crate::push::{RuleKind, RuleScope}; - ruma_api! { - metadata: { - description: "This endpoint get the actions for the specified push rule.", - method: GET, - name: "get_pushrule_actions", - r0_path: "/_matrix/client/r0/pushrules/:scope/:kind/:rule_id/actions", - stable_path: "/_matrix/client/v3/pushrules/:scope/:kind/:rule_id/actions", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "This endpoint get the actions for the specified push rule.", + method: GET, + name: "get_pushrule_actions", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/pushrules/:scope/:kind/:rule_id/actions", + 1.1 => "/_matrix/client/v3/pushrules/:scope/:kind/:rule_id/actions", } + }; - request: { - /// The scope to fetch a rule from. - #[ruma_api(path)] - pub scope: RuleScope, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The scope to fetch a rule from. + #[ruma_api(path)] + pub scope: RuleScope, - /// The kind of rule - #[ruma_api(path)] - pub kind: RuleKind, + /// The kind of rule + #[ruma_api(path)] + pub kind: RuleKind, - /// The identifier for the rule. - #[ruma_api(path)] - pub rule_id: &'a str, - } + /// The identifier for the rule. + #[ruma_api(path)] + pub rule_id: &'a str, + } - response: { - /// The actions to perform for this rule. - pub actions: Vec, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// The actions to perform for this rule. + pub actions: Vec, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/push/get_pushrule_enabled.rs b/crates/ruma-client-api/src/push/get_pushrule_enabled.rs index 99d2a2e1..685f2893 100644 --- a/crates/ruma-client-api/src/push/get_pushrule_enabled.rs +++ b/crates/ruma-client-api/src/push/get_pushrule_enabled.rs @@ -5,42 +5,44 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3pushrulesscopekindruleidenabled - use ruma_common::api::ruma_api; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + }; use crate::push::{RuleKind, RuleScope}; - ruma_api! { - metadata: { - description: "This endpoint gets whether the specified push rule is enabled.", - method: GET, - name: "get_pushrule_enabled", - r0_path: "/_matrix/client/r0/pushrules/:scope/:kind/:rule_id/enabled", - stable_path: "/_matrix/client/v3/pushrules/:scope/:kind/:rule_id/enabled", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "This endpoint gets whether the specified push rule is enabled.", + method: GET, + name: "get_pushrule_enabled", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/pushrules/:scope/:kind/:rule_id/enabled", + 1.1 => "/_matrix/client/v3/pushrules/:scope/:kind/:rule_id/enabled", } + }; - request: { - /// The scope to fetch a rule from. - #[ruma_api(path)] - pub scope: RuleScope, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The scope to fetch a rule from. + #[ruma_api(path)] + pub scope: RuleScope, - /// The kind of rule - #[ruma_api(path)] - pub kind: RuleKind, + /// The kind of rule + #[ruma_api(path)] + pub kind: RuleKind, - /// The identifier for the rule. - #[ruma_api(path)] - pub rule_id: &'a str, - } + /// The identifier for the rule. + #[ruma_api(path)] + pub rule_id: &'a str, + } - response: { - /// Whether the push rule is enabled or not. - pub enabled: bool, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// Whether the push rule is enabled or not. + pub enabled: bool, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/push/get_pushrules_all.rs b/crates/ruma-client-api/src/push/get_pushrules_all.rs index c3985001..a1ad0d12 100644 --- a/crates/ruma-client-api/src/push/get_pushrules_all.rs +++ b/crates/ruma-client-api/src/push/get_pushrules_all.rs @@ -5,29 +5,32 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3pushrules - use ruma_common::{api::ruma_api, push::Ruleset}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + push::Ruleset, + }; - ruma_api! { - metadata: { - description: "Retrieve all push rulesets for this user.", - method: GET, - name: "get_pushrules_all", - r0_path: "/_matrix/client/r0/pushrules/", - stable_path: "/_matrix/client/v3/pushrules/", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Retrieve all push rulesets for this user.", + method: GET, + name: "get_pushrules_all", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/pushrules/", + 1.1 => "/_matrix/client/v3/pushrules/", } + }; - #[derive(Default)] - request: {} + #[request(error = crate::Error)] + #[derive(Default)] + pub struct Request {} - response: { - /// The global ruleset. - pub global: Ruleset, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// The global ruleset. + pub global: Ruleset, } impl Request { diff --git a/crates/ruma-client-api/src/push/get_pushrules_global_scope.rs b/crates/ruma-client-api/src/push/get_pushrules_global_scope.rs index 9aeb18c9..827908ef 100644 --- a/crates/ruma-client-api/src/push/get_pushrules_global_scope.rs +++ b/crates/ruma-client-api/src/push/get_pushrules_global_scope.rs @@ -5,30 +5,33 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3pushrules - use ruma_common::{api::ruma_api, push::Ruleset}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + push::Ruleset, + }; - ruma_api! { - metadata: { - description: "Retrieve all push rulesets in the global scope for this user.", - method: GET, - name: "get_pushrules_global_scope", - r0_path: "/_matrix/client/r0/pushrules/global/", - stable_path: "/_matrix/client/v3/pushrules/global/", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Retrieve all push rulesets in the global scope for this user.", + method: GET, + name: "get_pushrules_global_scope", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/pushrules/global/", + 1.1 => "/_matrix/client/v3/pushrules/global/", } + }; - #[derive(Default)] - request: {} + #[request(error = crate::Error)] + #[derive(Default)] + pub struct Request {} - response: { - /// The global ruleset. - #[ruma_api(body)] - pub global: Ruleset, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// The global ruleset. + #[ruma_api(body)] + pub global: Ruleset, } impl Request { diff --git a/crates/ruma-client-api/src/push/set_pusher.rs b/crates/ruma-client-api/src/push/set_pusher.rs index fe567db4..d1401c52 100644 --- a/crates/ruma-client-api/src/push/set_pusher.rs +++ b/crates/ruma-client-api/src/push/set_pusher.rs @@ -7,35 +7,37 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#post_matrixclientv3pushersset - use ruma_common::api::ruma_api; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + }; use serde::Serialize; use crate::push::{Pusher, PusherIds}; - ruma_api! { - metadata: { - description: "This endpoint allows the creation, modification and deletion of pushers for this user ID.", - method: POST, - name: "set_pusher", - r0_path: "/_matrix/client/r0/pushers/set", - stable_path: "/_matrix/client/v3/pushers/set", - rate_limited: true, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "This endpoint allows the creation, modification and deletion of pushers for this user ID.", + method: POST, + name: "set_pusher", + rate_limited: true, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/pushers/set", + 1.1 => "/_matrix/client/v3/pushers/set", } + }; - request: { - /// The action to take. - #[ruma_api(body)] - pub action: PusherAction, - } - - #[derive(Default)] - response: {} - - error: crate::Error + #[request(error = crate::Error)] + pub struct Request { + /// The action to take. + #[ruma_api(body)] + pub action: PusherAction, } + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response {} + impl Request { /// Creates a new `Request` for the given action. pub fn new(action: PusherAction) -> Self { diff --git a/crates/ruma-client-api/src/push/set_pushrule.rs b/crates/ruma-client-api/src/push/set_pushrule.rs index e40920ec..4be5ded7 100644 --- a/crates/ruma-client-api/src/push/set_pushrule.rs +++ b/crates/ruma-client-api/src/push/set_pushrule.rs @@ -6,7 +6,8 @@ pub mod v3 { //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#put_matrixclientv3pushrulesscopekindruleid use ruma_common::{ - api::ruma_api, + api::{response, Metadata}, + metadata, push::{Action, NewPushRule, PushCondition}, serde::Incoming, }; @@ -14,23 +15,17 @@ pub mod v3 { use crate::push::RuleScope; - ruma_api! { - metadata: { - description: "This endpoint allows the creation and modification of push rules for this user ID.", - method: PUT, - name: "set_pushrule", - r0_path: "/_matrix/client/r0/pushrules/:scope/:kind/:rule_id", - stable_path: "/_matrix/client/v3/pushrules/:scope/:kind/:rule_id", - rate_limited: true, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "This endpoint allows the creation and modification of push rules for this user ID.", + method: PUT, + name: "set_pushrule", + rate_limited: true, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/pushrules/:scope/:kind/:rule_id", + 1.1 => "/_matrix/client/v3/pushrules/:scope/:kind/:rule_id", } - - #[derive(Default)] - response: {} - - error: crate::Error - } + }; /// Data for a request to the `set_pushrule` API endpoint. /// @@ -54,6 +49,10 @@ pub mod v3 { pub after: Option<&'a str>, } + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given scope and rule. pub fn new(scope: RuleScope, rule: NewPushRule) -> Self { @@ -73,7 +72,7 @@ pub mod v3 { type EndpointError = crate::Error; type IncomingResponse = Response; - const METADATA: ruma_common::api::Metadata = METADATA; + const METADATA: Metadata = METADATA; fn try_into_http_request( self, @@ -119,7 +118,7 @@ pub mod v3 { type EndpointError = crate::Error; type OutgoingResponse = Response; - const METADATA: ruma_common::api::Metadata = METADATA; + const METADATA: Metadata = METADATA; fn try_from_http_request( request: http::Request, diff --git a/crates/ruma-client-api/src/push/set_pushrule_actions.rs b/crates/ruma-client-api/src/push/set_pushrule_actions.rs index f25bbfad..1b146a07 100644 --- a/crates/ruma-client-api/src/push/set_pushrule_actions.rs +++ b/crates/ruma-client-api/src/push/set_pushrule_actions.rs @@ -5,45 +5,48 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#put_matrixclientv3pushrulesscopekindruleidactions - use ruma_common::{api::ruma_api, push::Action}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + push::Action, + }; use crate::push::{RuleKind, RuleScope}; - ruma_api! { - metadata: { - description: "This endpoint allows clients to change the actions of a push rule. This can be used to change the actions of builtin rules.", - method: PUT, - name: "set_pushrule_actions", - r0_path: "/_matrix/client/r0/pushrules/:scope/:kind/:rule_id/actions", - stable_path: "/_matrix/client/v3/pushrules/:scope/:kind/:rule_id/actions", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "This endpoint allows clients to change the actions of a push rule. This can be used to change the actions of builtin rules.", + method: PUT, + name: "set_pushrule_actions", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/pushrules/:scope/:kind/:rule_id/actions", + 1.1 => "/_matrix/client/v3/pushrules/:scope/:kind/:rule_id/actions", } + }; - request: { - /// The scope to fetch a rule from. - #[ruma_api(path)] - pub scope: RuleScope, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The scope to fetch a rule from. + #[ruma_api(path)] + pub scope: RuleScope, - /// The kind of rule - #[ruma_api(path)] - pub kind: RuleKind, + /// The kind of rule + #[ruma_api(path)] + pub kind: RuleKind, - /// The identifier for the rule. - #[ruma_api(path)] - pub rule_id: &'a str, + /// The identifier for the rule. + #[ruma_api(path)] + pub rule_id: &'a str, - /// The actions to perform for this rule - pub actions: Vec, - } - - #[derive(Default)] - response: {} - - error: crate::Error + /// The actions to perform for this rule + pub actions: Vec, } + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given scope, rule kind, rule ID and actions. pub fn new( diff --git a/crates/ruma-client-api/src/push/set_pushrule_enabled.rs b/crates/ruma-client-api/src/push/set_pushrule_enabled.rs index fab8f115..2d0e773c 100644 --- a/crates/ruma-client-api/src/push/set_pushrule_enabled.rs +++ b/crates/ruma-client-api/src/push/set_pushrule_enabled.rs @@ -5,45 +5,47 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#put_matrixclientv3pushrulesscopekindruleidenabled - use ruma_common::api::ruma_api; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + }; use crate::push::{RuleKind, RuleScope}; - ruma_api! { - metadata: { - description: "This endpoint allows clients to enable or disable the specified push rule.", - method: PUT, - name: "set_pushrule_enabled", - r0_path: "/_matrix/client/r0/pushrules/:scope/:kind/:rule_id/enabled", - stable_path: "/_matrix/client/v3/pushrules/:scope/:kind/:rule_id/enabled", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "This endpoint allows clients to enable or disable the specified push rule.", + method: PUT, + name: "set_pushrule_enabled", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/pushrules/:scope/:kind/:rule_id/enabled", + 1.1 => "/_matrix/client/v3/pushrules/:scope/:kind/:rule_id/enabled", } + }; - request: { - /// The scope to fetch a rule from. - #[ruma_api(path)] - pub scope: RuleScope, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The scope to fetch a rule from. + #[ruma_api(path)] + pub scope: RuleScope, - /// The kind of rule - #[ruma_api(path)] - pub kind: RuleKind, + /// The kind of rule + #[ruma_api(path)] + pub kind: RuleKind, - /// The identifier for the rule. - #[ruma_api(path)] - pub rule_id: &'a str, + /// The identifier for the rule. + #[ruma_api(path)] + pub rule_id: &'a str, - /// Whether the push rule is enabled or not. - pub enabled: bool, - } - - #[derive(Default)] - response: {} - - error: crate::Error + /// Whether the push rule is enabled or not. + pub enabled: bool, } + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given scope, rule kind, rule ID and enabled flag. pub fn new(scope: RuleScope, kind: RuleKind, rule_id: &'a str, enabled: bool) -> Self { diff --git a/crates/ruma-client-api/src/read_marker/set_read_marker.rs b/crates/ruma-client-api/src/read_marker/set_read_marker.rs index ad33a5fe..4319a6d2 100644 --- a/crates/ruma-client-api/src/read_marker/set_read_marker.rs +++ b/crates/ruma-client-api/src/read_marker/set_read_marker.rs @@ -9,64 +9,66 @@ pub mod v3 { //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#post_matrixclientv3roomsroomidread_markers //! [`create_receipt`]: crate::receipt::create_receipt - use ruma_common::{api::ruma_api, EventId, RoomId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, EventId, RoomId, + }; - ruma_api! { - metadata: { - description: "Sets the position of the read marker for a given room, and optionally the read receipt's location.", - method: POST, - name: "set_read_marker", - r0_path: "/_matrix/client/r0/rooms/:room_id/read_markers", - stable_path: "/_matrix/client/v3/rooms/:room_id/read_markers", - rate_limited: true, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Sets the position of the read marker for a given room, and optionally the read receipt's location.", + method: POST, + name: "set_read_marker", + rate_limited: true, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/rooms/:room_id/read_markers", + 1.1 => "/_matrix/client/v3/rooms/:room_id/read_markers", } + }; - request: { - /// The room ID to set the read marker in for the user. - #[ruma_api(path)] - pub room_id: &'a RoomId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The room ID to set the read marker in for the user. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The event ID the fully-read marker should be located at. - /// - /// The event MUST belong to the room. - /// - /// This is equivalent to calling the [`create_receipt`] endpoint with a - /// [`ReceiptType::FullyRead`]. - /// - /// [`create_receipt`]: crate::receipt::create_receipt - /// [`ReceiptType::FullyRead`]: crate::receipt::create_receipt::v3::ReceiptType::FullyRead - #[serde(rename = "m.fully_read", skip_serializing_if = "Option::is_none")] - pub fully_read: Option<&'a EventId>, + /// The event ID the fully-read marker should be located at. + /// + /// The event MUST belong to the room. + /// + /// This is equivalent to calling the [`create_receipt`] endpoint with a + /// [`ReceiptType::FullyRead`]. + /// + /// [`create_receipt`]: crate::receipt::create_receipt + /// [`ReceiptType::FullyRead`]: crate::receipt::create_receipt::v3::ReceiptType::FullyRead + #[serde(rename = "m.fully_read", skip_serializing_if = "Option::is_none")] + pub fully_read: Option<&'a EventId>, - /// The event ID to set the public read receipt location at. - /// - /// This is equivalent to calling the [`create_receipt`] endpoint with a - /// [`ReceiptType::Read`]. - /// - /// [`create_receipt`]: crate::receipt::create_receipt - /// [`ReceiptType::Read`]: crate::receipt::create_receipt::v3::ReceiptType::Read - #[serde(rename = "m.read", skip_serializing_if = "Option::is_none")] - pub read_receipt: Option<&'a EventId>, + /// The event ID to set the public read receipt location at. + /// + /// This is equivalent to calling the [`create_receipt`] endpoint with a + /// [`ReceiptType::Read`]. + /// + /// [`create_receipt`]: crate::receipt::create_receipt + /// [`ReceiptType::Read`]: crate::receipt::create_receipt::v3::ReceiptType::Read + #[serde(rename = "m.read", skip_serializing_if = "Option::is_none")] + pub read_receipt: Option<&'a EventId>, - /// The event ID to set the private read receipt location at. - /// - /// This is equivalent to calling the [`create_receipt`] endpoint with a - /// [`ReceiptType::ReadPrivate`]. - /// - /// [`create_receipt`]: crate::receipt::create_receipt - /// [`ReceiptType::ReadPrivate`]: crate::receipt::create_receipt::v3::ReceiptType::ReadPrivate - #[serde(rename = "m.read.private", skip_serializing_if = "Option::is_none")] - pub private_read_receipt: Option<&'a EventId>, - } - - #[derive(Default)] - response: {} - - error: crate::Error + /// The event ID to set the private read receipt location at. + /// + /// This is equivalent to calling the [`create_receipt`] endpoint with a + /// [`ReceiptType::ReadPrivate`]. + /// + /// [`create_receipt`]: crate::receipt::create_receipt + /// [`ReceiptType::ReadPrivate`]: crate::receipt::create_receipt::v3::ReceiptType::ReadPrivate + #[serde(rename = "m.read.private", skip_serializing_if = "Option::is_none")] + pub private_read_receipt: Option<&'a EventId>, } + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given room ID. pub fn new(room_id: &'a RoomId) -> Self { diff --git a/crates/ruma-client-api/src/receipt/create_receipt.rs b/crates/ruma-client-api/src/receipt/create_receipt.rs index 4f8c7e71..9ea163b9 100644 --- a/crates/ruma-client-api/src/receipt/create_receipt.rs +++ b/crates/ruma-client-api/src/receipt/create_receipt.rs @@ -6,55 +6,59 @@ pub mod v3 { //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#post_matrixclientv3roomsroomidreceiptreceipttypeeventid use ruma_common::{ - api::ruma_api, + api::{request, response, Metadata}, events::receipt::ReceiptThread, + metadata, serde::{OrdAsRefStr, PartialEqAsRefStr, PartialOrdAsRefStr, StringEnum}, EventId, RoomId, }; use crate::PrivOwnedStr; - ruma_api! { - metadata: { - description: "Send a receipt event to a room.", - method: POST, - name: "create_receipt", - r0_path: "/_matrix/client/r0/rooms/:room_id/receipt/:receipt_type/:event_id", - stable_path: "/_matrix/client/v3/rooms/:room_id/receipt/:receipt_type/:event_id", - rate_limited: true, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Send a receipt event to a room.", + method: POST, + name: "create_receipt", + rate_limited: true, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/rooms/:room_id/receipt/:receipt_type/:event_id", + 1.1 => "/_matrix/client/v3/rooms/:room_id/receipt/:receipt_type/:event_id", } + }; - request: { - /// The room in which to send the event. - #[ruma_api(path)] - pub room_id: &'a RoomId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The room in which to send the event. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The type of receipt to send. - #[ruma_api(path)] - pub receipt_type: ReceiptType, + /// The type of receipt to send. + #[ruma_api(path)] + pub receipt_type: ReceiptType, - /// The event ID to acknowledge up to. - #[ruma_api(path)] - pub event_id: &'a EventId, + /// The event ID to acknowledge up to. + #[ruma_api(path)] + pub event_id: &'a EventId, - /// The thread this receipt applies to. - /// - /// *Note* that this must be the default value if used with - /// [`ReceiptType::FullyRead`]. - /// - /// Defaults to [`ReceiptThread::Unthreaded`]. - #[serde(rename = "thread_id", default, skip_serializing_if = "ruma_common::serde::is_default")] - pub thread: ReceiptThread, - } - - #[derive(Default)] - response: {} - - error: crate::Error + /// The thread this receipt applies to. + /// + /// *Note* that this must be the default value if used with + /// [`ReceiptType::FullyRead`]. + /// + /// Defaults to [`ReceiptThread::Unthreaded`]. + #[serde( + rename = "thread_id", + default, + skip_serializing_if = "ruma_common::serde::is_default" + )] + pub thread: ReceiptThread, } + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given room ID, receipt type and event ID. pub fn new(room_id: &'a RoomId, receipt_type: ReceiptType, event_id: &'a EventId) -> Self { diff --git a/crates/ruma-client-api/src/redact/redact_event.rs b/crates/ruma-client-api/src/redact/redact_event.rs index 95df4d82..54a84f49 100644 --- a/crates/ruma-client-api/src/redact/redact_event.rs +++ b/crates/ruma-client-api/src/redact/redact_event.rs @@ -5,52 +5,54 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#put_matrixclientv3roomsroomidredacteventidtxnid - use ruma_common::{api::ruma_api, EventId, OwnedEventId, RoomId, TransactionId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, EventId, OwnedEventId, RoomId, TransactionId, + }; - ruma_api! { - metadata: { - description: "Redact an event, stripping all information not critical to the event graph integrity.", - method: PUT, - name: "redact_event", - r0_path: "/_matrix/client/r0/rooms/:room_id/redact/:event_id/:txn_id", - stable_path: "/_matrix/client/v3/rooms/:room_id/redact/:event_id/:txn_id", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Redact an event, stripping all information not critical to the event graph integrity.", + method: PUT, + name: "redact_event", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/rooms/:room_id/redact/:event_id/:txn_id", + 1.1 => "/_matrix/client/v3/rooms/:room_id/redact/:event_id/:txn_id", } + }; - request: { - /// The ID of the room of the event to redact. - #[ruma_api(path)] - pub room_id: &'a RoomId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The ID of the room of the event to redact. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The ID of the event to redact. - #[ruma_api(path)] - pub event_id: &'a EventId, + /// The ID of the event to redact. + #[ruma_api(path)] + pub event_id: &'a EventId, - /// The transaction ID for this event. - /// - /// Clients should generate a unique ID across requests within the - /// same session. A session is identified by an access token, and - /// persists when the [access token is refreshed]. - /// - /// It will be used by the server to ensure idempotency of requests. - /// - /// [access token is refreshed]: https://spec.matrix.org/v1.4/client-server-api/#refreshing-access-tokens - #[ruma_api(path)] - pub txn_id: &'a TransactionId, + /// The transaction ID for this event. + /// + /// Clients should generate a unique ID across requests within the + /// same session. A session is identified by an access token, and + /// persists when the [access token is refreshed]. + /// + /// It will be used by the server to ensure idempotency of requests. + /// + /// [access token is refreshed]: https://spec.matrix.org/v1.4/client-server-api/#refreshing-access-tokens + #[ruma_api(path)] + pub txn_id: &'a TransactionId, - /// The reason for the redaction. - #[serde(skip_serializing_if = "Option::is_none")] - pub reason: Option<&'a str>, - } + /// The reason for the redaction. + #[serde(skip_serializing_if = "Option::is_none")] + pub reason: Option<&'a str>, + } - response: { - /// The ID of the redacted event. - pub event_id: OwnedEventId, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// The ID of the redacted event. + pub event_id: OwnedEventId, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/relations/get_relating_events.rs b/crates/ruma-client-api/src/relations/get_relating_events.rs index e93ed015..a9a2c9e5 100644 --- a/crates/ruma-client-api/src/relations/get_relating_events.rs +++ b/crates/ruma-client-api/src/relations/get_relating_events.rs @@ -8,98 +8,103 @@ pub mod v1 { //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv1roomsroomidrelationseventid use js_int::UInt; - use ruma_common::{api::ruma_api, events::AnyMessageLikeEvent, serde::Raw, EventId, RoomId}; + use ruma_common::{ + api::{request, response, Metadata}, + events::AnyMessageLikeEvent, + metadata, + serde::Raw, + EventId, RoomId, + }; use crate::Direction; - ruma_api! { - metadata: { - description: "Get the child events for a given parent event.", - method: GET, - name: "get_relating_events", - unstable_path: "/_matrix/client/unstable/rooms/:room_id/relations/:event_id", - stable_path: "/_matrix/client/v1/rooms/:room_id/relations/:event_id", - rate_limited: false, - authentication: AccessToken, - added: 1.3, + const METADATA: Metadata = metadata! { + description: "Get the child events for a given parent event.", + method: GET, + name: "get_relating_events", + rate_limited: false, + authentication: AccessToken, + history: { + unstable => "/_matrix/client/unstable/rooms/:room_id/relations/:event_id", + 1.3 => "/_matrix/client/v1/rooms/:room_id/relations/:event_id", } + }; - request: { - /// The ID of the room containing the parent event. - #[ruma_api(path)] - pub room_id: &'a RoomId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The ID of the room containing the parent event. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The ID of the parent event whose child events are to be returned. - #[ruma_api(path)] - pub event_id: &'a EventId, + /// The ID of the parent event whose child events are to be returned. + #[ruma_api(path)] + pub event_id: &'a EventId, - /// The pagination token to start returning results from. - /// - /// If `None`, results start at the most recent topological event known to the server. - /// - /// Can be a `next_batch` or `prev_batch` token from a previous call, or a returned - /// `start` token from `/messages` or a `next_batch` token from `/sync`. - /// - /// Note that when paginating the `from` token should be "after" the `to` token in - /// terms of topological ordering, because it is only possible to paginate "backwards" - /// through events, starting at `from`. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub from: Option<&'a str>, + /// The pagination token to start returning results from. + /// + /// If `None`, results start at the most recent topological event known to the server. + /// + /// Can be a `next_batch` or `prev_batch` token from a previous call, or a returned + /// `start` token from `/messages` or a `next_batch` token from `/sync`. + /// + /// Note that when paginating the `from` token should be "after" the `to` token in + /// terms of topological ordering, because it is only possible to paginate "backwards" + /// through events, starting at `from`. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub from: Option<&'a str>, - /// The direction to return events from. - /// - /// Defaults to [`Direction::Backward`]. - #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")] - #[ruma_api(query)] - pub dir: Direction, + /// The direction to return events from. + /// + /// Defaults to [`Direction::Backward`]. + #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")] + #[ruma_api(query)] + pub dir: Direction, - /// The pagination token to stop returning results at. - /// - /// If `None`, results continue up to `limit` or until there are no more events. - /// - /// Like `from`, this can be a previous token from a prior call to this endpoint - /// or from `/messages` or `/sync`. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub to: Option<&'a str>, + /// The pagination token to stop returning results at. + /// + /// If `None`, results continue up to `limit` or until there are no more events. + /// + /// Like `from`, this can be a previous token from a prior call to this endpoint + /// or from `/messages` or `/sync`. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub to: Option<&'a str>, - /// The maximum number of results to return in a single `chunk`. - /// - /// The server can and should apply a maximum value to this parameter to avoid large - /// responses. - /// - /// Similarly, the server should apply a default value when not supplied. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub limit: Option, - } + /// The maximum number of results to return in a single `chunk`. + /// + /// The server can and should apply a maximum value to this parameter to avoid large + /// responses. + /// + /// Similarly, the server should apply a default value when not supplied. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub limit: Option, + } - response: { - /// The paginated child events which point to the parent. - /// - /// The events returned are ordered topologically, most-recent first. - /// - /// If no events are related to the parent or the pagination yields no results, an - /// empty `chunk` is returned. - pub chunk: Vec>, + #[response(error = crate::Error)] + pub struct Response { + /// The paginated child events which point to the parent. + /// + /// The events returned are ordered topologically, most-recent first. + /// + /// If no events are related to the parent or the pagination yields no results, an + /// empty `chunk` is returned. + pub chunk: Vec>, - /// An opaque string representing a pagination token. - /// - /// If this is `None`, there are no more results to fetch and the client should stop - /// paginating. - #[serde(skip_serializing_if = "Option::is_none")] - pub next_batch: Option, + /// An opaque string representing a pagination token. + /// + /// If this is `None`, there are no more results to fetch and the client should stop + /// paginating. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_batch: Option, - /// An opaque string representing a pagination token. - /// - /// If this is `None`, this is the start of the result set, i.e. this is the first - /// batch/page. - #[serde(skip_serializing_if = "Option::is_none")] - pub prev_batch: Option, - } - - error: crate::Error + /// An opaque string representing a pagination token. + /// + /// If this is `None`, this is the start of the result set, i.e. this is the first + /// batch/page. + #[serde(skip_serializing_if = "Option::is_none")] + pub prev_batch: Option, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/relations/get_relating_events_with_rel_type.rs b/crates/ruma-client-api/src/relations/get_relating_events_with_rel_type.rs index 16ca2507..ac2e1585 100644 --- a/crates/ruma-client-api/src/relations/get_relating_events_with_rel_type.rs +++ b/crates/ruma-client-api/src/relations/get_relating_events_with_rel_type.rs @@ -10,98 +10,98 @@ pub mod v1 { use js_int::UInt; use ruma_common::{ - api::ruma_api, + api::{request, response, Metadata}, events::{relation::RelationType, AnyMessageLikeEvent}, + metadata, serde::Raw, EventId, RoomId, }; - ruma_api! { - metadata: { - description: "Get the child events for a given parent event, with a given `relType`.", - method: GET, - name: "get_relating_events_with_rel_type", - unstable_path: "/_matrix/client/unstable/rooms/:room_id/relations/:event_id/:rel_type", - stable_path: "/_matrix/client/v1/rooms/:room_id/relations/:event_id/:rel_type", - rate_limited: false, - authentication: AccessToken, - added: 1.3, + const METADATA: Metadata = metadata! { + description: "Get the child events for a given parent event, with a given `relType`.", + method: GET, + name: "get_relating_events_with_rel_type", + rate_limited: false, + authentication: AccessToken, + history: { + unstable => "/_matrix/client/unstable/rooms/:room_id/relations/:event_id/:rel_type", + 1.3 => "/_matrix/client/v1/rooms/:room_id/relations/:event_id/:rel_type", } + }; - request: { - /// The ID of the room containing the parent event. - #[ruma_api(path)] - pub room_id: &'a RoomId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The ID of the room containing the parent event. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The ID of the parent event whose child events are to be returned. - #[ruma_api(path)] - pub event_id: &'a EventId, + /// The ID of the parent event whose child events are to be returned. + #[ruma_api(path)] + pub event_id: &'a EventId, - /// The relationship type to search for. - #[ruma_api(path)] - pub rel_type: RelationType, + /// The relationship type to search for. + #[ruma_api(path)] + pub rel_type: RelationType, - /// The pagination token to start returning results from. - /// - /// If `None`, results start at the most recent topological event known to the server. - /// - /// Can be a `next_batch` token from a previous call, or a returned `start` token from - /// `/messages` or a `next_batch` token from `/sync`. - /// - /// Note that when paginating the `from` token should be "after" the `to` token in - /// terms of topological ordering, because it is only possible to paginate "backwards" - /// through events, starting at `from`. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub from: Option<&'a str>, + /// The pagination token to start returning results from. + /// + /// If `None`, results start at the most recent topological event known to the server. + /// + /// Can be a `next_batch` token from a previous call, or a returned `start` token from + /// `/messages` or a `next_batch` token from `/sync`. + /// + /// Note that when paginating the `from` token should be "after" the `to` token in + /// terms of topological ordering, because it is only possible to paginate "backwards" + /// through events, starting at `from`. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub from: Option<&'a str>, - /// The pagination token to stop returning results at. - /// - /// If `None`, results continue up to `limit` or until there are no more events. - /// - /// Like `from`, this can be a previous token from a prior call to this endpoint - /// or from `/messages` or `/sync`. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub to: Option<&'a str>, + /// The pagination token to stop returning results at. + /// + /// If `None`, results continue up to `limit` or until there are no more events. + /// + /// Like `from`, this can be a previous token from a prior call to this endpoint + /// or from `/messages` or `/sync`. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub to: Option<&'a str>, - /// The maximum number of results to return in a single `chunk`. - /// - /// The server can and should apply a maximum value to this parameter to avoid large - /// responses. - /// - /// Similarly, the server should apply a default value when not supplied. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub limit: Option, - } + /// The maximum number of results to return in a single `chunk`. + /// + /// The server can and should apply a maximum value to this parameter to avoid large + /// responses. + /// + /// Similarly, the server should apply a default value when not supplied. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub limit: Option, + } - response: { - /// The paginated child events which point to the parent. - /// - /// The events returned will match the `rel_type` supplied in the URL and are ordered - /// topologically, most-recent first. - /// - /// If no events are related to the parent or the pagination yields no results, an - /// empty `chunk` is returned. - pub chunk: Vec>, + #[response(error = crate::Error)] + pub struct Response { + /// The paginated child events which point to the parent. + /// + /// The events returned will match the `rel_type` supplied in the URL and are ordered + /// topologically, most-recent first. + /// + /// If no events are related to the parent or the pagination yields no results, an + /// empty `chunk` is returned. + pub chunk: Vec>, - /// An opaque string representing a pagination token. - /// - /// If this is `None`, there are no more results to fetch and the client should stop - /// paginating. - #[serde(skip_serializing_if = "Option::is_none")] - pub next_batch: Option, + /// An opaque string representing a pagination token. + /// + /// If this is `None`, there are no more results to fetch and the client should stop + /// paginating. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_batch: Option, - /// An opaque string representing a pagination token. - /// - /// If this is `None`, this is the start of the result set, i.e. this is the first - /// batch/page. - #[serde(skip_serializing_if = "Option::is_none")] - pub prev_batch: Option, - } - - error: crate::Error + /// An opaque string representing a pagination token. + /// + /// If this is `None`, this is the start of the result set, i.e. this is the first + /// batch/page. + #[serde(skip_serializing_if = "Option::is_none")] + pub prev_batch: Option, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/relations/get_relating_events_with_rel_type_and_event_type.rs b/crates/ruma-client-api/src/relations/get_relating_events_with_rel_type_and_event_type.rs index 8c6dec3c..6ebd6df2 100644 --- a/crates/ruma-client-api/src/relations/get_relating_events_with_rel_type_and_event_type.rs +++ b/crates/ruma-client-api/src/relations/get_relating_events_with_rel_type_and_event_type.rs @@ -10,105 +10,105 @@ pub mod v1 { use js_int::UInt; use ruma_common::{ - api::ruma_api, + api::{request, response, Metadata}, events::{relation::RelationType, AnyMessageLikeEvent, RoomEventType}, + metadata, serde::Raw, EventId, RoomId, }; - ruma_api! { - metadata: { - description: "Get the child events for a given parent event, with a given `relType` and `eventType`.", - method: GET, - name: "get_relating_events_with_rel_type_and_event_type", - unstable_path: "/_matrix/client/unstable/rooms/:room_id/relations/:event_id/:rel_type/:event_type", - stable_path: "/_matrix/client/v1/rooms/:room_id/relations/:event_id/:rel_type/:event_type", - rate_limited: false, - authentication: AccessToken, - added: 1.3, + const METADATA: Metadata = metadata! { + description: "Get the child events for a given parent event, with a given `relType` and `eventType`.", + method: GET, + name: "get_relating_events_with_rel_type_and_event_type", + rate_limited: false, + authentication: AccessToken, + history: { + unstable => "/_matrix/client/unstable/rooms/:room_id/relations/:event_id/:rel_type/:event_type", + 1.3 => "/_matrix/client/v1/rooms/:room_id/relations/:event_id/:rel_type/:event_type", } + }; - request: { - /// The ID of the room containing the parent event. - #[ruma_api(path)] - pub room_id: &'a RoomId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The ID of the room containing the parent event. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The ID of the parent event whose child events are to be returned. - #[ruma_api(path)] - pub event_id: &'a EventId, + /// The ID of the parent event whose child events are to be returned. + #[ruma_api(path)] + pub event_id: &'a EventId, - /// The relationship type to search for. - #[ruma_api(path)] - pub rel_type: RelationType, + /// The relationship type to search for. + #[ruma_api(path)] + pub rel_type: RelationType, - /// The event type of child events to search for. - /// - /// Note that in encrypted rooms this will typically always be `m.room.encrypted` - /// regardless of the event type contained within the encrypted payload. - #[ruma_api(path)] - pub event_type: RoomEventType, + /// The event type of child events to search for. + /// + /// Note that in encrypted rooms this will typically always be `m.room.encrypted` + /// regardless of the event type contained within the encrypted payload. + #[ruma_api(path)] + pub event_type: RoomEventType, - /// The pagination token to start returning results from. - /// - /// If `None`, results start at the most recent topological event known to the server. - /// - /// Can be a `next_batch` token from a previous call, or a returned `start` token from - /// `/messages` or a `next_batch` token from `/sync`. - /// - /// Note that when paginating the `from` token should be "after" the `to` token in - /// terms of topological ordering, because it is only possible to paginate "backwards" - /// through events, starting at `from`. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub from: Option<&'a str>, + /// The pagination token to start returning results from. + /// + /// If `None`, results start at the most recent topological event known to the server. + /// + /// Can be a `next_batch` token from a previous call, or a returned `start` token from + /// `/messages` or a `next_batch` token from `/sync`. + /// + /// Note that when paginating the `from` token should be "after" the `to` token in + /// terms of topological ordering, because it is only possible to paginate "backwards" + /// through events, starting at `from`. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub from: Option<&'a str>, - /// The pagination token to stop returning results at. - /// - /// If `None`, results continue up to `limit` or until there are no more events. - /// - /// Like `from`, this can be a previous token from a prior call to this endpoint - /// or from `/messages` or `/sync`. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub to: Option<&'a str>, + /// The pagination token to stop returning results at. + /// + /// If `None`, results continue up to `limit` or until there are no more events. + /// + /// Like `from`, this can be a previous token from a prior call to this endpoint + /// or from `/messages` or `/sync`. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub to: Option<&'a str>, - /// The maximum number of results to return in a single `chunk`. - /// - /// The server can and should apply a maximum value to this parameter to avoid large - /// responses. - /// - /// Similarly, the server should apply a default value when not supplied. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub limit: Option, - } + /// The maximum number of results to return in a single `chunk`. + /// + /// The server can and should apply a maximum value to this parameter to avoid large + /// responses. + /// + /// Similarly, the server should apply a default value when not supplied. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub limit: Option, + } - response: { - /// The paginated child events which point to the parent. - /// - /// The events returned will match the `rel_type` and `even_type` supplied in the URL - /// and are ordered topologically, most-recent first. - /// - /// If no events are related to the parent or the pagination yields no results, an - /// empty `chunk` is returned. - pub chunk: Vec>, + #[response(error = crate::Error)] + pub struct Response { + /// The paginated child events which point to the parent. + /// + /// The events returned will match the `rel_type` and `even_type` supplied in the URL + /// and are ordered topologically, most-recent first. + /// + /// If no events are related to the parent or the pagination yields no results, an + /// empty `chunk` is returned. + pub chunk: Vec>, - /// An opaque string representing a pagination token. - /// - /// If this is `None`, there are no more results to fetch and the client should stop - /// paginating. - #[serde(skip_serializing_if = "Option::is_none")] - pub next_batch: Option, + /// An opaque string representing a pagination token. + /// + /// If this is `None`, there are no more results to fetch and the client should stop + /// paginating. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_batch: Option, - /// An opaque string representing a pagination token. - /// - /// If this is `None`, this is the start of the result set, i.e. this is the first - /// batch/page. - #[serde(skip_serializing_if = "Option::is_none")] - pub prev_batch: Option, - } - - error: crate::Error + /// An opaque string representing a pagination token. + /// + /// If this is `None`, this is the start of the result set, i.e. this is the first + /// batch/page. + #[serde(skip_serializing_if = "Option::is_none")] + pub prev_batch: Option, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/room/aliases.rs b/crates/ruma-client-api/src/room/aliases.rs index f6e65452..b4f7d5e1 100644 --- a/crates/ruma-client-api/src/room/aliases.rs +++ b/crates/ruma-client-api/src/room/aliases.rs @@ -5,33 +5,35 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3roomsroomidaliases - use ruma_common::{api::ruma_api, OwnedRoomAliasId, RoomId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, OwnedRoomAliasId, RoomId, + }; - ruma_api! { - metadata: { - description: "Get a list of aliases maintained by the local server for the given room.", - method: GET, - name: "aliases", - r0_path: "/_matrix/client/r0/rooms/:room_id/aliases", - stable_path: "/_matrix/client/v3/rooms/:room_id/aliases", - unstable_path: "/_matrix/client/unstable/org.matrix.msc2432/rooms/:room_id/aliases", - rate_limited: true, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Get a list of aliases maintained by the local server for the given room.", + method: GET, + name: "aliases", + rate_limited: true, + authentication: AccessToken, + history: { + unstable => "/_matrix/client/unstable/org.matrix.msc2432/rooms/:room_id/aliases", + 1.0 => "/_matrix/client/r0/rooms/:room_id/aliases", + 1.1 => "/_matrix/client/v3/rooms/:room_id/aliases", } + }; - request: { - /// The room ID to get aliases of. - #[ruma_api(path)] - pub room_id: &'a RoomId, - } + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The room ID to get aliases of. + #[ruma_api(path)] + pub room_id: &'a RoomId, + } - response: { - /// The server's local aliases on the room. - pub aliases: Vec, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// The server's local aliases on the room. + pub aliases: Vec, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/room/create_room.rs b/crates/ruma-client-api/src/room/create_room.rs index 42e22fa6..742113e8 100644 --- a/crates/ruma-client-api/src/room/create_room.rs +++ b/crates/ruma-client-api/src/room/create_room.rs @@ -7,7 +7,7 @@ pub mod v3 { use assign::assign; use ruma_common::{ - api::ruma_api, + api::{request, response, Metadata}, events::{ room::{ create::{PreviousRoom, RoomCreateEventContent}, @@ -15,6 +15,7 @@ pub mod v3 { }, AnyInitialStateEvent, }, + metadata, room::RoomType, serde::{Raw, StringEnum}, OwnedRoomId, OwnedUserId, RoomVersionId, @@ -27,86 +28,85 @@ pub mod v3 { PrivOwnedStr, }; - ruma_api! { - metadata: { - description: "Create a new room.", - method: POST, - name: "create_room", - r0_path: "/_matrix/client/r0/createRoom", - stable_path: "/_matrix/client/v3/createRoom", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Create a new room.", + method: POST, + name: "create_room", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/createRoom", + 1.1 => "/_matrix/client/v3/createRoom", } + }; - #[derive(Default)] - request: { - /// Extra keys to be added to the content of the `m.room.create`. - #[serde(default, skip_serializing_if = "Option::is_none")] - pub creation_content: Option>, + #[request(error = crate::Error)] + #[derive(Default)] + pub struct Request<'a> { + /// Extra keys to be added to the content of the `m.room.create`. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub creation_content: Option>, - /// List of state events to send to the new room. - /// - /// Takes precedence over events set by preset, but gets overridden by name and topic keys. - #[serde(default, skip_serializing_if = "<[_]>::is_empty")] - pub initial_state: &'a [Raw], + /// List of state events to send to the new room. + /// + /// Takes precedence over events set by preset, but gets overridden by name and topic keys. + #[serde(default, skip_serializing_if = "<[_]>::is_empty")] + pub initial_state: &'a [Raw], - /// A list of user IDs to invite to the room. - /// - /// This will tell the server to invite everyone in the list to the newly created room. - #[serde(default, skip_serializing_if = "<[_]>::is_empty")] - pub invite: &'a [OwnedUserId], + /// A list of user IDs to invite to the room. + /// + /// This will tell the server to invite everyone in the list to the newly created room. + #[serde(default, skip_serializing_if = "<[_]>::is_empty")] + pub invite: &'a [OwnedUserId], - /// List of third party IDs of users to invite. - #[serde(default, skip_serializing_if = "<[_]>::is_empty")] - pub invite_3pid: &'a [Invite3pid<'a>], + /// List of third party IDs of users to invite. + #[serde(default, skip_serializing_if = "<[_]>::is_empty")] + pub invite_3pid: &'a [Invite3pid<'a>], - /// If set, this sets the `is_direct` flag on room invites. - #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")] - pub is_direct: bool, + /// If set, this sets the `is_direct` flag on room invites. + #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")] + pub is_direct: bool, - /// If this is included, an `m.room.name` event will be sent into the room to indicate the - /// name of the room. - #[serde(skip_serializing_if = "Option::is_none")] - pub name: Option<&'a str>, + /// If this is included, an `m.room.name` event will be sent into the room to indicate the + /// name of the room. + #[serde(skip_serializing_if = "Option::is_none")] + pub name: Option<&'a str>, - /// Power level content to override in the default power level event. - #[serde(skip_serializing_if = "Option::is_none")] - pub power_level_content_override: Option>, + /// Power level content to override in the default power level event. + #[serde(skip_serializing_if = "Option::is_none")] + pub power_level_content_override: Option>, - /// Convenience parameter for setting various default state events based on a preset. - #[serde(skip_serializing_if = "Option::is_none")] - pub preset: Option, + /// Convenience parameter for setting various default state events based on a preset. + #[serde(skip_serializing_if = "Option::is_none")] + pub preset: Option, - /// The desired room alias local part. - #[serde(skip_serializing_if = "Option::is_none")] - pub room_alias_name: Option<&'a str>, + /// The desired room alias local part. + #[serde(skip_serializing_if = "Option::is_none")] + pub room_alias_name: Option<&'a str>, - /// Room version to set for the room. - /// - /// Defaults to homeserver's default if not specified. - #[serde(skip_serializing_if = "Option::is_none")] - pub room_version: Option<&'a RoomVersionId>, + /// Room version to set for the room. + /// + /// Defaults to homeserver's default if not specified. + #[serde(skip_serializing_if = "Option::is_none")] + pub room_version: Option<&'a RoomVersionId>, - /// If this is included, an `m.room.topic` event will be sent into the room to indicate - /// the topic for the room. - #[serde(skip_serializing_if = "Option::is_none")] - pub topic: Option<&'a str>, + /// If this is included, an `m.room.topic` event will be sent into the room to indicate + /// the topic for the room. + #[serde(skip_serializing_if = "Option::is_none")] + pub topic: Option<&'a str>, - /// A public visibility indicates that the room will be shown in the published room list. - /// - /// A private visibility will hide the room from the published room list. Defaults to - /// `Private`. - #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")] - pub visibility: Visibility, - } + /// A public visibility indicates that the room will be shown in the published room list. + /// + /// A private visibility will hide the room from the published room list. Defaults to + /// `Private`. + #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")] + pub visibility: Visibility, + } - response: { - /// The created room's ID. - pub room_id: OwnedRoomId, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// The created room's ID. + pub room_id: OwnedRoomId, } impl Request<'_> { diff --git a/crates/ruma-client-api/src/room/get_room_event.rs b/crates/ruma-client-api/src/room/get_room_event.rs index f71b095f..6ecd44df 100644 --- a/crates/ruma-client-api/src/room/get_room_event.rs +++ b/crates/ruma-client-api/src/room/get_room_event.rs @@ -5,37 +5,42 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3roomsroomideventeventid - use ruma_common::{api::ruma_api, events::AnyTimelineEvent, serde::Raw, EventId, RoomId}; + use ruma_common::{ + api::{request, response, Metadata}, + events::AnyTimelineEvent, + metadata, + serde::Raw, + EventId, RoomId, + }; - ruma_api! { - metadata: { - description: "Get a single event based on roomId/eventId", - method: GET, - name: "get_room_event", - r0_path: "/_matrix/client/r0/rooms/:room_id/event/:event_id", - stable_path: "/_matrix/client/v3/rooms/:room_id/event/:event_id", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Get a single event based on roomId/eventId", + method: GET, + name: "get_room_event", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/rooms/:room_id/event/:event_id", + 1.1 => "/_matrix/client/v3/rooms/:room_id/event/:event_id", } + }; - request: { - /// The ID of the room the event is in. - #[ruma_api(path)] - pub room_id: &'a RoomId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The ID of the room the event is in. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The ID of the event. - #[ruma_api(path)] - pub event_id: &'a EventId, - } + /// The ID of the event. + #[ruma_api(path)] + pub event_id: &'a EventId, + } - response: { - /// Arbitrary JSON of the event body. - #[ruma_api(body)] - pub event: Raw, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// Arbitrary JSON of the event body. + #[ruma_api(body)] + pub event: Raw, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/room/report_content.rs b/crates/ruma-client-api/src/room/report_content.rs index 5897acb6..e3e01fbf 100644 --- a/crates/ruma-client-api/src/room/report_content.rs +++ b/crates/ruma-client-api/src/room/report_content.rs @@ -6,44 +6,46 @@ pub mod v3 { //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#post_matrixclientv3roomsroomidreporteventid use js_int::Int; - use ruma_common::{api::ruma_api, EventId, RoomId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, EventId, RoomId, + }; - ruma_api! { - metadata: { - description: "Report content as inappropriate.", - method: POST, - name: "report_content", - r0_path: "/_matrix/client/r0/rooms/:room_id/report/:event_id", - stable_path: "/_matrix/client/v3/rooms/:room_id/report/:event_id", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Report content as inappropriate.", + method: POST, + name: "report_content", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/rooms/:room_id/report/:event_id", + 1.1 => "/_matrix/client/v3/rooms/:room_id/report/:event_id", } + }; - request: { - /// Room in which the event to be reported is located. - #[ruma_api(path)] - pub room_id: &'a RoomId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// Room in which the event to be reported is located. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// Event to report. - #[ruma_api(path)] - pub event_id: &'a EventId, + /// Event to report. + #[ruma_api(path)] + pub event_id: &'a EventId, - /// Integer between -100 and 0 rating offensivness. - pub score: Option, + /// Integer between -100 and 0 rating offensivness. + pub score: Option, - /// Reason to report content. - /// - /// May be blank. - pub reason: Option<&'a str>, - } - - #[derive(Default)] - response: {} - - error: crate::Error + /// Reason to report content. + /// + /// May be blank. + pub reason: Option<&'a str>, } + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given room ID, event ID, score and reason. pub fn new( diff --git a/crates/ruma-client-api/src/room/upgrade_room.rs b/crates/ruma-client-api/src/room/upgrade_room.rs index 01348e5f..576db3bf 100644 --- a/crates/ruma-client-api/src/room/upgrade_room.rs +++ b/crates/ruma-client-api/src/room/upgrade_room.rs @@ -5,35 +5,37 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#post_matrixclientv3roomsroomidupgrade - use ruma_common::{api::ruma_api, OwnedRoomId, RoomId, RoomVersionId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, OwnedRoomId, RoomId, RoomVersionId, + }; - ruma_api! { - metadata: { - description: "Upgrades a room to a particular version.", - method: POST, - name: "upgrade_room", - r0_path: "/_matrix/client/r0/rooms/:room_id/upgrade", - stable_path: "/_matrix/client/v3/rooms/:room_id/upgrade", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Upgrades a room to a particular version.", + method: POST, + name: "upgrade_room", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/rooms/:room_id/upgrade", + 1.1 => "/_matrix/client/v3/rooms/:room_id/upgrade", } + }; - request: { - /// ID of the room to be upgraded. - #[ruma_api(path)] - pub room_id: &'a RoomId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// ID of the room to be upgraded. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// New version for the room. - pub new_version: &'a RoomVersionId, - } + /// New version for the room. + pub new_version: &'a RoomVersionId, + } - response: { - /// ID of the new room. - pub replacement_room: OwnedRoomId, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// ID of the new room. + pub replacement_room: OwnedRoomId, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/search/search_events.rs b/crates/ruma-client-api/src/search/search_events.rs index eacaa334..dedb4b75 100644 --- a/crates/ruma-client-api/src/search/search_events.rs +++ b/crates/ruma-client-api/src/search/search_events.rs @@ -9,8 +9,9 @@ pub mod v3 { use js_int::{uint, UInt}; use ruma_common::{ - api::ruma_api, + api::{request, response, Metadata}, events::{AnyStateEvent, AnyTimelineEvent}, + metadata, serde::{Incoming, Raw, StringEnum}, OwnedEventId, OwnedMxcUri, OwnedRoomId, OwnedUserId, }; @@ -21,35 +22,34 @@ pub mod v3 { PrivOwnedStr, }; - ruma_api! { - metadata: { - description: "Search events.", - method: POST, - name: "search", - r0_path: "/_matrix/client/r0/search", - stable_path: "/_matrix/client/v3/search", - rate_limited: true, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Search events.", + method: POST, + name: "search", + rate_limited: true, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/search", + 1.1 => "/_matrix/client/v3/search", } + }; - request: { - /// The point to return events from. - /// - /// If given, this should be a `next_batch` result from a previous call to this endpoint. - #[ruma_api(query)] - pub next_batch: Option<&'a str>, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The point to return events from. + /// + /// If given, this should be a `next_batch` result from a previous call to this endpoint. + #[ruma_api(query)] + pub next_batch: Option<&'a str>, - /// Describes which categories to search in and their criteria. - pub search_categories: Categories<'a>, - } + /// Describes which categories to search in and their criteria. + pub search_categories: Categories<'a>, + } - response: { - /// A grouping of search results by category. - pub search_categories: ResultCategories, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// A grouping of search results by category. + pub search_categories: ResultCategories, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/server/get_user_info.rs b/crates/ruma-client-api/src/server/get_user_info.rs index 95ab487c..f1c14408 100644 --- a/crates/ruma-client-api/src/server/get_user_info.rs +++ b/crates/ruma-client-api/src/server/get_user_info.rs @@ -7,39 +7,41 @@ pub mod v3 { use std::collections::BTreeMap; - use ruma_common::{api::ruma_api, MilliSecondsSinceUnixEpoch, OwnedUserId, UserId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, MilliSecondsSinceUnixEpoch, OwnedUserId, UserId, + }; use serde::{Deserialize, Serialize}; - ruma_api! { - metadata: { - description: "Get information about a particular user.", - method: GET, - name: "get_user_info", - r0_path: "/_matrix/client/r0/admin/whois/:user_id", - stable_path: "/_matrix/client/v3/admin/whois/:user_id", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Get information about a particular user.", + method: GET, + name: "get_user_info", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/admin/whois/:user_id", + 1.1 => "/_matrix/client/v3/admin/whois/:user_id", } + }; - request: { - /// The user to look up. - #[ruma_api(path)] - pub user_id: &'a UserId, - } + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The user to look up. + #[ruma_api(path)] + pub user_id: &'a UserId, + } - #[derive(Default)] - response: { - /// The Matrix user ID of the user. - #[serde(skip_serializing_if = "Option::is_none")] - pub user_id: Option, + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response { + /// The Matrix user ID of the user. + #[serde(skip_serializing_if = "Option::is_none")] + pub user_id: Option, - /// A map of the user's device identifiers to information about that device. - #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] - pub devices: BTreeMap, - } - - error: crate::Error + /// A map of the user's device identifiers to information about that device. + #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] + pub devices: BTreeMap, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/session/get_login_types.rs b/crates/ruma-client-api/src/session/get_login_types.rs index 6c9bd7b7..b6a61b8c 100644 --- a/crates/ruma-client-api/src/session/get_login_types.rs +++ b/crates/ruma-client-api/src/session/get_login_types.rs @@ -8,7 +8,8 @@ pub mod v3 { use std::borrow::Cow; use ruma_common::{ - api::ruma_api, + api::{request, response, Metadata}, + metadata, serde::{JsonObject, StringEnum}, OwnedMxcUri, }; @@ -17,27 +18,26 @@ pub mod v3 { use crate::PrivOwnedStr; - ruma_api! { - metadata: { - description: "Gets the homeserver's supported login types to authenticate users. Clients should pick one of these and supply it as the type when logging in.", - method: GET, - name: "get_login_types", - r0_path: "/_matrix/client/r0/login", - stable_path: "/_matrix/client/v3/login", - rate_limited: true, - authentication: None, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Gets the homeserver's supported login types to authenticate users. Clients should pick one of these and supply it as the type when logging in.", + method: GET, + name: "get_login_types", + rate_limited: true, + authentication: None, + history: { + 1.0 => "/_matrix/client/r0/login", + 1.1 => "/_matrix/client/v3/login", } + }; - #[derive(Default)] - request: {} + #[request(error = crate::Error)] + #[derive(Default)] + pub struct Request {} - response: { - /// The homeserver's supported login types. - pub flows: Vec, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// The homeserver's supported login types. + pub flows: Vec, } impl Request { diff --git a/crates/ruma-client-api/src/session/login.rs b/crates/ruma-client-api/src/session/login.rs index 6a3be95a..93ebe141 100644 --- a/crates/ruma-client-api/src/session/login.rs +++ b/crates/ruma-client-api/src/session/login.rs @@ -8,7 +8,8 @@ pub mod v3 { use std::{fmt, time::Duration}; use ruma_common::{ - api::ruma_api, + api::{request, response, Metadata}, + metadata, serde::{Incoming, JsonObject}, DeviceId, OwnedDeviceId, OwnedServerName, OwnedUserId, }; @@ -20,95 +21,93 @@ pub mod v3 { use crate::uiaa::{IncomingUserIdentifier, UserIdentifier}; - ruma_api! { - metadata: { - description: "Login to the homeserver.", - method: POST, - name: "login", - r0_path: "/_matrix/client/r0/login", - stable_path: "/_matrix/client/v3/login", - rate_limited: true, - authentication: None, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Login to the homeserver.", + method: POST, + name: "login", + rate_limited: true, + authentication: None, + history: { + 1.0 => "/_matrix/client/r0/login", + 1.1 => "/_matrix/client/v3/login", } + }; - request: { - /// The authentication mechanism. - #[serde(flatten)] - pub login_info: LoginInfo<'a>, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The authentication mechanism. + #[serde(flatten)] + pub login_info: LoginInfo<'a>, - /// ID of the client device - #[serde(skip_serializing_if = "Option::is_none")] - pub device_id: Option<&'a DeviceId>, + /// ID of the client device + #[serde(skip_serializing_if = "Option::is_none")] + pub device_id: Option<&'a DeviceId>, - /// A display name to assign to the newly-created device. - /// - /// Ignored if `device_id` corresponds to a known device. - #[serde(skip_serializing_if = "Option::is_none")] - pub initial_device_display_name: Option<&'a str>, + /// A display name to assign to the newly-created device. + /// + /// Ignored if `device_id` corresponds to a known device. + #[serde(skip_serializing_if = "Option::is_none")] + pub initial_device_display_name: Option<&'a str>, - /// If set to `true`, the client supports [refresh tokens]. - /// - /// [refresh tokens]: https://spec.matrix.org/v1.4/client-server-api/#refreshing-access-tokens - #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")] - pub refresh_token: bool, - } - - response: { - /// The fully-qualified Matrix ID that has been registered. - pub user_id: OwnedUserId, - - /// An access token for the account. - pub access_token: String, - - /// The hostname of the homeserver on which the account has been registered. - /// - /// Deprecated: Clients should instead use the `user_id.server_name()` - /// method if they require it. - #[serde(skip_serializing_if = "Option::is_none")] - pub home_server: Option, - - /// ID of the logged-in device. - /// - /// Will be the same as the corresponding parameter in the request, if one was - /// specified. - pub device_id: OwnedDeviceId, - - /// Client configuration provided by the server. - /// - /// If present, clients SHOULD use the provided object to reconfigure themselves. - #[serde(skip_serializing_if = "Option::is_none")] - pub well_known: Option, - - /// A [refresh token] for the account. - /// - /// This token can be used to obtain a new access token when it expires by calling the - /// [`refresh_token`] endpoint. - /// - /// [refresh token]: https://spec.matrix.org/v1.4/client-server-api/#refreshing-access-tokens - /// [`refresh_token`]: crate::session::refresh_token - #[serde(skip_serializing_if = "Option::is_none")] - pub refresh_token: Option, - - /// The lifetime of the access token, in milliseconds. - /// - /// Once the access token has expired, a new access token can be obtained by using the - /// provided refresh token. If no refresh token is provided, the client will need to - /// re-login to obtain a new access token. - /// - /// If this is `None`, the client can assume that the access token will not expire. - #[serde( - with = "ruma_common::serde::duration::opt_ms", - default, - skip_serializing_if = "Option::is_none", - rename = "expires_in_ms", - )] - pub expires_in: Option, - } - - error: crate::Error + /// If set to `true`, the client supports [refresh tokens]. + /// + /// [refresh tokens]: https://spec.matrix.org/v1.4/client-server-api/#refreshing-access-tokens + #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")] + pub refresh_token: bool, } + #[response(error = crate::Error)] + pub struct Response { + /// The fully-qualified Matrix ID that has been registered. + pub user_id: OwnedUserId, + + /// An access token for the account. + pub access_token: String, + + /// The hostname of the homeserver on which the account has been registered. + /// + /// Deprecated: Clients should instead use the `user_id.server_name()` + /// method if they require it. + #[serde(skip_serializing_if = "Option::is_none")] + pub home_server: Option, + + /// ID of the logged-in device. + /// + /// Will be the same as the corresponding parameter in the request, if one was + /// specified. + pub device_id: OwnedDeviceId, + + /// Client configuration provided by the server. + /// + /// If present, clients SHOULD use the provided object to reconfigure themselves. + #[serde(skip_serializing_if = "Option::is_none")] + pub well_known: Option, + + /// A [refresh token] for the account. + /// + /// This token can be used to obtain a new access token when it expires by calling the + /// [`refresh_token`] endpoint. + /// + /// [refresh token]: https://spec.matrix.org/v1.4/client-server-api/#refreshing-access-tokens + /// [`refresh_token`]: crate::session::refresh_token + #[serde(skip_serializing_if = "Option::is_none")] + pub refresh_token: Option, + + /// The lifetime of the access token, in milliseconds. + /// + /// Once the access token has expired, a new access token can be obtained by using the + /// provided refresh token. If no refresh token is provided, the client will need to + /// re-login to obtain a new access token. + /// + /// If this is `None`, the client can assume that the access token will not expire. + #[serde( + with = "ruma_common::serde::duration::opt_ms", + default, + skip_serializing_if = "Option::is_none", + rename = "expires_in_ms" + )] + pub expires_in: Option, + } impl<'a> Request<'a> { /// Creates a new `Request` with the given login info. pub fn new(login_info: LoginInfo<'a>) -> Self { diff --git a/crates/ruma-client-api/src/session/login_fallback.rs b/crates/ruma-client-api/src/session/login_fallback.rs index fbb9e6a8..6fc66a7c 100644 --- a/crates/ruma-client-api/src/session/login_fallback.rs +++ b/crates/ruma-client-api/src/session/login_fallback.rs @@ -2,39 +2,43 @@ //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#login-fallback -use ruma_common::{api::ruma_api, DeviceId}; +use ruma_common::{ + api::{request, response, Metadata}, + metadata, DeviceId, +}; -ruma_api! { - metadata: { - description: "Get login fallback web page.", - method: GET, - name: "login_fallback", - stable_path: "/_matrix/static/client/login/", - rate_limited: false, - authentication: None, - added: 1.0, +const METADATA: Metadata = metadata! { + description: "Get login fallback web page.", + method: GET, + name: "login_fallback", + rate_limited: false, + authentication: None, + history: { + 1.0 => "/_matrix/static/client/login/", } +}; - #[derive(Default)] - request: { - /// ID of the client device. - #[ruma_api(query)] - #[serde(skip_serializing_if = "Option::is_none")] - pub device_id: Option<&'a DeviceId>, +#[request(error = crate::Error)] +#[derive(Default)] +pub struct Request<'a> { + /// ID of the client device. + #[ruma_api(query)] + #[serde(skip_serializing_if = "Option::is_none")] + pub device_id: Option<&'a DeviceId>, - /// A display name to assign to the newly-created device. - /// - /// Ignored if `device_id` corresponds to a known device. - #[ruma_api(query)] - #[serde(skip_serializing_if = "Option::is_none")] - pub initial_device_display_name: Option<&'a str>, - } + /// A display name to assign to the newly-created device. + /// + /// Ignored if `device_id` corresponds to a known device. + #[ruma_api(query)] + #[serde(skip_serializing_if = "Option::is_none")] + pub initial_device_display_name: Option<&'a str>, +} - response: { - /// HTML to return to client. - #[ruma_api(raw_body)] - pub body: Vec, - } +#[response(error = crate::Error)] +pub struct Response { + /// HTML to return to client. + #[ruma_api(raw_body)] + pub body: Vec, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/session/logout.rs b/crates/ruma-client-api/src/session/logout.rs index 36c06bd8..9180891d 100644 --- a/crates/ruma-client-api/src/session/logout.rs +++ b/crates/ruma-client-api/src/session/logout.rs @@ -5,28 +5,30 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#post_matrixclientv3logout - use ruma_common::api::ruma_api; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + }; - ruma_api! { - metadata: { - description: "Log out of the homeserver.", - method: POST, - name: "logout", - r0_path: "/_matrix/client/r0/logout", - stable_path: "/_matrix/client/v3/logout", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Log out of the homeserver.", + method: POST, + name: "logout", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/logout", + 1.1 => "/_matrix/client/v3/logout", } + }; - #[derive(Default)] - request: {} + #[request(error = crate::Error)] + #[derive(Default)] + pub struct Request {} - #[derive(Default)] - response: {} - - error: crate::Error - } + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response {} impl Request { /// Creates an empty `Request`. diff --git a/crates/ruma-client-api/src/session/logout_all.rs b/crates/ruma-client-api/src/session/logout_all.rs index 95d589eb..4058f9ce 100644 --- a/crates/ruma-client-api/src/session/logout_all.rs +++ b/crates/ruma-client-api/src/session/logout_all.rs @@ -5,28 +5,30 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#post_matrixclientv3logoutall - use ruma_common::api::ruma_api; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + }; - ruma_api! { - metadata: { - description: "Invalidates all access tokens for a user, so that they can no longer be used for authorization.", - method: POST, - name: "logout_all", - r0_path: "/_matrix/client/r0/logout/all", - stable_path: "/_matrix/client/v3/logout/all", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Invalidates all access tokens for a user, so that they can no longer be used for authorization.", + method: POST, + name: "logout_all", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/logout/all", + 1.1 => "/_matrix/client/v3/logout/all", } + }; - #[derive(Default)] - request: {} + #[request(error = crate::Error)] + #[derive(Default)] + pub struct Request {} - #[derive(Default)] - response: {} - - error: crate::Error - } + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response {} impl Request { /// Creates an empty `Request`. diff --git a/crates/ruma-client-api/src/session/refresh_token.rs b/crates/ruma-client-api/src/session/refresh_token.rs index c859ed53..729bb116 100644 --- a/crates/ruma-client-api/src/session/refresh_token.rs +++ b/crates/ruma-client-api/src/session/refresh_token.rs @@ -27,47 +27,49 @@ pub mod v3 { use std::time::Duration; - use ruma_common::api::ruma_api; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + }; - ruma_api! { - metadata: { - description: "Refresh an access token.", - method: POST, - name: "refresh", - unstable_path: "/_matrix/client/unstable/org.matrix.msc2918/refresh", - stable_path: "/_matrix/client/v3/refresh", - rate_limited: true, - authentication: None, - added: 1.3, + const METADATA: Metadata = metadata! { + description: "Refresh an access token.", + method: POST, + name: "refresh", + rate_limited: true, + authentication: None, + history: { + unstable => "/_matrix/client/unstable/org.matrix.msc2918/refresh", + 1.3 => "/_matrix/client/v3/refresh", } + }; - request: { - /// The refresh token. - pub refresh_token: &'a str, - } + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The refresh token. + pub refresh_token: &'a str, + } - response: { - /// The new access token to use. - pub access_token: String, + #[response(error = crate::Error)] + pub struct Response { + /// The new access token to use. + pub access_token: String, - /// The new refresh token to use when the access token needs to be refreshed again. - /// - /// If this is `None`, the old refresh token can be re-used. - #[serde(skip_serializing_if = "Option::is_none")] - pub refresh_token: Option, + /// The new refresh token to use when the access token needs to be refreshed again. + /// + /// If this is `None`, the old refresh token can be re-used. + #[serde(skip_serializing_if = "Option::is_none")] + pub refresh_token: Option, - /// The lifetime of the access token, in milliseconds. - /// - /// If this is `None`, the client can assume that the access token will not expire. - #[serde( - with = "ruma_common::serde::duration::opt_ms", - default, - skip_serializing_if = "Option::is_none" - )] - pub expires_in_ms: Option, - } - - error: crate::Error + /// The lifetime of the access token, in milliseconds. + /// + /// If this is `None`, the client can assume that the access token will not expire. + #[serde( + with = "ruma_common::serde::duration::opt_ms", + default, + skip_serializing_if = "Option::is_none" + )] + pub expires_in_ms: Option, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/session/sso_login.rs b/crates/ruma-client-api/src/session/sso_login.rs index 8e044225..12e472a3 100644 --- a/crates/ruma-client-api/src/session/sso_login.rs +++ b/crates/ruma-client-api/src/session/sso_login.rs @@ -6,35 +6,37 @@ pub mod v3 { //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3loginssoredirect use http::header::LOCATION; - use ruma_common::api::ruma_api; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + }; - ruma_api! { - metadata: { - description: "", - method: GET, - name: "sso_login", - r0_path: "/_matrix/client/r0/login/sso/redirect", - stable_path: "/_matrix/client/v3/login/sso/redirect", - rate_limited: false, - authentication: None, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "", + method: GET, + name: "sso_login", + rate_limited: false, + authentication: None, + history: { + 1.0 => "/_matrix/client/r0/login/sso/redirect", + 1.1 => "/_matrix/client/v3/login/sso/redirect", } + }; - request: { - /// URL to which the homeserver should return the user after completing - /// authentication with the SSO identity provider. - #[ruma_api(query)] - #[serde(rename = "redirectUrl")] - pub redirect_url: &'a str, - } + #[request(error = crate::Error)] + pub struct Request<'a> { + /// URL to which the homeserver should return the user after completing + /// authentication with the SSO identity provider. + #[ruma_api(query)] + #[serde(rename = "redirectUrl")] + pub redirect_url: &'a str, + } - response: { - /// Redirect URL to the SSO identity provider. - #[ruma_api(header = LOCATION)] - pub location: String, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// Redirect URL to the SSO identity provider. + #[ruma_api(header = LOCATION)] + pub location: String, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/session/sso_login_with_provider.rs b/crates/ruma-client-api/src/session/sso_login_with_provider.rs index f355be69..84b973c4 100644 --- a/crates/ruma-client-api/src/session/sso_login_with_provider.rs +++ b/crates/ruma-client-api/src/session/sso_login_with_provider.rs @@ -8,39 +8,41 @@ pub mod v3 { //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3loginssoredirectidpid use http::header::LOCATION; - use ruma_common::api::ruma_api; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + }; - ruma_api! { - metadata: { - description: "Get the SSO login identity provider url.", - method: GET, - name: "sso_login_with_provider", - unstable_path: "/_matrix/client/unstable/org.matrix.msc2858/login/sso/redirect/:idp_id", - stable_path: "/_matrix/client/v3/login/sso/redirect/:idp_id", - rate_limited: false, - authentication: None, - added: 1.1, + const METADATA: Metadata = metadata! { + description: "Get the SSO login identity provider url.", + method: GET, + name: "sso_login_with_provider", + rate_limited: false, + authentication: None, + history: { + unstable => "/_matrix/client/unstable/org.matrix.msc2858/login/sso/redirect/:idp_id", + 1.1 => "/_matrix/client/v3/login/sso/redirect/:idp_id", } + }; - request: { - /// The ID of the provider to use for SSO login. - #[ruma_api(path)] - pub idp_id: &'a str, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The ID of the provider to use for SSO login. + #[ruma_api(path)] + pub idp_id: &'a str, - /// URL to which the homeserver should return the user after completing - /// authentication with the SSO identity provider. - #[ruma_api(query)] - #[serde(rename = "redirectUrl")] - pub redirect_url: &'a str, - } + /// URL to which the homeserver should return the user after completing + /// authentication with the SSO identity provider. + #[ruma_api(query)] + #[serde(rename = "redirectUrl")] + pub redirect_url: &'a str, + } - response: { - /// Redirect URL to the SSO identity provider. - #[ruma_api(header = LOCATION)] - pub location: String, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// Redirect URL to the SSO identity provider. + #[ruma_api(header = LOCATION)] + pub location: String, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/space/get_hierarchy.rs b/crates/ruma-client-api/src/space/get_hierarchy.rs index f93a6e75..ed5b3c23 100644 --- a/crates/ruma-client-api/src/space/get_hierarchy.rs +++ b/crates/ruma-client-api/src/space/get_hierarchy.rs @@ -6,66 +6,69 @@ pub mod v1 { //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv1roomsroomidhierarchy use js_int::UInt; - use ruma_common::{api::ruma_api, RoomId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, RoomId, + }; use crate::space::SpaceHierarchyRoomsChunk; - ruma_api! { - metadata: { - description: "Paginates over the space tree in a depth-first manner to locate child rooms of a given space.", - method: GET, - name: "hierarchy", - unstable_path: "/_matrix/client/unstable/org.matrix.msc2946/rooms/:room_id/hierarchy", - stable_path: "/_matrix/client/v1/rooms/:room_id/hierarchy", - rate_limited: true, - authentication: AccessToken, - added: 1.2, + const METADATA: Metadata = metadata! { + description: "Paginates over the space tree in a depth-first manner to locate child rooms of a given space.", + method: GET, + name: "hierarchy", + rate_limited: true, + authentication: AccessToken, + history: { + unstable => "/_matrix/client/unstable/org.matrix.msc2946/rooms/:room_id/hierarchy", + 1.2 => "/_matrix/client/v1/rooms/:room_id/hierarchy", } + }; - request: { - /// The room ID of the space to get a hierarchy for. - #[ruma_api(path)] - pub room_id: &'a RoomId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The room ID of the space to get a hierarchy for. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// A pagination token from a previous result. - /// - /// If specified, `max_depth` and `suggested_only` cannot be changed from the first request. - #[ruma_api(query)] - pub from: Option<&'a str>, + /// A pagination token from a previous result. + /// + /// If specified, `max_depth` and `suggested_only` cannot be changed from the first + /// request. + #[ruma_api(query)] + pub from: Option<&'a str>, - /// The maximum number of rooms to include per response. - #[ruma_api(query)] - pub limit: Option, + /// The maximum number of rooms to include per response. + #[ruma_api(query)] + pub limit: Option, - /// How far to go into the space. - /// - /// When reached, no further child rooms will be returned. - #[ruma_api(query)] - pub max_depth: Option, + /// How far to go into the space. + /// + /// When reached, no further child rooms will be returned. + #[ruma_api(query)] + pub max_depth: Option, - /// Whether or not the server should only consider suggested rooms. - /// - /// Suggested rooms are annotated in their `m.space.child` event contents. - /// - /// Defaults to `false`. - #[ruma_api(query)] - #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")] - pub suggested_only: bool, - } + /// Whether or not the server should only consider suggested rooms. + /// + /// Suggested rooms are annotated in their `m.space.child` event contents. + /// + /// Defaults to `false`. + #[ruma_api(query)] + #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")] + pub suggested_only: bool, + } - #[derive(Default)] - response: { - /// A token to supply to from to keep paginating the responses. - /// - /// Not present when there are no further results. - #[serde(skip_serializing_if = "Option::is_none")] - pub next_batch: Option, + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response { + /// A token to supply to from to keep paginating the responses. + /// + /// Not present when there are no further results. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_batch: Option, - /// A paginated chunk of the space children. - pub rooms: Vec, - } - - error: crate::Error + /// A paginated chunk of the space children. + pub rooms: Vec, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/state/get_state_events.rs b/crates/ruma-client-api/src/state/get_state_events.rs index b71bce01..5cce89f2 100644 --- a/crates/ruma-client-api/src/state/get_state_events.rs +++ b/crates/ruma-client-api/src/state/get_state_events.rs @@ -5,37 +5,42 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3roomsroomidstate - use ruma_common::{api::ruma_api, events::AnyStateEvent, serde::Raw, RoomId}; + use ruma_common::{ + api::{request, response, Metadata}, + events::AnyStateEvent, + metadata, + serde::Raw, + RoomId, + }; - ruma_api! { - metadata: { - description: "Get state events for a room.", - method: GET, - name: "get_state_events", - r0_path: "/_matrix/client/r0/rooms/:room_id/state", - stable_path: "/_matrix/client/v3/rooms/:room_id/state", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Get state events for a room.", + method: GET, + name: "get_state_events", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/rooms/:room_id/state", + 1.1 => "/_matrix/client/v3/rooms/:room_id/state", } + }; - request: { - /// The room to look up the state for. - #[ruma_api(path)] - pub room_id: &'a RoomId, - } + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The room to look up the state for. + #[ruma_api(path)] + pub room_id: &'a RoomId, + } - response: { - /// If the user is a member of the room this will be the current state of the room as a - /// list of events. - /// - /// If the user has left the room then this will be the state of the room when they left as - /// a list of events. - #[ruma_api(body)] - pub room_state: Vec>, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// If the user is a member of the room this will be the current state of the room as a + /// list of events. + /// + /// If the user has left the room then this will be the state of the room when they left as + /// a list of events. + #[ruma_api(body)] + pub room_state: Vec>, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/state/get_state_events_for_key.rs b/crates/ruma-client-api/src/state/get_state_events_for_key.rs index 83f4c5af..dfb2782d 100644 --- a/crates/ruma-client-api/src/state/get_state_events_for_key.rs +++ b/crates/ruma-client-api/src/state/get_state_events_for_key.rs @@ -6,34 +6,33 @@ pub mod v3 { //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3roomsroomidstateeventtypestatekey use ruma_common::{ - api::ruma_api, + api::{response, Metadata}, events::{AnyStateEventContent, StateEventType}, + metadata, serde::{Incoming, Raw}, RoomId, }; - ruma_api! { - metadata: { - description: "Get state events associated with a given key.", - method: GET, - name: "get_state_events_for_key", - r0_path: "/_matrix/client/r0/rooms/:room_id/state/:event_type/:state_key", - stable_path: "/_matrix/client/v3/rooms/:room_id/state/:event_type/:state_key", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Get state events associated with a given key.", + method: GET, + name: "get_state_events_for_key", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/rooms/:room_id/state/:event_type/:state_key", + 1.1 => "/_matrix/client/v3/rooms/:room_id/state/:event_type/:state_key", } + }; - response: { - /// The content of the state event. - /// - /// Since the inner type of the `Raw` does not implement `Deserialize`, you need to use - /// [`Raw::deserialize_content`] to deserialize it. - #[ruma_api(body)] - pub content: Raw, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// The content of the state event. + /// + /// Since the inner type of the `Raw` does not implement `Deserialize`, you need to use + /// [`Raw::deserialize_content`] to deserialize it. + #[ruma_api(body)] + pub content: Raw, } /// Data for a request to the `get_state_events_for_key` API endpoint. @@ -72,7 +71,7 @@ pub mod v3 { type EndpointError = crate::Error; type IncomingResponse = Response; - const METADATA: ruma_common::api::Metadata = METADATA; + const METADATA: Metadata = METADATA; fn try_into_http_request( self, @@ -110,7 +109,7 @@ pub mod v3 { type EndpointError = crate::Error; type OutgoingResponse = Response; - const METADATA: ruma_common::api::Metadata = METADATA; + const METADATA: Metadata = METADATA; fn try_from_http_request( _request: http::Request, diff --git a/crates/ruma-client-api/src/state/send_state_event.rs b/crates/ruma-client-api/src/state/send_state_event.rs index 156eb2f9..87dc95ae 100644 --- a/crates/ruma-client-api/src/state/send_state_event.rs +++ b/crates/ruma-client-api/src/state/send_state_event.rs @@ -8,31 +8,30 @@ pub mod v3 { use std::borrow::Borrow; use ruma_common::{ - api::ruma_api, + api::{response, Metadata}, events::{AnyStateEventContent, StateEventContent, StateEventType}, + metadata, serde::{Incoming, Raw}, MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId, }; use serde_json::value::to_raw_value as to_raw_json_value; - ruma_api! { - metadata: { - description: "Send a state event to a room associated with a given state key.", - method: PUT, - name: "send_state_event", - r0_path: "/_matrix/client/r0/rooms/:room_id/state/:event_type/:state_key", - stable_path: "/_matrix/client/v3/rooms/:room_id/state/:event_type/:state_key", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Send a state event to a room associated with a given state key.", + method: PUT, + name: "send_state_event", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/rooms/:room_id/state/:event_type/:state_key", + 1.1 => "/_matrix/client/v3/rooms/:room_id/state/:event_type/:state_key", } + }; - response: { - /// A unique identifier for the event. - pub event_id: OwnedEventId, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// A unique identifier for the event. + pub event_id: OwnedEventId, } /// Data for a request to the `send_state_event` API endpoint. @@ -114,7 +113,7 @@ pub mod v3 { type EndpointError = crate::Error; type IncomingResponse = Response; - const METADATA: ruma_common::api::Metadata = METADATA; + const METADATA: Metadata = METADATA; fn try_into_http_request( self, @@ -157,7 +156,7 @@ pub mod v3 { type EndpointError = crate::Error; type OutgoingResponse = Response; - const METADATA: ruma_common::api::Metadata = METADATA; + const METADATA: Metadata = METADATA; fn try_from_http_request( request: http::Request, diff --git a/crates/ruma-client-api/src/sync/sync_events/v3.rs b/crates/ruma-client-api/src/sync/sync_events/v3.rs index 68e051e2..3db8c5d6 100644 --- a/crates/ruma-client-api/src/sync/sync_events/v3.rs +++ b/crates/ruma-client-api/src/sync/sync_events/v3.rs @@ -7,12 +7,13 @@ use std::{collections::BTreeMap, time::Duration}; use super::{DeviceLists, UnreadNotificationsCount}; use js_int::UInt; use ruma_common::{ - api::ruma_api, + api::{request, response, Metadata}, events::{ presence::PresenceEvent, AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, AnyStrippedStateEvent, AnySyncEphemeralRoomEvent, AnySyncStateEvent, AnySyncTimelineEvent, AnyToDeviceEvent, }, + metadata, presence::PresenceState, serde::{Incoming, Raw}, DeviceKeyAlgorithm, OwnedEventId, OwnedRoomId, @@ -21,95 +22,94 @@ use serde::{Deserialize, Serialize}; use crate::filter::{FilterDefinition, IncomingFilterDefinition}; -ruma_api! { - metadata: { - description: "Get all new events from all rooms since the last sync or a given point of time.", - method: GET, - name: "sync", - r0_path: "/_matrix/client/r0/sync", - stable_path: "/_matrix/client/v3/sync", - rate_limited: false, - authentication: AccessToken, - added: 1.0, +const METADATA: Metadata = metadata! { + description: "Get all new events from all rooms since the last sync or a given point of time.", + method: GET, + name: "sync", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/sync", + 1.1 => "/_matrix/client/v3/sync", } +}; - #[derive(Default)] - request: { - /// A filter represented either as its full JSON definition or the ID of a saved filter. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub filter: Option<&'a Filter<'a>>, +#[request(error = crate::Error)] +#[derive(Default)] +pub struct Request<'a> { + /// A filter represented either as its full JSON definition or the ID of a saved filter. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub filter: Option<&'a Filter<'a>>, - /// A point in time to continue a sync from. - /// - /// Should be a token from the `next_batch` field of a previous `/sync` - /// request. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub since: Option<&'a str>, + /// A point in time to continue a sync from. + /// + /// Should be a token from the `next_batch` field of a previous `/sync` + /// request. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub since: Option<&'a str>, - /// Controls whether to include the full state for all rooms the user is a member of. - #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")] - #[ruma_api(query)] - pub full_state: bool, + /// Controls whether to include the full state for all rooms the user is a member of. + #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")] + #[ruma_api(query)] + pub full_state: bool, - /// Controls whether the client is automatically marked as online by polling this API. - /// - /// Defaults to `PresenceState::Online`. - #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")] - #[ruma_api(query)] - pub set_presence: &'a PresenceState, + /// Controls whether the client is automatically marked as online by polling this API. + /// + /// Defaults to `PresenceState::Online`. + #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")] + #[ruma_api(query)] + pub set_presence: &'a PresenceState, - /// The maximum time to poll in milliseconds before returning this request. - #[serde( - with = "ruma_common::serde::duration::opt_ms", - default, - skip_serializing_if = "Option::is_none", - )] - #[ruma_api(query)] - pub timeout: Option, - } + /// The maximum time to poll in milliseconds before returning this request. + #[serde( + with = "ruma_common::serde::duration::opt_ms", + default, + skip_serializing_if = "Option::is_none" + )] + #[ruma_api(query)] + pub timeout: Option, +} - response: { - /// The batch token to supply in the `since` param of the next `/sync` request. - pub next_batch: String, +#[response(error = crate::Error)] +pub struct Response { + /// The batch token to supply in the `since` param of the next `/sync` request. + pub next_batch: String, - /// Updates to rooms. - #[serde(default, skip_serializing_if = "Rooms::is_empty")] - pub rooms: Rooms, + /// Updates to rooms. + #[serde(default, skip_serializing_if = "Rooms::is_empty")] + pub rooms: Rooms, - /// Updates to the presence status of other users. - #[serde(default, skip_serializing_if = "Presence::is_empty")] - pub presence: Presence, + /// Updates to the presence status of other users. + #[serde(default, skip_serializing_if = "Presence::is_empty")] + pub presence: Presence, - /// The global private data created by this user. - #[serde(default, skip_serializing_if = "GlobalAccountData::is_empty")] - pub account_data: GlobalAccountData, + /// The global private data created by this user. + #[serde(default, skip_serializing_if = "GlobalAccountData::is_empty")] + pub account_data: GlobalAccountData, - /// Messages sent directly between devices. - #[serde(default, skip_serializing_if = "ToDevice::is_empty")] - pub to_device: ToDevice, + /// Messages sent directly between devices. + #[serde(default, skip_serializing_if = "ToDevice::is_empty")] + pub to_device: ToDevice, - /// Information on E2E device updates. - /// - /// Only present on an incremental sync. - #[serde(default, skip_serializing_if = "DeviceLists::is_empty")] - pub device_lists: DeviceLists, + /// Information on E2E device updates. + /// + /// Only present on an incremental sync. + #[serde(default, skip_serializing_if = "DeviceLists::is_empty")] + pub device_lists: DeviceLists, - /// For each key algorithm, the number of unclaimed one-time keys - /// currently held on the server for a device. - #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] - pub device_one_time_keys_count: BTreeMap, + /// For each key algorithm, the number of unclaimed one-time keys + /// currently held on the server for a device. + #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] + pub device_one_time_keys_count: BTreeMap, - /// For each key algorithm, the number of unclaimed one-time keys - /// currently held on the server for a device. - /// - /// The presence of this field indicates that the server supports - /// fallback keys. - pub device_unused_fallback_key_types: Option>, - } - - error: crate::Error + /// For each key algorithm, the number of unclaimed one-time keys + /// currently held on the server for a device. + /// + /// The presence of this field indicates that the server supports + /// fallback keys. + pub device_unused_fallback_key_types: Option>, } impl Request<'_> { diff --git a/crates/ruma-client-api/src/sync/sync_events/v4.rs b/crates/ruma-client-api/src/sync/sync_events/v4.rs index e8b78d8a..05be954a 100644 --- a/crates/ruma-client-api/src/sync/sync_events/v4.rs +++ b/crates/ruma-client-api/src/sync/sync_events/v4.rs @@ -5,91 +5,87 @@ use std::{collections::BTreeMap, time::Duration}; use super::{DeviceLists, UnreadNotificationsCount}; use js_int::UInt; use ruma_common::{ - api::ruma_api, + api::{request, response, Metadata}, events::{ AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent, AnyStrippedStateEvent, AnySyncStateEvent, AnySyncTimelineEvent, AnyToDeviceEvent, RoomEventType, }, + metadata, serde::{duration::opt_ms, Raw}, DeviceKeyAlgorithm, OwnedRoomId, }; use serde::{Deserialize, Serialize}; -ruma_api! { - metadata: { - description: "Get all new events in a sliding window of rooms since the last sync or a given point of time.", - method: POST, - name: "sync", - // added: 1.4, - // stable_path: "/_matrix/client/v4/sync", - unstable_path: "/_matrix/client/unstable/org.matrix.msc3575/sync", - rate_limited: false, - authentication: AccessToken, +const METADATA: Metadata = metadata! { + description: "Get all new events in a sliding window of rooms since the last sync or a given point of time.", + method: POST, + name: "sync", + rate_limited: false, + authentication: AccessToken, + history: { + unstable => "/_matrix/client/unstable/org.matrix.msc3575/sync", + // 1.4 => "/_matrix/client/v4/sync", } +}; - #[derive(Default)] - request: { - /// A point in time to continue a sync from. - /// - /// Should be a token from the `pos` field of a previous `/sync` - /// response. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub pos: Option<&'a str>, +#[request(error = crate::Error)] +#[derive(Default)] +pub struct Request<'a> { + /// A point in time to continue a sync from. + /// + /// Should be a token from the `pos` field of a previous `/sync` + /// response. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub pos: Option<&'a str>, - /// Allows clients to know what request params reached the server, - /// functionally similar to txn IDs on /send for events. - #[serde(skip_serializing_if = "Option::is_none")] - pub txn_id: Option<&'a str>, + /// Allows clients to know what request params reached the server, + /// functionally similar to txn IDs on /send for events. + #[serde(skip_serializing_if = "Option::is_none")] + pub txn_id: Option<&'a str>, - /// The maximum time to poll before responding to this request. - #[serde( - with = "opt_ms", - default, - skip_serializing_if = "Option::is_none", - )] - #[ruma_api(query)] - pub timeout: Option, + /// The maximum time to poll before responding to this request. + #[serde(with = "opt_ms", default, skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub timeout: Option, - /// The lists of rooms we're interested in. - pub lists: &'a [SyncRequestList], + /// The lists of rooms we're interested in. + pub lists: &'a [SyncRequestList], - /// Specific rooms and event types that we want to receive events from. - #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] - pub room_subscriptions: BTreeMap, + /// Specific rooms and event types that we want to receive events from. + #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] + pub room_subscriptions: BTreeMap, - /// Specific rooms we no longer want to receive events from. - #[serde(default, skip_serializing_if = "<[_]>::is_empty")] - pub unsubscribe_rooms: &'a [OwnedRoomId], + /// Specific rooms we no longer want to receive events from. + #[serde(default, skip_serializing_if = "<[_]>::is_empty")] + pub unsubscribe_rooms: &'a [OwnedRoomId], - /// Extensions API. - #[serde(default, skip_serializing_if = "ExtensionsConfig::is_empty")] - pub extensions: ExtensionsConfig, - } + /// Extensions API. + #[serde(default, skip_serializing_if = "ExtensionsConfig::is_empty")] + pub extensions: ExtensionsConfig, +} - response: { - /// Whether this response describes an initial sync (i.e. after the `pos` token has been - /// discard by the server?). - #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")] - pub initial: bool, +#[response(error = crate::Error)] +pub struct Response { + /// Whether this response describes an initial sync (i.e. after the `pos` token has been + /// discard by the server?). + #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")] + pub initial: bool, - /// The token to supply in the `pos` param of the next `/sync` request. - pub pos: String, + /// The token to supply in the `pos` param of the next `/sync` request. + pub pos: String, - /// Updates to the sliding room list. - #[serde(default, skip_serializing_if = "Vec::is_empty")] - pub lists: Vec, + /// Updates to the sliding room list. + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub lists: Vec, - /// The updates on rooms. - #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] - pub rooms: BTreeMap, + /// The updates on rooms. + #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] + pub rooms: BTreeMap, - /// Extensions API. - #[serde(default, skip_serializing_if = "Extensions::is_empty")] - pub extensions: Extensions, - } - - error: crate::Error + /// Extensions API. + #[serde(default, skip_serializing_if = "Extensions::is_empty")] + pub extensions: Extensions, } impl Request<'_> { diff --git a/crates/ruma-client-api/src/tag/create_tag.rs b/crates/ruma-client-api/src/tag/create_tag.rs index b21a2aaf..fb14bf0d 100644 --- a/crates/ruma-client-api/src/tag/create_tag.rs +++ b/crates/ruma-client-api/src/tag/create_tag.rs @@ -5,44 +5,47 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#put_matrixclientv3useruseridroomsroomidtagstag - use ruma_common::{api::ruma_api, events::tag::TagInfo, RoomId, UserId}; + use ruma_common::{ + api::{request, response, Metadata}, + events::tag::TagInfo, + metadata, RoomId, UserId, + }; - ruma_api! { - metadata: { - description: "Add a new tag to a room.", - method: PUT, - name: "create_tag", - r0_path: "/_matrix/client/r0/user/:user_id/rooms/:room_id/tags/:tag", - stable_path: "/_matrix/client/v3/user/:user_id/rooms/:room_id/tags/:tag", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Add a new tag to a room.", + method: PUT, + name: "create_tag", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/user/:user_id/rooms/:room_id/tags/:tag", + 1.1 => "/_matrix/client/v3/user/:user_id/rooms/:room_id/tags/:tag", } + }; - request: { - /// The ID of the user creating the tag. - #[ruma_api(path)] - pub user_id: &'a UserId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The ID of the user creating the tag. + #[ruma_api(path)] + pub user_id: &'a UserId, - /// The room to tag. - #[ruma_api(path)] - pub room_id: &'a RoomId, + /// The room to tag. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The name of the tag to create. - #[ruma_api(path)] - pub tag: &'a str, + /// The name of the tag to create. + #[ruma_api(path)] + pub tag: &'a str, - /// Info about the tag. - #[ruma_api(body)] - pub tag_info: TagInfo, - } - - #[derive(Default)] - response: {} - - error: crate::Error + /// Info about the tag. + #[ruma_api(body)] + pub tag_info: TagInfo, } + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given user ID, room ID, tag and tag info. pub fn new( diff --git a/crates/ruma-client-api/src/tag/delete_tag.rs b/crates/ruma-client-api/src/tag/delete_tag.rs index 1cf893a1..3eb1b771 100644 --- a/crates/ruma-client-api/src/tag/delete_tag.rs +++ b/crates/ruma-client-api/src/tag/delete_tag.rs @@ -5,40 +5,42 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#put_matrixclientv3useruseridroomsroomidtagstag - use ruma_common::{api::ruma_api, RoomId, UserId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, RoomId, UserId, + }; - ruma_api! { - metadata: { - description: "Remove a tag from a room.", - method: DELETE, - name: "delete_tag", - r0_path: "/_matrix/client/r0/user/:user_id/rooms/:room_id/tags/:tag", - stable_path: "/_matrix/client/v3/user/:user_id/rooms/:room_id/tags/:tag", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Remove a tag from a room.", + method: DELETE, + name: "delete_tag", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/user/:user_id/rooms/:room_id/tags/:tag", + 1.1 => "/_matrix/client/v3/user/:user_id/rooms/:room_id/tags/:tag", } + }; - request: { - /// The user whose tag will be deleted. - #[ruma_api(path)] - pub user_id: &'a UserId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The user whose tag will be deleted. + #[ruma_api(path)] + pub user_id: &'a UserId, - /// The tagged room. - #[ruma_api(path)] - pub room_id: &'a RoomId, + /// The tagged room. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The name of the tag to delete. - #[ruma_api(path)] - pub tag: &'a str, - } - - #[derive(Default)] - response: {} - - error: crate::Error + /// The name of the tag to delete. + #[ruma_api(path)] + pub tag: &'a str, } + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given user ID, room ID and tag pub fn new(user_id: &'a UserId, room_id: &'a RoomId, tag: &'a str) -> Self { diff --git a/crates/ruma-client-api/src/tag/get_tags.rs b/crates/ruma-client-api/src/tag/get_tags.rs index f1f64fdd..9c8c1f84 100644 --- a/crates/ruma-client-api/src/tag/get_tags.rs +++ b/crates/ruma-client-api/src/tag/get_tags.rs @@ -5,36 +5,39 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3useruseridroomsroomidtags - use ruma_common::{api::ruma_api, events::tag::Tags, RoomId, UserId}; + use ruma_common::{ + api::{request, response, Metadata}, + events::tag::Tags, + metadata, RoomId, UserId, + }; - ruma_api! { - metadata: { - description: "Get the tags associated with a room.", - method: GET, - name: "get_tags", - r0_path: "/_matrix/client/r0/user/:user_id/rooms/:room_id/tags", - stable_path: "/_matrix/client/v3/user/:user_id/rooms/:room_id/tags", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Get the tags associated with a room.", + method: GET, + name: "get_tags", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/user/:user_id/rooms/:room_id/tags", + 1.1 => "/_matrix/client/v3/user/:user_id/rooms/:room_id/tags", } + }; - request: { - /// The user whose tags will be retrieved. - #[ruma_api(path)] - pub user_id: &'a UserId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The user whose tags will be retrieved. + #[ruma_api(path)] + pub user_id: &'a UserId, - /// The room from which tags will be retrieved. - #[ruma_api(path)] - pub room_id: &'a RoomId, - } + /// The room from which tags will be retrieved. + #[ruma_api(path)] + pub room_id: &'a RoomId, + } - response: { - /// The user's tags for the room. - pub tags: Tags, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// The user's tags for the room. + pub tags: Tags, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/thirdparty/get_location_for_protocol.rs b/crates/ruma-client-api/src/thirdparty/get_location_for_protocol.rs index 53a248f5..366b36b2 100644 --- a/crates/ruma-client-api/src/thirdparty/get_location_for_protocol.rs +++ b/crates/ruma-client-api/src/thirdparty/get_location_for_protocol.rs @@ -7,38 +7,41 @@ pub mod v3 { use std::collections::BTreeMap; - use ruma_common::{api::ruma_api, thirdparty::Location}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + thirdparty::Location, + }; - ruma_api! { - metadata: { - description: "Fetches third party locations for a protocol.", - method: GET, - name: "get_location_for_protocol", - r0_path: "/_matrix/client/r0/thirdparty/location/:protocol", - stable_path: "/_matrix/client/v3/thirdparty/location/:protocol", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Fetches third party locations for a protocol.", + method: GET, + name: "get_location_for_protocol", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/thirdparty/location/:protocol", + 1.1 => "/_matrix/client/v3/thirdparty/location/:protocol", } + }; - request: { - /// The protocol used to communicate to the third party network. - #[ruma_api(path)] - pub protocol: &'a str, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The protocol used to communicate to the third party network. + #[ruma_api(path)] + pub protocol: &'a str, - /// One or more custom fields to help identify the third party location. - // The specification is incorrect for this parameter. See [matrix-spec#560](https://github.com/matrix-org/matrix-spec/issues/560). - #[ruma_api(query_map)] - pub fields: BTreeMap, - } + /// One or more custom fields to help identify the third party location. + // The specification is incorrect for this parameter. See [matrix-spec#560](https://github.com/matrix-org/matrix-spec/issues/560). + #[ruma_api(query_map)] + pub fields: BTreeMap, + } - response: { - /// List of matched third party locations. - #[ruma_api(body)] - pub locations: Vec, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// List of matched third party locations. + #[ruma_api(body)] + pub locations: Vec, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/thirdparty/get_location_for_room_alias.rs b/crates/ruma-client-api/src/thirdparty/get_location_for_room_alias.rs index dcfb2f6c..ad177329 100644 --- a/crates/ruma-client-api/src/thirdparty/get_location_for_room_alias.rs +++ b/crates/ruma-client-api/src/thirdparty/get_location_for_room_alias.rs @@ -5,33 +5,37 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3thirdpartylocation - use ruma_common::{api::ruma_api, thirdparty::Location, RoomAliasId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + thirdparty::Location, + RoomAliasId, + }; - ruma_api! { - metadata: { - description: "Retrieve an array of third party network locations from a Matrix room alias.", - method: GET, - name: "get_location_for_room_alias", - r0_path: "/_matrix/client/r0/thirdparty/location", - stable_path: "/_matrix/client/v3/thirdparty/location", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Retrieve an array of third party network locations from a Matrix room alias.", + method: GET, + name: "get_location_for_room_alias", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/thirdparty/location", + 1.1 => "/_matrix/client/v3/thirdparty/location", } + }; - request: { - /// The Matrix room alias to look up. - #[ruma_api(query)] - pub alias: &'a RoomAliasId, - } + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The Matrix room alias to look up. + #[ruma_api(query)] + pub alias: &'a RoomAliasId, + } - response: { - /// List of matched third party locations. - #[ruma_api(body)] - pub locations: Vec, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// List of matched third party locations. + #[ruma_api(body)] + pub locations: Vec, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/thirdparty/get_protocol.rs b/crates/ruma-client-api/src/thirdparty/get_protocol.rs index b3a60e90..b24836c0 100644 --- a/crates/ruma-client-api/src/thirdparty/get_protocol.rs +++ b/crates/ruma-client-api/src/thirdparty/get_protocol.rs @@ -5,33 +5,36 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3thirdpartyprotocolprotocol - use ruma_common::{api::ruma_api, thirdparty::Protocol}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + thirdparty::Protocol, + }; - ruma_api! { - metadata: { - description: "Fetches the metadata from the homeserver about a particular third party protocol.", - method: GET, - name: "get_protocol", - r0_path: "/_matrix/client/r0/thirdparty/protocol/:protocol", - stable_path: "/_matrix/client/v3/thirdparty/protocol/:protocol", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Fetches the metadata from the homeserver about a particular third party protocol.", + method: GET, + name: "get_protocol", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/thirdparty/protocol/:protocol", + 1.1 => "/_matrix/client/v3/thirdparty/protocol/:protocol", } + }; - request: { - /// The name of the protocol. - #[ruma_api(path)] - pub protocol: &'a str, - } + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The name of the protocol. + #[ruma_api(path)] + pub protocol: &'a str, + } - response: { - /// Metadata about the protocol. - #[ruma_api(body)] - pub protocol: Protocol, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// Metadata about the protocol. + #[ruma_api(body)] + pub protocol: Protocol, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/thirdparty/get_protocols.rs b/crates/ruma-client-api/src/thirdparty/get_protocols.rs index a545993b..be9d728e 100644 --- a/crates/ruma-client-api/src/thirdparty/get_protocols.rs +++ b/crates/ruma-client-api/src/thirdparty/get_protocols.rs @@ -7,30 +7,33 @@ pub mod v3 { use std::collections::BTreeMap; - use ruma_common::{api::ruma_api, thirdparty::Protocol}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + thirdparty::Protocol, + }; - ruma_api! { - metadata: { - description: "Fetches the overall metadata about protocols supported by the homeserver.", - method: GET, - name: "get_protocols", - r0_path: "/_matrix/client/r0/thirdparty/protocols", - stable_path: "/_matrix/client/v3/thirdparty/protocols", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Fetches the overall metadata about protocols supported by the homeserver.", + method: GET, + name: "get_protocols", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/thirdparty/protocols", + 1.1 => "/_matrix/client/v3/thirdparty/protocols", } + }; - #[derive(Default)] - request: {} + #[request(error = crate::Error)] + #[derive(Default)] + pub struct Request {} - response: { - /// Metadata about protocols supported by the homeserver. - #[ruma_api(body)] - pub protocols: BTreeMap, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// Metadata about protocols supported by the homeserver. + #[ruma_api(body)] + pub protocols: BTreeMap, } impl Request { diff --git a/crates/ruma-client-api/src/thirdparty/get_user_for_protocol.rs b/crates/ruma-client-api/src/thirdparty/get_user_for_protocol.rs index ffee5730..c4685e9c 100644 --- a/crates/ruma-client-api/src/thirdparty/get_user_for_protocol.rs +++ b/crates/ruma-client-api/src/thirdparty/get_user_for_protocol.rs @@ -7,38 +7,41 @@ pub mod v3 { use std::collections::BTreeMap; - use ruma_common::{api::ruma_api, thirdparty::User}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + thirdparty::User, + }; - ruma_api! { - metadata: { - description: "Fetches third party users for a protocol.", - method: GET, - name: "get_user_for_protocol", - r0_path: "/_matrix/client/r0/thirdparty/user/:protocol", - stable_path: "/_matrix/client/v3/thirdparty/user/:protocol", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Fetches third party users for a protocol.", + method: GET, + name: "get_user_for_protocol", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/thirdparty/user/:protocol", + 1.1 => "/_matrix/client/v3/thirdparty/user/:protocol", } + }; - request: { - /// The protocol used to communicate to the third party network. - #[ruma_api(path)] - pub protocol: &'a str, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The protocol used to communicate to the third party network. + #[ruma_api(path)] + pub protocol: &'a str, - /// One or more custom fields that are passed to the AS to help identify the user. - // The specification is incorrect for this parameter. See [matrix-spec#560](https://github.com/matrix-org/matrix-spec/issues/560). - #[ruma_api(query_map)] - pub fields: BTreeMap, - } + /// One or more custom fields that are passed to the AS to help identify the user. + // The specification is incorrect for this parameter. See [matrix-spec#560](https://github.com/matrix-org/matrix-spec/issues/560). + #[ruma_api(query_map)] + pub fields: BTreeMap, + } - response: { - /// List of matched third party users. - #[ruma_api(body)] - pub users: Vec, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// List of matched third party users. + #[ruma_api(body)] + pub users: Vec, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/thirdparty/get_user_for_user_id.rs b/crates/ruma-client-api/src/thirdparty/get_user_for_user_id.rs index 1d988be9..a1926c50 100644 --- a/crates/ruma-client-api/src/thirdparty/get_user_for_user_id.rs +++ b/crates/ruma-client-api/src/thirdparty/get_user_for_user_id.rs @@ -5,33 +5,37 @@ pub mod v3 { //! //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#get_matrixclientv3thirdpartyuser - use ruma_common::{api::ruma_api, thirdparty::User, UserId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + thirdparty::User, + UserId, + }; - ruma_api! { - metadata: { - description: "Retrieve an array of third party users from a Matrix User ID.", - method: GET, - name: "get_user_for_user_id", - r0_path: "/_matrix/client/r0/thirdparty/user", - stable_path: "/_matrix/client/v3/thirdparty/user", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Retrieve an array of third party users from a Matrix User ID.", + method: GET, + name: "get_user_for_user_id", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/thirdparty/user", + 1.1 => "/_matrix/client/v3/thirdparty/user", } + }; - request: { - /// The Matrix User ID to look up. - #[ruma_api(query)] - pub userid: &'a UserId, - } + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The Matrix User ID to look up. + #[ruma_api(query)] + pub userid: &'a UserId, + } - response: { - /// List of matched third party users. - #[ruma_api(body)] - pub users: Vec, - } - - error: crate::Error + #[response(error = crate::Error)] + pub struct Response { + /// List of matched third party users. + #[ruma_api(body)] + pub users: Vec, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/threads/get_threads.rs b/crates/ruma-client-api/src/threads/get_threads.rs index cf8d52fb..2b0eb6e6 100644 --- a/crates/ruma-client-api/src/threads/get_threads.rs +++ b/crates/ruma-client-api/src/threads/get_threads.rs @@ -9,67 +9,67 @@ pub mod v1 { use js_int::UInt; use ruma_common::{ - api::ruma_api, + api::{request, response, Metadata}, events::AnyTimelineEvent, + metadata, serde::{Raw, StringEnum}, RoomId, }; use crate::PrivOwnedStr; - ruma_api! { - metadata: { - description: "Retrieve a list of threads in a room, with optional filters.", - method: GET, - name: "get_thread_roots", - unstable_path: "/_matrix/client/unstable/org.matrix.msc3856/rooms/:room_id/threads", - stable_path: "/_matrix/client/v1/rooms/:room_id/threads", - rate_limited: true, - authentication: AccessToken, - added: 1.4, + const METADATA: Metadata = metadata! { + description: "Retrieve a list of threads in a room, with optional filters.", + method: GET, + name: "get_thread_roots", + rate_limited: true, + authentication: AccessToken, + history: { + unstable => "/_matrix/client/unstable/org.matrix.msc3856/rooms/:room_id/threads", + 1.4 => "/_matrix/client/v1/rooms/:room_id/threads", } + }; - request: { - /// The room ID where the thread roots are located. - #[ruma_api(path)] - pub room_id: &'a RoomId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The room ID where the thread roots are located. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The pagination token to start returning results from. - /// - /// If `None`, results start at the most recent topological event visible to the user. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub from: Option<&'a str>, + /// The pagination token to start returning results from. + /// + /// If `None`, results start at the most recent topological event visible to the user. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub from: Option<&'a str>, - /// Which thread roots are of interest to the caller. - #[serde(skip_serializing_if = "ruma_common::serde::is_default")] - #[ruma_api(query)] - pub include: IncludeThreads, + /// Which thread roots are of interest to the caller. + #[serde(skip_serializing_if = "ruma_common::serde::is_default")] + #[ruma_api(query)] + pub include: IncludeThreads, - /// The maximum number of results to return in a single `chunk`. - /// - /// Servers should apply a default value, and impose a maximum value to avoid resource - /// exhaustion. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub limit: Option, - } + /// The maximum number of results to return in a single `chunk`. + /// + /// Servers should apply a default value, and impose a maximum value to avoid resource + /// exhaustion. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub limit: Option, + } - response: { - /// The thread roots, ordered by the `latest_event` in each event's aggregation bundle. - /// - /// All events returned include bundled aggregations. - pub chunk: Vec>, + #[response(error = crate::Error)] + pub struct Response { + /// The thread roots, ordered by the `latest_event` in each event's aggregation bundle. + /// + /// All events returned include bundled aggregations. + pub chunk: Vec>, - /// An opaque string to provide to `from` to keep paginating the responses. - /// - /// If this is `None`, there are no more results to fetch and the client should stop - /// paginating. - #[serde(skip_serializing_if = "Option::is_none")] - pub next_batch: Option, - } - - error: crate::Error + /// An opaque string to provide to `from` to keep paginating the responses. + /// + /// If this is `None`, there are no more results to fetch and the client should stop + /// paginating. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_batch: Option, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/to_device/send_event_to_device.rs b/crates/ruma-client-api/src/to_device/send_event_to_device.rs index b0c62942..cf2c2e1e 100644 --- a/crates/ruma-client-api/src/to_device/send_event_to_device.rs +++ b/crates/ruma-client-api/src/to_device/send_event_to_device.rs @@ -8,52 +8,55 @@ pub mod v3 { use std::collections::BTreeMap; use ruma_common::{ - api::ruma_api, events::AnyToDeviceEventContent, serde::Raw, - to_device::DeviceIdOrAllDevices, OwnedUserId, TransactionId, + api::{request, response, Metadata}, + events::AnyToDeviceEventContent, + metadata, + serde::Raw, + to_device::DeviceIdOrAllDevices, + OwnedUserId, TransactionId, }; - ruma_api! { - metadata: { - description: "Send an event to a device or devices.", - method: PUT, - name: "send_event_to_device", - r0_path: "/_matrix/client/r0/sendToDevice/:event_type/:txn_id", - stable_path: "/_matrix/client/v3/sendToDevice/:event_type/:txn_id", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Send an event to a device or devices.", + method: PUT, + name: "send_event_to_device", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/sendToDevice/:event_type/:txn_id", + 1.1 => "/_matrix/client/v3/sendToDevice/:event_type/:txn_id", } + }; - request: { - /// Type of event being sent to each device. - #[ruma_api(path)] - pub event_type: &'a str, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// Type of event being sent to each device. + #[ruma_api(path)] + pub event_type: &'a str, - /// The transaction ID for this event. - /// - /// Clients should generate a unique ID across requests within the - /// same session. A session is identified by an access token, and - /// persists when the [access token is refreshed]. - /// - /// It will be used by the server to ensure idempotency of requests. - /// - /// [access token is refreshed]: https://spec.matrix.org/v1.4/client-server-api/#refreshing-access-tokens - #[ruma_api(path)] - pub txn_id: &'a TransactionId, + /// The transaction ID for this event. + /// + /// Clients should generate a unique ID across requests within the + /// same session. A session is identified by an access token, and + /// persists when the [access token is refreshed]. + /// + /// It will be used by the server to ensure idempotency of requests. + /// + /// [access token is refreshed]: https://spec.matrix.org/v1.4/client-server-api/#refreshing-access-tokens + #[ruma_api(path)] + pub txn_id: &'a TransactionId, - /// Messages to send. - /// - /// Different message events can be sent to different devices in the same request, but all - /// events within one request must be of the same type. - pub messages: Messages, - } - - #[derive(Default)] - response: {} - - error: crate::Error + /// Messages to send. + /// + /// Different message events can be sent to different devices in the same request, but all + /// events within one request must be of the same type. + pub messages: Messages, } + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given event type, transaction ID and raw messages. pub fn new_raw(event_type: &'a str, txn_id: &'a TransactionId, messages: Messages) -> Self { diff --git a/crates/ruma-client-api/src/typing/create_typing_event.rs b/crates/ruma-client-api/src/typing/create_typing_event.rs index b89beaeb..91c12d0d 100644 --- a/crates/ruma-client-api/src/typing/create_typing_event.rs +++ b/crates/ruma-client-api/src/typing/create_typing_event.rs @@ -7,41 +7,43 @@ pub mod v3 { use std::time::Duration; - use ruma_common::{api::ruma_api, RoomId, UserId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, RoomId, UserId, + }; use serde::{de::Error, Deserialize, Deserializer, Serialize}; - ruma_api! { - metadata: { - method: PUT, - r0_path: "/_matrix/client/r0/rooms/:room_id/typing/:user_id", - stable_path: "/_matrix/client/v3/rooms/:room_id/typing/:user_id", - name: "create_typing_event", - description: "Send a typing event to a room.", - authentication: AccessToken, - rate_limited: true, - added: 1.0, + const METADATA: Metadata = metadata! { + method: PUT, + name: "create_typing_event", + description: "Send a typing event to a room.", + authentication: AccessToken, + rate_limited: true, + history: { + 1.0 => "/_matrix/client/r0/rooms/:room_id/typing/:user_id", + 1.1 => "/_matrix/client/v3/rooms/:room_id/typing/:user_id", } + }; - request: { - /// The room in which the user is typing. - #[ruma_api(path)] - pub room_id: &'a RoomId, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The room in which the user is typing. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The user who has started to type. - #[ruma_api(path)] - pub user_id: &'a UserId, + /// The user who has started to type. + #[ruma_api(path)] + pub user_id: &'a UserId, - /// Whether the user is typing within a length of time or not. - #[serde(flatten)] - pub state: Typing, - } - - #[derive(Default)] - response: {} - - error: crate::Error + /// Whether the user is typing within a length of time or not. + #[serde(flatten)] + pub state: Typing, } + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given user ID, room ID and typing state. pub fn new(user_id: &'a UserId, room_id: &'a RoomId, state: Typing) -> Self { diff --git a/crates/ruma-client-api/src/uiaa/get_uiaa_fallback_page.rs b/crates/ruma-client-api/src/uiaa/get_uiaa_fallback_page.rs index c86cf4d8..32967c80 100644 --- a/crates/ruma-client-api/src/uiaa/get_uiaa_fallback_page.rs +++ b/crates/ruma-client-api/src/uiaa/get_uiaa_fallback_page.rs @@ -6,47 +6,49 @@ pub mod v3 { //! [spec]: https://spec.matrix.org/v1.4/client-server-api/#fallback use http::header::LOCATION; - use ruma_common::api::ruma_api; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + }; - ruma_api! { - metadata: { - description: "Get UIAA fallback web page.", - method: GET, - name: "authorize_fallback", - r0_path: "/_matrix/client/r0/auth/:auth_type/fallback/web", - stable_path: "/_matrix/client/v3/auth/:auth_type/fallback/web", - rate_limited: false, - authentication: None, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Get UIAA fallback web page.", + method: GET, + name: "authorize_fallback", + rate_limited: false, + authentication: None, + history: { + 1.0 => "/_matrix/client/r0/auth/:auth_type/fallback/web", + 1.1 => "/_matrix/client/v3/auth/:auth_type/fallback/web", } + }; - request: { - /// The type name ("m.login.dummy", etc.) of the uiaa stage to get a fallback page for. - #[ruma_api(path)] - pub auth_type: String, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The type name ("m.login.dummy", etc.) of the uiaa stage to get a fallback page for. + #[ruma_api(path)] + pub auth_type: &'a str, - /// The ID of the session given by the homeserver. - #[ruma_api(query)] - pub session: String, - } - - #[derive(Default)] - response: { - /// Optional URI to redirect to. - #[ruma_api(header = LOCATION)] - pub redirect_url: Option, - - /// HTML to return to client. - #[ruma_api(raw_body)] - pub body: Vec, - } - - error: crate::Error + /// The ID of the session given by the homeserver. + #[ruma_api(query)] + pub session: &'a str, } - impl Request { + #[response(error = crate::Error)] + #[derive(Default)] + pub struct Response { + /// Optional URI to redirect to. + #[ruma_api(header = LOCATION)] + pub redirect_url: Option, + + /// HTML to return to client. + #[ruma_api(raw_body)] + pub body: Vec, + } + + impl<'a> Request<'a> { /// Creates a new `Request` with the given auth type and session ID. - pub fn new(auth_type: String, session: String) -> Self { + pub fn new(auth_type: &'a str, session: &'a str) -> Self { Self { auth_type, session } } } diff --git a/crates/ruma-client-api/src/user_directory/search_users.rs b/crates/ruma-client-api/src/user_directory/search_users.rs index dc7e98c7..3be9fc0d 100644 --- a/crates/ruma-client-api/src/user_directory/search_users.rs +++ b/crates/ruma-client-api/src/user_directory/search_users.rs @@ -7,49 +7,51 @@ pub mod v3 { use http::header::ACCEPT_LANGUAGE; use js_int::{uint, UInt}; - use ruma_common::{api::ruma_api, OwnedMxcUri, OwnedUserId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, OwnedMxcUri, OwnedUserId, + }; use serde::{Deserialize, Serialize}; - ruma_api! { - metadata: { - description: "Performs a search for users.", - method: POST, - name: "search_users", - r0_path: "/_matrix/client/r0/user_directory/search", - stable_path: "/_matrix/client/v3/user_directory/search", - rate_limited: true, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Performs a search for users.", + method: POST, + name: "search_users", + rate_limited: true, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/user_directory/search", + 1.1 => "/_matrix/client/v3/user_directory/search", } + }; - request: { - /// The term to search for. - pub search_term: &'a str, + #[request(error = crate::Error)] + pub struct Request<'a> { + /// The term to search for. + pub search_term: &'a str, - /// The maximum number of results to return. - /// - /// Defaults to 10. - #[serde(default = "default_limit", skip_serializing_if = "is_default_limit")] - pub limit: UInt, + /// The maximum number of results to return. + /// + /// Defaults to 10. + #[serde(default = "default_limit", skip_serializing_if = "is_default_limit")] + pub limit: UInt, - /// Language tag to determine the collation to use for the (case-insensitive) search. - /// - /// See [MDN] for the syntax. - /// - /// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language#Syntax - #[ruma_api(header = ACCEPT_LANGUAGE)] - pub language: Option, - } + /// Language tag to determine the collation to use for the (case-insensitive) search. + /// + /// See [MDN] for the syntax. + /// + /// [MDN]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language#Syntax + #[ruma_api(header = ACCEPT_LANGUAGE)] + pub language: Option, + } - response: { - /// Ordered by rank and then whether or not profile info is available. - pub results: Vec, + #[response(error = crate::Error)] + pub struct Response { + /// Ordered by rank and then whether or not profile info is available. + pub results: Vec, - /// Indicates if the result list has been truncated by the limit. - pub limited: bool, - } - - error: crate::Error + /// Indicates if the result list has been truncated by the limit. + pub limited: bool, } impl<'a> Request<'a> { diff --git a/crates/ruma-client-api/src/voip/get_turn_server_info.rs b/crates/ruma-client-api/src/voip/get_turn_server_info.rs index e6d629c3..e848c6a3 100644 --- a/crates/ruma-client-api/src/voip/get_turn_server_info.rs +++ b/crates/ruma-client-api/src/voip/get_turn_server_info.rs @@ -7,39 +7,41 @@ pub mod v3 { use std::time::Duration; - use ruma_common::api::ruma_api; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + }; - ruma_api! { - metadata: { - description: "Get credentials for the client to use when initiating VoIP calls.", - method: GET, - name: "turn_server_info", - r0_path: "/_matrix/client/r0/voip/turnServer", - stable_path: "/_matrix/client/v3/voip/turnServer", - rate_limited: true, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Get credentials for the client to use when initiating VoIP calls.", + method: GET, + name: "turn_server_info", + rate_limited: true, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/client/r0/voip/turnServer", + 1.1 => "/_matrix/client/v3/voip/turnServer", } + }; - #[derive(Default)] - request: {} + #[request(error = crate::Error)] + #[derive(Default)] + pub struct Request {} - response: { - /// The username to use. - pub username: String, + #[response(error = crate::Error)] + pub struct Response { + /// The username to use. + pub username: String, - /// The password to use. - pub password: String, + /// The password to use. + pub password: String, - /// A list of TURN URIs. - pub uris: Vec, + /// A list of TURN URIs. + pub uris: Vec, - /// The time-to-live in seconds. - #[serde(with = "ruma_common::serde::duration::secs")] - pub ttl: Duration, - } - - error: crate::Error + /// The time-to-live in seconds. + #[serde(with = "ruma_common::serde::duration::secs")] + pub ttl: Duration, } impl Request { diff --git a/crates/ruma-common/src/api.rs b/crates/ruma-common/src/api.rs index 5e32864d..ee0f16fa 100644 --- a/crates/ruma-common/src/api.rs +++ b/crates/ruma-common/src/api.rs @@ -643,9 +643,8 @@ macro_rules! metadata { ( @field authentication: $scheme:ident ) => { $crate::api::AuthScheme::$scheme }; ( @field history: { - $( unstable => $unstable_path:literal ),* - $(, $( $version:literal => $rhs:tt ),+ )? - $(,)? + $( unstable => $unstable_path:literal, )* + $( $( $version:literal => $rhs:tt, )+ )? } ) => { $crate::metadata! { @history_impl @@ -670,7 +669,7 @@ macro_rules! metadata { )? ) => { $crate::api::VersionHistory::new( - &[ $( $unstable_path ),+ ], + &[ $( $unstable_path ),* ], &[ $($( ($crate::api::MatrixVersion::from_lit(stringify!($version)), $stable_path) ),+)? ], diff --git a/crates/ruma-common/tests/api/conversions.rs b/crates/ruma-common/tests/api/conversions.rs index eba71b40..ad68bbc8 100644 --- a/crates/ruma-common/tests/api/conversions.rs +++ b/crates/ruma-common/tests/api/conversions.rs @@ -3,43 +3,52 @@ use http::header::CONTENT_TYPE; use ruma_common::{ api::{ - ruma_api, IncomingRequest as _, MatrixVersion, OutgoingRequest as _, + request, response, IncomingRequest as _, MatrixVersion, Metadata, OutgoingRequest as _, OutgoingRequestAppserviceExt, SendAccessToken, }, - user_id, OwnedUserId, + metadata, user_id, OwnedUserId, }; -ruma_api! { - metadata: { - description: "Does something.", - method: POST, - name: "my_endpoint", - unstable_path: "/_matrix/foo/:bar/:user", - rate_limited: false, - authentication: None, +const METADATA: Metadata = metadata! { + description: "Does something.", + method: POST, + name: "my_endpoint", + rate_limited: false, + authentication: None, + history: { + unstable => "/_matrix/foo/:bar/:user", } +}; - request: { - pub hello: String, - #[ruma_api(header = CONTENT_TYPE)] - pub world: String, - #[ruma_api(query)] - pub q1: String, - #[ruma_api(query)] - pub q2: u32, - #[ruma_api(path)] - pub bar: String, - #[ruma_api(path)] - pub user: OwnedUserId, - } +#[request] +pub struct Request { + pub hello: String, - response: { - pub hello: String, - #[ruma_api(header = CONTENT_TYPE)] - pub world: String, - #[serde(skip_serializing_if = "Option::is_none")] - pub optional_flag: Option, - } + #[ruma_api(header = CONTENT_TYPE)] + pub world: String, + + #[ruma_api(query)] + pub q1: String, + + #[ruma_api(query)] + pub q2: u32, + + #[ruma_api(path)] + pub bar: String, + + #[ruma_api(path)] + pub user: OwnedUserId, +} + +#[response] +pub struct Response { + pub hello: String, + + #[ruma_api(header = CONTENT_TYPE)] + pub world: String, + + #[serde(skip_serializing_if = "Option::is_none")] + pub optional_flag: Option, } #[test] @@ -120,37 +129,49 @@ fn request_with_user_id_serde() { } mod without_query { - use ruma_common::{api::MatrixVersion, OwnedUserId}; + use http::header::CONTENT_TYPE; + use ruma_common::{ + api::{ + request, response, MatrixVersion, Metadata, OutgoingRequestAppserviceExt, + SendAccessToken, + }, + metadata, user_id, OwnedUserId, + }; - use super::{ruma_api, user_id, OutgoingRequestAppserviceExt, SendAccessToken, CONTENT_TYPE}; - - ruma_api! { - metadata: { - description: "Does something without query.", - method: POST, - name: "my_endpoint", - unstable_path: "/_matrix/foo/:bar/:user", - rate_limited: false, - authentication: None, + const METADATA: Metadata = metadata! { + description: "Does something without query.", + method: POST, + name: "my_endpoint", + rate_limited: false, + authentication: None, + history: { + unstable => "/_matrix/foo/:bar/:user", } + }; - request: { - pub hello: String, - #[ruma_api(header = CONTENT_TYPE)] - pub world: String, - #[ruma_api(path)] - pub bar: String, - #[ruma_api(path)] - pub user: OwnedUserId, - } + #[request] + pub struct Request { + pub hello: String, - response: { - pub hello: String, - #[ruma_api(header = CONTENT_TYPE)] - pub world: String, - #[serde(skip_serializing_if = "Option::is_none")] - pub optional_flag: Option, - } + #[ruma_api(header = CONTENT_TYPE)] + pub world: String, + + #[ruma_api(path)] + pub bar: String, + + #[ruma_api(path)] + pub user: OwnedUserId, + } + + #[response] + pub struct Response { + pub hello: String, + + #[ruma_api(header = CONTENT_TYPE)] + pub world: String, + + #[serde(skip_serializing_if = "Option::is_none")] + pub optional_flag: Option, } #[test] diff --git a/crates/ruma-common/tests/api/header_override.rs b/crates/ruma-common/tests/api/header_override.rs index f80a6f33..3fc761fc 100644 --- a/crates/ruma-common/tests/api/header_override.rs +++ b/crates/ruma-common/tests/api/header_override.rs @@ -1,32 +1,38 @@ #![allow(clippy::exhaustive_structs)] use http::header::{Entry, CONTENT_TYPE, LOCATION}; -use ruma_common::api::{ - ruma_api, MatrixVersion, OutgoingRequest as _, OutgoingResponse as _, SendAccessToken, +use ruma_common::{ + api::{ + request, response, MatrixVersion, Metadata, OutgoingRequest as _, OutgoingResponse as _, + SendAccessToken, + }, + metadata, }; -ruma_api! { - metadata: { - description: "Does something.", - method: GET, - name: "no_fields", - unstable_path: "/_matrix/my/endpoint", - rate_limited: false, - authentication: None, +const METADATA: Metadata = metadata! { + description: "Does something.", + method: GET, + name: "no_fields", + rate_limited: false, + authentication: None, + history: { + unstable => "/_matrix/my/endpoint", } +}; - request: { - #[ruma_api(header = LOCATION)] - pub location: Option, +#[request] +pub struct Request { + #[ruma_api(header = LOCATION)] + pub location: Option, - #[ruma_api(header = CONTENT_TYPE)] - pub stuff: String, - } + #[ruma_api(header = CONTENT_TYPE)] + pub stuff: String, +} - response: { - #[ruma_api(header = CONTENT_TYPE)] - pub stuff: String, - } +#[response] +pub struct Response { + #[ruma_api(header = CONTENT_TYPE)] + pub stuff: String, } #[test] diff --git a/crates/ruma-common/tests/api/no_fields.rs b/crates/ruma-common/tests/api/no_fields.rs index be69b41b..bab45224 100644 --- a/crates/ruma-common/tests/api/no_fields.rs +++ b/crates/ruma-common/tests/api/no_fields.rs @@ -3,35 +3,51 @@ use ruma_common::api::{ }; mod get { - ruma_common::api::ruma_api! { - metadata: { - description: "Does something.", - method: GET, - name: "no_fields", - unstable_path: "/_matrix/my/endpoint", - rate_limited: false, - authentication: None, - } + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + }; - request: {} - response: {} - } + const METADATA: Metadata = metadata! { + description: "Does something.", + method: GET, + name: "no_fields", + rate_limited: false, + authentication: None, + history: { + unstable => "/_matrix/my/endpoint", + } + }; + + #[request] + pub struct Request {} + + #[response] + pub struct Response {} } mod post { - ruma_common::api::ruma_api! { - metadata: { - description: "Does something.", - method: POST, - name: "no_fields", - unstable_path: "/_matrix/my/endpoint", - rate_limited: false, - authentication: None, - } + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + }; - request: {} - response: {} - } + const METADATA: Metadata = metadata! { + description: "Does something.", + method: POST, + name: "no_fields", + rate_limited: false, + authentication: None, + history: { + unstable => "/_matrix/my/endpoint", + } + }; + + #[request] + pub struct Request {} + + #[response] + pub struct Response {} } #[test] diff --git a/crates/ruma-common/tests/api/optional_headers.rs b/crates/ruma-common/tests/api/optional_headers.rs index d94193b8..3550a3ca 100644 --- a/crates/ruma-common/tests/api/optional_headers.rs +++ b/crates/ruma-common/tests/api/optional_headers.rs @@ -1,23 +1,28 @@ use http::header::LOCATION; -use ruma_common::api::ruma_api; +use ruma_common::{ + api::{request, response, Metadata}, + metadata, +}; -ruma_api! { - metadata: { - description: "Does something.", - method: GET, - name: "no_fields", - unstable_path: "/_matrix/my/endpoint", - rate_limited: false, - authentication: None, +const METADATA: Metadata = metadata! { + description: "Does something.", + method: GET, + name: "no_fields", + rate_limited: false, + authentication: None, + history: { + unstable => "/_matrix/my/endpoint", } +}; - request: { - #[ruma_api(header = LOCATION)] - pub location: Option, - } - - response: { - #[ruma_api(header = LOCATION)] - pub stuff: Option, - } +#[request] +pub struct Request { + #[ruma_api(header = LOCATION)] + pub location: Option, +} + +#[response] +pub struct Response { + #[ruma_api(header = LOCATION)] + pub stuff: Option, } diff --git a/crates/ruma-common/tests/api/ruma_api.rs b/crates/ruma-common/tests/api/ruma_api.rs index 43493ddb..833fe018 100644 --- a/crates/ruma-common/tests/api/ruma_api.rs +++ b/crates/ruma-common/tests/api/ruma_api.rs @@ -1,13 +1,10 @@ #[test] fn ui() { let t = trybuild::TestCases::new(); - t.pass("tests/api/ui/01-api-sanity-check.rs"); - t.compile_fail("tests/api/ui/02-invalid-path.rs"); - t.pass("tests/api/ui/03-move-value.rs"); - t.compile_fail("tests/api/ui/04-attributes.rs"); - t.pass("tests/api/ui/05-request-only.rs"); - t.pass("tests/api/ui/06-response-only.rs"); - t.compile_fail("tests/api/ui/07-error-type-attribute.rs"); - t.compile_fail("tests/api/ui/08-deprecated-without-added.rs"); - t.compile_fail("tests/api/ui/09-removed-without-deprecated.rs"); + t.pass("tests/api/ui/api-sanity-check.rs"); + t.pass("tests/api/ui/move-value.rs"); + t.pass("tests/api/ui/request-only.rs"); + t.pass("tests/api/ui/response-only.rs"); + t.compile_fail("tests/api/ui/deprecated-without-added.rs"); + t.compile_fail("tests/api/ui/removed-without-deprecated.rs"); } diff --git a/crates/ruma-common/tests/api/ruma_api_lifetime.rs b/crates/ruma-common/tests/api/ruma_api_lifetime.rs index 990d442b..f290780c 100644 --- a/crates/ruma-common/tests/api/ruma_api_lifetime.rs +++ b/crates/ruma-common/tests/api/ruma_api_lifetime.rs @@ -7,156 +7,181 @@ pub struct OtherThing<'t> { } mod empty_response { - use ruma_common::{api::ruma_api, RoomAliasId, RoomId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, RoomAliasId, RoomId, + }; - ruma_api! { - metadata: { - description: "Add an alias to a room.", - method: PUT, - name: "create_alias", - unstable_path: "/_matrix/client/r0/directory/room/:room_alias", - rate_limited: false, - authentication: AccessToken, + const METADATA: Metadata = metadata! { + description: "Add an alias to a room.", + method: PUT, + name: "create_alias", + rate_limited: false, + authentication: AccessToken, + history: { + unstable => "/_matrix/client/r0/directory/room/:room_alias", } + }; - request: { - /// The room alias to set. - #[ruma_api(path)] - pub room_alias: &'a RoomAliasId, + #[request] + pub struct Request<'a> { + /// The room alias to set. + #[ruma_api(path)] + pub room_alias: &'a RoomAliasId, - /// The room ID to set. - pub room_id: &'a RoomId, - } - - response: {} + /// The room ID to set. + pub room_id: &'a RoomId, } + + #[response] + pub struct Response {} } mod nested_types { - use ruma_common::{api::ruma_api, RoomAliasId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, RoomAliasId, + }; - ruma_api! { - metadata: { - description: "Add an alias to a room.", - method: PUT, - name: "create_alias", - unstable_path: "/_matrix/client/r0/directory/room", - rate_limited: false, - authentication: AccessToken, + const METADATA: Metadata = metadata! { + description: "Add an alias to a room.", + method: PUT, + name: "create_alias", + rate_limited: false, + authentication: AccessToken, + history: { + unstable => "/_matrix/client/r0/directory/room", } + }; - request: { - /// The room alias to set. - pub room_alias: &'a [Option<&'a RoomAliasId>], + #[request] + pub struct Request<'a> { + /// The room alias to set. + pub room_alias: &'a [Option<&'a RoomAliasId>], - /// The room ID to set. - pub room_id: &'b [Option>], - } - - response: {} + /// The room ID to set. + pub room_id: &'a [Option>], } + + #[response] + pub struct Response {} } mod full_request_response { use http::header::CONTENT_TYPE; - use ruma_common::api::ruma_api; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + }; use super::{IncomingOtherThing, OtherThing}; - ruma_api! { - metadata: { - description: "Does something.", - method: POST, - name: "no_fields", - unstable_path: "/_matrix/my/endpoint/:thing", - rate_limited: false, - authentication: None, + const METADATA: Metadata = metadata! { + description: "Does something.", + method: POST, + name: "no_fields", + rate_limited: false, + authentication: None, + history: { + unstable => "/_matrix/my/endpoint/:thing", } + }; - request: { - #[ruma_api(query)] - pub abc: &'a str, - #[ruma_api(path)] - pub thing: &'a str, - #[ruma_api(header = CONTENT_TYPE)] - pub stuff: &'a str, - pub more: OtherThing<'t>, - } + #[request] + pub struct Request<'a> { + #[ruma_api(query)] + pub abc: &'a str, + #[ruma_api(path)] + pub thing: &'a str, + #[ruma_api(header = CONTENT_TYPE)] + pub stuff: &'a str, + pub more: OtherThing<'a>, + } - response: { - #[ruma_api(body)] - pub thing: Vec, - #[ruma_api(header = CONTENT_TYPE)] - pub stuff: String, - } + #[response] + pub struct Response { + #[ruma_api(body)] + pub thing: Vec, + #[ruma_api(header = CONTENT_TYPE)] + pub stuff: String, } } mod full_request_response_with_query_map { use http::header::CONTENT_TYPE; - use ruma_common::api::ruma_api; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + }; - ruma_api! { - metadata: { - description: "Does something.", - method: GET, - name: "no_fields", - unstable_path: "/_matrix/my/endpoint/:thing", - rate_limited: false, - authentication: None, + const METADATA: Metadata = metadata! { + description: "Does something.", + method: GET, + name: "no_fields", + rate_limited: false, + authentication: None, + history: { + unstable => "/_matrix/my/endpoint/:thing", } + }; - request: { - #[ruma_api(query_map)] - // pub abc: &'a [(&'a str, &'a str)], // TODO handle this use case - pub abc: Vec<(String, String)>, - #[ruma_api(path)] - pub thing: &'a str, - #[ruma_api(header = CONTENT_TYPE)] - pub stuff: &'a str, - } + #[request] + pub struct Request<'a> { + #[ruma_api(query_map)] + // pub abc: &'a [(&'a str, &'a str)], // TODO handle this use case + pub abc: Vec<(String, String)>, + #[ruma_api(path)] + pub thing: &'a str, + #[ruma_api(header = CONTENT_TYPE)] + pub stuff: &'a str, + } - response: { - #[ruma_api(body)] - pub thing: String, - #[ruma_api(header = CONTENT_TYPE)] - pub stuff: String, - } + #[response] + pub struct Response { + #[ruma_api(body)] + pub thing: String, + #[ruma_api(header = CONTENT_TYPE)] + pub stuff: String, } } mod query_fields { - use ruma_common::api::ruma_api; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + }; - ruma_api! { - metadata: { - description: "Get the list of rooms in this homeserver's public directory.", - method: GET, - name: "get_public_rooms", - unstable_path: "/_matrix/client/r0/publicRooms", - rate_limited: false, - authentication: None, + const METADATA: Metadata = metadata! { + description: "Get the list of rooms in this homeserver's public directory.", + method: GET, + name: "get_public_rooms", + rate_limited: false, + authentication: None, + history: { + unstable => "/_matrix/client/r0/publicRooms", } + }; - request: { - /// Limit for the number of results to return. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub limit: Option, + #[request] + pub struct Request<'a> { + /// Limit for the number of results to return. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub limit: Option, - /// Pagination token from a previous request. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub since: Option<&'a str>, + /// Pagination token from a previous request. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub since: Option<&'a str>, - /// The server to fetch the public room lists from. - /// - /// `None` means the server this request is sent to. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub server: Option<&'a str>, - } - - response: {} + /// The server to fetch the public room lists from. + /// + /// `None` means the server this request is sent to. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub server: Option<&'a str>, } + + #[response] + pub struct Response {} } diff --git a/crates/ruma-common/tests/api/ruma_api_macros.rs b/crates/ruma-common/tests/api/ruma_api_macros.rs index 35eae261..80391b9e 100644 --- a/crates/ruma-common/tests/api/ruma_api_macros.rs +++ b/crates/ruma-common/tests/api/ruma_api_macros.rs @@ -4,139 +4,157 @@ pub mod some_endpoint { use http::header::CONTENT_TYPE; use ruma_common::{ - api::ruma_api, + api::{request, response, Metadata}, events::{tag::TagEvent, AnyTimelineEvent}, + metadata, serde::Raw, OwnedUserId, }; - ruma_api! { - metadata: { - description: "Does something.", - method: POST, // An `http::Method` constant. No imports required. - name: "some_endpoint", - unstable_path: "/_matrix/some/endpoint/:user", - rate_limited: false, - authentication: None, + const METADATA: Metadata = metadata! { + description: "Does something.", + method: POST, // An `http::Method` constant. No imports required. + name: "some_endpoint", + rate_limited: false, + authentication: None, + history: { + unstable => "/_matrix/some/endpoint/:user", } + }; - request: { - // With no attribute on the field, it will be put into the body of the request. - pub a_field: String, + #[request] + pub struct Request { + // With no attribute on the field, it will be put into the body of the request. + pub a_field: String, - // This value will be put into the "Content-Type" HTTP header. - #[ruma_api(header = CONTENT_TYPE)] - pub content_type: String, + // This value will be put into the "Content-Type" HTTP header. + #[ruma_api(header = CONTENT_TYPE)] + pub content_type: String, - // This value will be put into the query string of the request's URL. - #[ruma_api(query)] - pub bar: String, + // This value will be put into the query string of the request's URL. + #[ruma_api(query)] + pub bar: String, - // This value will be inserted into the request's URL in place of the - // ":user" path component. - #[ruma_api(path)] - pub user: OwnedUserId, - } + // This value will be inserted into the request's URL in place of the + // ":user" path component. + #[ruma_api(path)] + pub user: OwnedUserId, + } - response: { - // This value will be extracted from the "Content-Type" HTTP header. - #[ruma_api(header = CONTENT_TYPE)] - pub content_type: String, + #[response] + pub struct Response { + // This value will be extracted from the "Content-Type" HTTP header. + #[ruma_api(header = CONTENT_TYPE)] + pub content_type: String, - // With no attribute on the field, it will be extracted from the body of the response. - pub value: String, + // With no attribute on the field, it will be extracted from the body of the response. + pub value: String, - // You can use serde attributes on any kind of field - #[serde(skip_serializing_if = "Option::is_none")] - pub optional_flag: Option, + // You can use serde attributes on any kind of field + #[serde(skip_serializing_if = "Option::is_none")] + pub optional_flag: Option, - // Use `Raw` instead of the actual event to allow additional fields to be sent... - pub event: Raw, + // Use `Raw` instead of the actual event to allow additional fields to be sent... + pub event: Raw, - // ... and to allow unknown events when the endpoint deals with event collections. - pub list_of_events: Vec>, - } + // ... and to allow unknown events when the endpoint deals with event collections. + pub list_of_events: Vec>, } } pub mod newtype_body_endpoint { - use ruma_common::api::ruma_api; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + }; #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] pub struct MyCustomType { pub a_field: String, } - ruma_api! { - metadata: { - description: "Does something.", - method: PUT, - name: "newtype_body_endpoint", - unstable_path: "/_matrix/some/newtype/body/endpoint", - rate_limited: false, - authentication: None, + const METADATA: Metadata = metadata! { + description: "Does something.", + method: PUT, + name: "newtype_body_endpoint", + rate_limited: false, + authentication: None, + history: { + unstable => "/_matrix/some/newtype/body/endpoint", } + }; - request: { - #[ruma_api(body)] - pub list_of_custom_things: Vec, - } + #[request] + pub struct Request { + #[ruma_api(body)] + pub list_of_custom_things: Vec, + } - response: { - #[ruma_api(body)] - pub my_custom_thing: MyCustomType, - } + #[response] + pub struct Response { + #[ruma_api(body)] + pub my_custom_thing: MyCustomType, } } pub mod raw_body_endpoint { - use ruma_common::api::ruma_api; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + }; #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] pub struct MyCustomType { pub a_field: String, } - ruma_api! { - metadata: { - description: "Does something.", - method: PUT, - name: "newtype_body_endpoint", - unstable_path: "/_matrix/some/newtype/body/endpoint", - rate_limited: false, - authentication: None, + const METADATA: Metadata = metadata! { + description: "Does something.", + method: PUT, + name: "newtype_body_endpoint", + rate_limited: false, + authentication: None, + history: { + unstable => "/_matrix/some/newtype/body/endpoint", } + }; - request: { - #[ruma_api(raw_body)] - pub file: &'a [u8], - } + #[request] + pub struct Request<'a> { + #[ruma_api(raw_body)] + pub file: &'a [u8], + } - response: { - #[ruma_api(raw_body)] - pub file: Vec, - } + #[response] + pub struct Response { + #[ruma_api(raw_body)] + pub file: Vec, } } pub mod query_map_endpoint { - use ruma_common::api::ruma_api; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + }; - ruma_api! { - metadata: { - description: "Does something.", - method: GET, - name: "newtype_body_endpoint", - unstable_path: "/_matrix/some/query/map/endpoint", - rate_limited: false, - authentication: None, + const METADATA: Metadata = metadata! { + description: "Does something.", + method: GET, + name: "newtype_body_endpoint", + rate_limited: false, + authentication: None, + history: { + unstable => "/_matrix/some/query/map/endpoint", } + }; - request: { - #[ruma_api(query_map)] - pub fields: Vec<(String, String)>, - } - - response: {} + #[request] + pub struct Request { + #[ruma_api(query_map)] + pub fields: Vec<(String, String)>, } + + #[response] + pub struct Response {} } diff --git a/crates/ruma-common/tests/api/ui/01-api-sanity-check.rs b/crates/ruma-common/tests/api/ui/01-api-sanity-check.rs deleted file mode 100644 index 0758fb8b..00000000 --- a/crates/ruma-common/tests/api/ui/01-api-sanity-check.rs +++ /dev/null @@ -1,79 +0,0 @@ -use http::header::CONTENT_TYPE; -use ruma_common::{ - api::ruma_api, - events::{tag::TagEvent, AnyTimelineEvent}, - serde::Raw, -}; - -ruma_api! { - metadata: { - description: "Does something.", - method: POST, // An `http::Method` constant. No imports required. - name: "some_endpoint", - unstable_path: "/_matrix/some/msc1234/endpoint/:baz", - r0_path: "/_matrix/some/r0/endpoint/:baz", - stable_path: "/_matrix/some/v3/endpoint/:baz", - rate_limited: false, - authentication: None, - added: 1.0, - deprecated: 1.2, - removed: 1.3, - } - - request: { - // With no attribute on the field, it will be put into the body of the request. - pub foo: String, - - // This value will be put into the "Content-Type" HTTP header. - #[ruma_api(header = CONTENT_TYPE)] - pub content_type: String, - - // This value will be put into the query string of the request's URL. - #[ruma_api(query)] - pub bar: String, - - // This value will be inserted into the request's URL in place of the - // ":baz" path component. - #[ruma_api(path)] - pub baz: String, - } - - response: { - // This value will be extracted from the "Content-Type" HTTP header. - #[ruma_api(header = CONTENT_TYPE)] - pub content_type: String, - - // With no attribute on the field, it will be extracted from the body of the response. - pub value: String, - - // You can use serde attributes on any kind of field - #[serde(skip_serializing_if = "Option::is_none")] - pub optional_flag: Option, - - // Use `Raw` instead of the actual event to allow additional fields to be sent... - pub event: Raw, - - // ... and to allow unknown events when the endpoint deals with event collections. - pub list_of_events: Vec>, - } -} - -fn main() { - use ruma_common::api::MatrixVersion; - - assert_eq!( - METADATA.history.unstable_paths().collect::>(), - &["/_matrix/some/msc1234/endpoint/:baz"], - ); - assert_eq!( - METADATA.history.stable_paths().collect::>(), - &[ - (MatrixVersion::V1_0, "/_matrix/some/r0/endpoint/:baz"), - (MatrixVersion::V1_1, "/_matrix/some/v3/endpoint/:baz") - ] - ); - - assert_eq!(METADATA.history.added_in(), Some(MatrixVersion::V1_0)); - assert_eq!(METADATA.history.deprecated_in(), Some(MatrixVersion::V1_2)); - assert_eq!(METADATA.history.removed_in(), Some(MatrixVersion::V1_3)); -} diff --git a/crates/ruma-common/tests/api/ui/02-invalid-path.rs b/crates/ruma-common/tests/api/ui/02-invalid-path.rs deleted file mode 100644 index ecf8b843..00000000 --- a/crates/ruma-common/tests/api/ui/02-invalid-path.rs +++ /dev/null @@ -1,39 +0,0 @@ -use ruma_common::api::ruma_api; - -ruma_api! { - metadata: { - description: "This will fail.", - method: GET, - name: "invalid_path", - unstable_path: "µ/°/§/€", - rate_limited: false, - authentication: None, - } - - request: { - #[ruma_api(query_map)] - pub fields: Vec<(String, String)>, - } - - response: {} -} - -ruma_api! { - metadata: { - description: "This will fail.", - method: GET, - name: "invalid_path", - unstable_path: "path/to/invalid space/endpoint", - rate_limited: false, - authentication: None, - } - - request: { - #[ruma_api(query_map)] - pub fields: Vec<(String, String)>, - } - - response: {} -} - -fn main() {} diff --git a/crates/ruma-common/tests/api/ui/02-invalid-path.stderr b/crates/ruma-common/tests/api/ui/02-invalid-path.stderr deleted file mode 100644 index 3a367959..00000000 --- a/crates/ruma-common/tests/api/ui/02-invalid-path.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error: path may only contain printable ASCII characters with no spaces - --> $DIR/02-invalid-path.rs:8:24 - | -8 | unstable_path: "µ/°/§/€", - | ^^^^^^^^^ - -error: path may only contain printable ASCII characters with no spaces - --> $DIR/02-invalid-path.rs:26:24 - | -26 | unstable_path: "path/to/invalid space/endpoint", - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/crates/ruma-common/tests/api/ui/03-move-value.rs b/crates/ruma-common/tests/api/ui/03-move-value.rs deleted file mode 100644 index 5be84d39..00000000 --- a/crates/ruma-common/tests/api/ui/03-move-value.rs +++ /dev/null @@ -1,122 +0,0 @@ -// This tests that the "body" fields are moved after all other fields because they -// consume the request/response. - -mod newtype_body { - use http::header::CONTENT_TYPE; - use ruma_common::{api::ruma_api, OwnedUserId}; - - #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] - pub struct Foo; - - ruma_api! { - metadata: { - description: "Does something.", - method: POST, - name: "my_endpoint", - unstable_path: "/_matrix/foo/:bar/", - rate_limited: false, - authentication: None, - } - - request: { - #[ruma_api(body)] - pub q2: Foo, - - #[ruma_api(path)] - pub bar: String, - - #[ruma_api(query)] - pub baz: OwnedUserId, - - #[ruma_api(header = CONTENT_TYPE)] - pub world: String, - } - - response: { - #[ruma_api(body)] - pub q2: Foo, - - #[ruma_api(header = CONTENT_TYPE)] - pub world: String, - } - } -} - -mod raw_body { - use http::header::CONTENT_TYPE; - use ruma_common::{api::ruma_api, OwnedUserId}; - - ruma_api! { - metadata: { - description: "Does something.", - method: POST, - name: "my_endpoint", - unstable_path: "/_matrix/foo/:bar/", - rate_limited: false, - authentication: None, - } - - request: { - #[ruma_api(raw_body)] - pub q2: Vec, - - #[ruma_api(path)] - pub bar: String, - - #[ruma_api(query)] - pub baz: OwnedUserId, - - #[ruma_api(header = CONTENT_TYPE)] - pub world: String, - } - - response: { - #[ruma_api(raw_body)] - pub q2: Vec, - - #[ruma_api(header = CONTENT_TYPE)] - pub world: String, - } - } -} - -mod plain { - use http::header::CONTENT_TYPE; - use ruma_common::{api::ruma_api, OwnedUserId}; - - #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] - pub struct Foo; - - ruma_api! { - metadata: { - description: "Does something.", - method: POST, - name: "my_endpoint", - unstable_path: "/_matrix/foo/:bar/", - rate_limited: false, - authentication: None, - } - - request: { - pub q2: Foo, - - #[ruma_api(path)] - pub bar: String, - - #[ruma_api(query)] - pub baz: OwnedUserId, - - #[ruma_api(header = CONTENT_TYPE)] - pub world: String, - } - - response: { - pub q2: Vec, - - #[ruma_api(header = CONTENT_TYPE)] - pub world: String, - } - } -} - -fn main() {} diff --git a/crates/ruma-common/tests/api/ui/04-attributes.rs b/crates/ruma-common/tests/api/ui/04-attributes.rs deleted file mode 100644 index 3aa07c7b..00000000 --- a/crates/ruma-common/tests/api/ui/04-attributes.rs +++ /dev/null @@ -1,30 +0,0 @@ -use http::header::CONTENT_TYPE; -use ruma_common::api::ruma_api; - -ruma_api! { - metadata: { - description: "Does something.", - method: POST, // An `http::Method` constant. No imports required. - name: "some_endpoint", - unstable_path: "/_matrix/some/endpoint/:baz", - rate_limited: false, - authentication: None, - } - - #[not_a_real_attribute_should_fail] - request: { - pub foo: String, - #[ruma_api(header = CONTENT_TYPE)] - pub content_type: String, - #[ruma_api(query)] - pub bar: String, - #[ruma_api(path)] - pub baz: String, - } - - response: { - pub value: String, - } -} - -fn main() {} diff --git a/crates/ruma-common/tests/api/ui/04-attributes.stderr b/crates/ruma-common/tests/api/ui/04-attributes.stderr deleted file mode 100644 index 8518b81f..00000000 --- a/crates/ruma-common/tests/api/ui/04-attributes.stderr +++ /dev/null @@ -1,5 +0,0 @@ -error: cannot find attribute `not_a_real_attribute_should_fail` in this scope - --> $DIR/04-attributes.rs:14:7 - | -14 | #[not_a_real_attribute_should_fail] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/crates/ruma-common/tests/api/ui/05-request-only.rs b/crates/ruma-common/tests/api/ui/05-request-only.rs deleted file mode 100644 index 7cb3e49a..00000000 --- a/crates/ruma-common/tests/api/ui/05-request-only.rs +++ /dev/null @@ -1,50 +0,0 @@ -use bytes::BufMut; -use ruma_common::api::{ - error::{FromHttpResponseError, IntoHttpError, MatrixError}, - ruma_api, IncomingResponse, OutgoingResponse, -}; - -ruma_api! { - metadata: { - description: "Does something.", - method: POST, // An `http::Method` constant. No imports required. - name: "some_endpoint", - unstable_path: "/_matrix/some/endpoint/:foo", - rate_limited: false, - authentication: None, - } - - #[derive(PartialEq)] // Make sure attributes work - request: { - // With no attribute on the field, it will be put into the body of the request. - #[ruma_api(path)] - pub foo: String, - } -} - -pub struct Response; - -impl IncomingResponse for Response { - type EndpointError = MatrixError; - - fn try_from_http_response>( - _: http::Response, - ) -> Result> { - todo!() - } -} - -impl OutgoingResponse for Response { - fn try_into_http_response( - self, - ) -> Result, IntoHttpError> { - todo!() - } -} - -fn main() { - let req1 = Request { foo: "foo".into() }; - let req2 = req1.clone(); - - assert_eq!(req1, req2); -} diff --git a/crates/ruma-common/tests/api/ui/06-response-only.rs b/crates/ruma-common/tests/api/ui/06-response-only.rs deleted file mode 100644 index 3f72b080..00000000 --- a/crates/ruma-common/tests/api/ui/06-response-only.rs +++ /dev/null @@ -1,24 +0,0 @@ -use ruma_common::api::ruma_api; - -ruma_api! { - metadata: { - description: "Does something.", - method: POST, // An `http::Method` constant. No imports required. - name: "some_endpoint", - unstable_path: "/_matrix/some/endpoint/:baz", - rate_limited: false, - authentication: None, - } - - #[derive(PartialEq)] // Make sure attributes work - response: { - pub flag: bool, - } -} - -fn main() { - let res1 = Response { flag: false }; - let res2 = res1.clone(); - - assert_eq!(res1, res2); -} diff --git a/crates/ruma-common/tests/api/ui/07-error-type-attribute.rs b/crates/ruma-common/tests/api/ui/07-error-type-attribute.rs deleted file mode 100644 index c865dc1a..00000000 --- a/crates/ruma-common/tests/api/ui/07-error-type-attribute.rs +++ /dev/null @@ -1,21 +0,0 @@ -use ruma_common::api::ruma_api; - -ruma_api! { - metadata: { - description: "Does something.", - method: POST, // An `http::Method` constant. No imports required. - name: "some_endpoint", - unstable_path: "/_matrix/some/endpoint/:baz", - rate_limited: false, - authentication: None, - } - - request: {} - - response: {} - - #[derive(Default)] - error: ruma_common::api::error::MatrixError -} - -fn main() {} diff --git a/crates/ruma-common/tests/api/ui/07-error-type-attribute.stderr b/crates/ruma-common/tests/api/ui/07-error-type-attribute.stderr deleted file mode 100644 index 74d77e42..00000000 --- a/crates/ruma-common/tests/api/ui/07-error-type-attribute.stderr +++ /dev/null @@ -1,5 +0,0 @@ -error: unexpected token - --> $DIR/07-error-type-attribute.rs:17:5 - | -17 | #[derive(Default)] - | ^ diff --git a/crates/ruma-common/tests/api/ui/08-deprecated-without-added.rs b/crates/ruma-common/tests/api/ui/08-deprecated-without-added.rs deleted file mode 100644 index 169966e4..00000000 --- a/crates/ruma-common/tests/api/ui/08-deprecated-without-added.rs +++ /dev/null @@ -1,23 +0,0 @@ -use ruma_common::api::ruma_api; - -ruma_api! { - metadata: { - description: "This will fail.", - method: GET, - name: "invalid_versions", - unstable_path: "/a/path", - rate_limited: false, - authentication: None, - - deprecated: 1.1, - } - - request: { - #[ruma_api(query_map)] - pub fields: Vec<(String, String)>, - } - - response: {} -} - -fn main() {} diff --git a/crates/ruma-common/tests/api/ui/08-deprecated-without-added.stderr b/crates/ruma-common/tests/api/ui/08-deprecated-without-added.stderr deleted file mode 100644 index 9260e510..00000000 --- a/crates/ruma-common/tests/api/ui/08-deprecated-without-added.stderr +++ /dev/null @@ -1,13 +0,0 @@ -error: deprecated version is defined while added version is not defined - --> $DIR/08-deprecated-without-added.rs:3:1 - | -3 | / ruma_api! { -4 | | metadata: { -5 | | description: "This will fail.", -6 | | method: GET, -... | -20 | | response: {} -21 | | } - | |_^ - | - = note: this error originates in the macro `ruma_api` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/crates/ruma-common/tests/api/ui/09-removed-without-deprecated.rs b/crates/ruma-common/tests/api/ui/09-removed-without-deprecated.rs deleted file mode 100644 index a635f8d2..00000000 --- a/crates/ruma-common/tests/api/ui/09-removed-without-deprecated.rs +++ /dev/null @@ -1,23 +0,0 @@ -use ruma_common::api::ruma_api; - -ruma_api! { - metadata: { - description: "This will fail.", - method: GET, - name: "invalid_versions", - unstable_path: "/a/path", - rate_limited: false, - authentication: None, - - removed: 1.1, - } - - request: { - #[ruma_api(query_map)] - pub fields: Vec<(String, String)>, - } - - response: {} -} - -fn main() {} diff --git a/crates/ruma-common/tests/api/ui/09-removed-without-deprecated.stderr b/crates/ruma-common/tests/api/ui/09-removed-without-deprecated.stderr deleted file mode 100644 index 6a472502..00000000 --- a/crates/ruma-common/tests/api/ui/09-removed-without-deprecated.stderr +++ /dev/null @@ -1,13 +0,0 @@ -error: removed version is defined while deprecated version is not defined - --> $DIR/09-removed-without-deprecated.rs:3:1 - | -3 | / ruma_api! { -4 | | metadata: { -5 | | description: "This will fail.", -6 | | method: GET, -... | -20 | | response: {} -21 | | } - | |_^ - | - = note: this error originates in the macro `ruma_api` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/crates/ruma-common/tests/api/ui/api-sanity-check.rs b/crates/ruma-common/tests/api/ui/api-sanity-check.rs new file mode 100644 index 00000000..929c21b6 --- /dev/null +++ b/crates/ruma-common/tests/api/ui/api-sanity-check.rs @@ -0,0 +1,81 @@ +use http::header::CONTENT_TYPE; +use ruma_common::{ + api::{request, response, Metadata}, + events::{tag::TagEvent, AnyTimelineEvent}, + metadata, + serde::Raw, +}; + +const METADATA: Metadata = metadata! { + description: "Does something.", + method: POST, // An `http::Method` constant. No imports required. + name: "some_endpoint", + rate_limited: false, + authentication: None, + history: { + unstable => "/_matrix/some/msc1234/endpoint/:baz", + 1.0 => "/_matrix/some/r0/endpoint/:baz", + 1.1 => "/_matrix/some/v3/endpoint/:baz", + 1.2 => deprecated, + 1.3 => removed, + } +}; + +#[request] +pub struct Request { + // With no attribute on the field, it will be put into the body of the request. + pub foo: String, + + // This value will be put into the "Content-Type" HTTP header. + #[ruma_api(header = CONTENT_TYPE)] + pub content_type: String, + + // This value will be put into the query string of the request's URL. + #[ruma_api(query)] + pub bar: String, + + // This value will be inserted into the request's URL in place of the + // ":baz" path component. + #[ruma_api(path)] + pub baz: String, +} + +#[response] +pub struct Response { + // This value will be extracted from the "Content-Type" HTTP header. + #[ruma_api(header = CONTENT_TYPE)] + pub content_type: String, + + // With no attribute on the field, it will be extracted from the body of the response. + pub value: String, + + // You can use serde attributes on any kind of field + #[serde(skip_serializing_if = "Option::is_none")] + pub optional_flag: Option, + + // Use `Raw` instead of the actual event to allow additional fields to be sent... + pub event: Raw, + + // ... and to allow unknown events when the endpoint deals with event collections. + pub list_of_events: Vec>, +} + +fn main() { + use ruma_common::api::MatrixVersion; + + assert_eq!( + METADATA.history.unstable_paths().collect::>(), + &["/_matrix/some/msc1234/endpoint/:baz"], + ); + assert_eq!( + METADATA.history.stable_paths().collect::>(), + &[ + (MatrixVersion::V1_0, "/_matrix/some/r0/endpoint/:baz"), + (MatrixVersion::V1_1, "/_matrix/some/v3/endpoint/:baz") + ], + ); + + assert_eq!(METADATA.history.added_in(), Some(MatrixVersion::V1_0)); + assert_eq!(METADATA.history.deprecated_in(), Some(MatrixVersion::V1_2)); + assert_eq!(METADATA.history.removed_in(), Some(MatrixVersion::V1_3)); +} diff --git a/crates/ruma-common/tests/api/ui/deprecated-without-added.rs b/crates/ruma-common/tests/api/ui/deprecated-without-added.rs new file mode 100644 index 00000000..17ef471c --- /dev/null +++ b/crates/ruma-common/tests/api/ui/deprecated-without-added.rs @@ -0,0 +1,15 @@ +use ruma_common::{api::Metadata, metadata}; + +const _: Metadata = metadata! { + description: "This will fail.", + method: GET, + name: "invalid_versions", + unstable => "/a/path", + rate_limited: false, + authentication: None, + history: { + 1.1 => deprecated, + } +}; + +fn main() {} diff --git a/crates/ruma-common/tests/api/ui/deprecated-without-added.stderr b/crates/ruma-common/tests/api/ui/deprecated-without-added.stderr new file mode 100644 index 00000000..01e582a8 --- /dev/null +++ b/crates/ruma-common/tests/api/ui/deprecated-without-added.stderr @@ -0,0 +1,5 @@ +error: no rules expected the token `=>` + --> tests/api/ui/deprecated-without-added.rs:7:14 + | +7 | unstable => "/a/path", + | ^^ no rules expected this token in macro call diff --git a/crates/ruma-common/tests/api/ui/move-value.rs b/crates/ruma-common/tests/api/ui/move-value.rs new file mode 100644 index 00000000..c72aa946 --- /dev/null +++ b/crates/ruma-common/tests/api/ui/move-value.rs @@ -0,0 +1,137 @@ +// This tests that the "body" fields are moved after all other fields because they +// consume the request/response. + +mod newtype_body { + use http::header::CONTENT_TYPE; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, OwnedUserId, + }; + + #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] + pub struct Foo; + + const METADATA: Metadata = metadata! { + description: "Does something.", + method: POST, + name: "my_endpoint", + rate_limited: false, + authentication: None, + history: { + unstable => "/_matrix/foo/:bar/", + } + }; + + #[request] + pub struct Request { + #[ruma_api(body)] + pub q2: Foo, + + #[ruma_api(path)] + pub bar: String, + + #[ruma_api(query)] + pub baz: OwnedUserId, + + #[ruma_api(header = CONTENT_TYPE)] + pub world: String, + } + + #[response] + pub struct Response { + #[ruma_api(body)] + pub q2: Foo, + + #[ruma_api(header = CONTENT_TYPE)] + pub world: String, + } +} + +mod raw_body { + use http::header::CONTENT_TYPE; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, OwnedUserId, + }; + + const METADATA: Metadata = metadata! { + description: "Does something.", + method: POST, + name: "my_endpoint", + rate_limited: false, + authentication: None, + history: { + unstable => "/_matrix/foo/:bar/", + } + }; + + #[request] + pub struct Request { + #[ruma_api(raw_body)] + pub q2: Vec, + + #[ruma_api(path)] + pub bar: String, + + #[ruma_api(query)] + pub baz: OwnedUserId, + + #[ruma_api(header = CONTENT_TYPE)] + pub world: String, + } + + #[response] + pub struct Response { + #[ruma_api(raw_body)] + pub q2: Vec, + + #[ruma_api(header = CONTENT_TYPE)] + pub world: String, + } +} + +mod plain { + use http::header::CONTENT_TYPE; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, OwnedUserId, + }; + + #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] + pub struct Foo; + + const METADATA: Metadata = metadata! { + description: "Does something.", + method: POST, + name: "my_endpoint", + rate_limited: false, + authentication: None, + history: { + unstable => "/_matrix/foo/:bar/", + } + }; + + #[request] + pub struct Request { + pub q2: Foo, + + #[ruma_api(path)] + pub bar: String, + + #[ruma_api(query)] + pub baz: OwnedUserId, + + #[ruma_api(header = CONTENT_TYPE)] + pub world: String, + } + + #[response] + pub struct Response { + pub q2: Vec, + + #[ruma_api(header = CONTENT_TYPE)] + pub world: String, + } +} + +fn main() {} diff --git a/crates/ruma-common/tests/api/ui/removed-without-deprecated.rs b/crates/ruma-common/tests/api/ui/removed-without-deprecated.rs new file mode 100644 index 00000000..34c0e729 --- /dev/null +++ b/crates/ruma-common/tests/api/ui/removed-without-deprecated.rs @@ -0,0 +1,15 @@ +use ruma_common::{api::Metadata, metadata}; + +const METADATA: Metadata = metadata! { + description: "This will fail.", + method: GET, + name: "invalid_versions", + unstable => "/a/path", + rate_limited: false, + authentication: None, + history: { + 1.1 => removed, + } +}; + +fn main() {} diff --git a/crates/ruma-common/tests/api/ui/removed-without-deprecated.stderr b/crates/ruma-common/tests/api/ui/removed-without-deprecated.stderr new file mode 100644 index 00000000..c9b2a6f7 --- /dev/null +++ b/crates/ruma-common/tests/api/ui/removed-without-deprecated.stderr @@ -0,0 +1,5 @@ +error: no rules expected the token `=>` + --> tests/api/ui/removed-without-deprecated.rs:7:14 + | +7 | unstable => "/a/path", + | ^^ no rules expected this token in macro call diff --git a/crates/ruma-common/tests/api/ui/request-only.rs b/crates/ruma-common/tests/api/ui/request-only.rs new file mode 100644 index 00000000..d744c1e7 --- /dev/null +++ b/crates/ruma-common/tests/api/ui/request-only.rs @@ -0,0 +1,54 @@ +use bytes::BufMut; +use ruma_common::{ + api::{ + error::{FromHttpResponseError, IntoHttpError, MatrixError}, + request, IncomingResponse, Metadata, OutgoingResponse, + }, + metadata, +}; + +const METADATA: Metadata = metadata! { + description: "Does something.", + method: POST, // An `http::Method` constant. No imports required. + name: "some_endpoint", + rate_limited: false, + authentication: None, + history: { + unstable => "/_matrix/some/endpoint/:foo", + } +}; + +#[request] +#[derive(PartialEq)] // Make sure attributes work +pub struct Request { + // With no attribute on the field, it will be put into the body of the request. + #[ruma_api(path)] + pub foo: String, +} + +pub struct Response; + +impl IncomingResponse for Response { + type EndpointError = MatrixError; + + fn try_from_http_response>( + _: http::Response, + ) -> Result> { + todo!() + } +} + +impl OutgoingResponse for Response { + fn try_into_http_response( + self, + ) -> Result, IntoHttpError> { + todo!() + } +} + +fn main() { + let req1 = Request { foo: "foo".into() }; + let req2 = req1.clone(); + + assert_eq!(req1, req2); +} diff --git a/crates/ruma-common/tests/api/ui/response-only.rs b/crates/ruma-common/tests/api/ui/response-only.rs new file mode 100644 index 00000000..ef79e5e4 --- /dev/null +++ b/crates/ruma-common/tests/api/ui/response-only.rs @@ -0,0 +1,14 @@ +use ruma_common::api::response; + +#[derive(PartialEq)] // Make sure attributes work +#[response] +pub struct Response { + pub flag: bool, +} + +fn main() { + let res1 = Response { flag: false }; + let res2 = res1.clone(); + + assert_eq!(res1, res2); +} diff --git a/crates/ruma-federation-api/src/authorization/get_event_authorization.rs b/crates/ruma-federation-api/src/authorization/get_event_authorization.rs index cfe0244a..a58d2f16 100644 --- a/crates/ruma-federation-api/src/authorization/get_event_authorization.rs +++ b/crates/ruma-federation-api/src/authorization/get_event_authorization.rs @@ -7,35 +7,39 @@ pub mod v1 { //! //! [spec]: https://spec.matrix.org/v1.4/server-server-api/#get_matrixfederationv1event_authroomideventid - use ruma_common::{api::ruma_api, EventId, RoomId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, EventId, RoomId, + }; use serde_json::value::RawValue as RawJsonValue; - ruma_api! { - metadata: { - description: "Retrieves the complete auth chain for a given event.", - name: "get_event_authorization", - method: GET, - stable_path: "/_matrix/federation/v1/event_auth/:room_id/:event_id", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Retrieves the complete auth chain for a given event.", + method: GET, + name: "get_event_authorization", + rate_limited: false, + authentication: ServerSignatures, + history: { + 1.0 => "/_matrix/federation/v1/event_auth/:room_id/:event_id", } + }; - request: { - /// The room ID to get the auth chain for. - #[ruma_api(path)] - pub room_id: &'a RoomId, + #[request] + pub struct Request<'a> { + /// The room ID to get the auth chain for. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The event ID to get the auth chain for. - #[ruma_api(path)] - pub event_id: &'a EventId, - } + /// The event ID to get the auth chain for. + #[ruma_api(path)] + pub event_id: &'a EventId, + } - response: { - /// The full set of authorization events that make up the state of the room, - /// and their authorization events, recursively. - pub auth_chain: Vec>, - } + #[response] + pub struct Response { + /// The full set of authorization events that make up the state of the room, + /// and their authorization events, recursively. + pub auth_chain: Vec>, } impl<'a> Request<'a> { diff --git a/crates/ruma-federation-api/src/backfill/get_backfill.rs b/crates/ruma-federation-api/src/backfill/get_backfill.rs index c4ce925a..c05b3505 100644 --- a/crates/ruma-federation-api/src/backfill/get_backfill.rs +++ b/crates/ruma-federation-api/src/backfill/get_backfill.rs @@ -9,45 +9,48 @@ pub mod v1 { use js_int::UInt; use ruma_common::{ - api::ruma_api, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedServerName, RoomId, + api::{request, response, Metadata}, + metadata, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedServerName, RoomId, }; use serde_json::value::RawValue as RawJsonValue; - ruma_api! { - metadata: { - description: "Request more history from another homeserver", - name: "get_backfill", - method: GET, - stable_path: "/_matrix/federation/v1/backfill/:room_id", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Request more history from another homeserver", + method: GET, + name: "get_backfill", + rate_limited: false, + authentication: ServerSignatures, + history: { + 1.0 => "/_matrix/federation/v1/backfill/:room_id", } + }; - request: { - /// The room ID to backfill. - #[ruma_api(path)] - pub room_id: &'a RoomId, + #[request] + pub struct Request<'a> { + /// The room ID to backfill. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The event IDs to backfill from. - #[ruma_api(query)] - pub v: &'a [OwnedEventId], + /// The event IDs to backfill from. + #[ruma_api(query)] + pub v: &'a [OwnedEventId], - /// The maximum number of PDUs to retrieve, including the given events. - #[ruma_api(query)] - pub limit: UInt, - } + /// The maximum number of PDUs to retrieve, including the given events. + #[ruma_api(query)] + pub limit: UInt, + } - response: { - /// The `server_name` of the homeserver sending this transaction. - pub origin: OwnedServerName, + #[response] + pub struct Response { + /// The `server_name` of the homeserver sending this transaction. + pub origin: OwnedServerName, - /// POSIX timestamp in milliseconds on originating homeserver when this transaction started. - pub origin_server_ts: MilliSecondsSinceUnixEpoch, + /// POSIX timestamp in milliseconds on originating homeserver when this transaction + /// started. + pub origin_server_ts: MilliSecondsSinceUnixEpoch, - /// List of persistent updates to rooms. - pub pdus: Vec>, - } + /// List of persistent updates to rooms. + pub pdus: Vec>, } impl<'a> Request<'a> { diff --git a/crates/ruma-federation-api/src/device/get_devices.rs b/crates/ruma-federation-api/src/device/get_devices.rs index fe3df751..b132581e 100644 --- a/crates/ruma-federation-api/src/device/get_devices.rs +++ b/crates/ruma-federation-api/src/device/get_devices.rs @@ -9,53 +9,56 @@ pub mod v1 { use js_int::UInt; use ruma_common::{ - api::ruma_api, + api::{request, response, Metadata}, encryption::{CrossSigningKey, DeviceKeys}, + metadata, serde::Raw, OwnedDeviceId, OwnedUserId, UserId, }; use serde::{Deserialize, Serialize}; - ruma_api! { - metadata: { - description: "Gets information on all of the user's devices.", - name: "get_devices", - method: GET, - stable_path: "/_matrix/federation/v1/user/devices/:user_id", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Gets information on all of the user's devices.", + method: GET, + name: "get_devices", + rate_limited: false, + authentication: ServerSignatures, + history: { + 1.0 => "/_matrix/federation/v1/user/devices/:user_id", } + }; - request: { - /// The user ID to retrieve devices for. - /// - /// Must be a user local to the receiving homeserver. - #[ruma_api(path)] - pub user_id: &'a UserId, - } + #[request] + pub struct Request<'a> { + /// The user ID to retrieve devices for. + /// + /// Must be a user local to the receiving homeserver. + #[ruma_api(path)] + pub user_id: &'a UserId, + } - response: { - /// The user ID devices were requested for. - pub user_id: OwnedUserId, + #[response] + pub struct Response { + /// The user ID devices were requested for. + pub user_id: OwnedUserId, - /// A unique ID for a given user_id which describes the version of the returned device list. - /// - /// This is matched with the `stream_id` field in `m.device_list_update` EDUs in order to - /// incrementally update the returned device_list. - pub stream_id: UInt, + /// A unique ID for a given user_id which describes the version of the returned device + /// list. + /// + /// This is matched with the `stream_id` field in `m.device_list_update` EDUs in order to + /// incrementally update the returned device_list. + pub stream_id: UInt, - /// The user's devices. - pub devices: Vec, + /// The user's devices. + pub devices: Vec, - /// The user's master key. - #[serde(skip_serializing_if = "Option::is_none")] - pub master_key: Option>, + /// The user's master key. + #[serde(skip_serializing_if = "Option::is_none")] + pub master_key: Option>, - /// The users's self-signing key. - #[serde(skip_serializing_if = "Option::is_none")] - pub self_signing_key: Option>, - } + /// The users's self-signing key. + #[serde(skip_serializing_if = "Option::is_none")] + pub self_signing_key: Option>, } impl<'a> Request<'a> { diff --git a/crates/ruma-federation-api/src/directory/get_public_rooms.rs b/crates/ruma-federation-api/src/directory/get_public_rooms.rs index ab1f6266..e1e6c020 100644 --- a/crates/ruma-federation-api/src/directory/get_public_rooms.rs +++ b/crates/ruma-federation-api/src/directory/get_public_rooms.rs @@ -9,55 +9,57 @@ pub mod v1 { use js_int::UInt; use ruma_common::{ - api::ruma_api, + api::{request, response, Metadata}, directory::{IncomingRoomNetwork, PublicRoomsChunk, RoomNetwork}, + metadata, }; - ruma_api! { - metadata: { - description: "Gets all the public rooms for the homeserver.", - method: GET, - name: "get_public_rooms", - stable_path: "/_matrix/federation/v1/publicRooms", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Gets all the public rooms for the homeserver.", + method: GET, + name: "get_public_rooms", + rate_limited: false, + authentication: ServerSignatures, + history: { + 1.0 => "/_matrix/federation/v1/publicRooms", } + }; - #[derive(Default)] - request: { - /// Limit for the number of results to return. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub limit: Option, + #[request] + #[derive(Default)] + pub struct Request<'a> { + /// Limit for the number of results to return. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub limit: Option, - /// Pagination token from a previous request. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub since: Option<&'a str>, + /// Pagination token from a previous request. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub since: Option<&'a str>, - /// Network to fetch the public room lists from. - #[serde(flatten, skip_serializing_if = "ruma_common::serde::is_default")] - #[ruma_api(query)] - pub room_network: RoomNetwork<'a>, - } + /// Network to fetch the public room lists from. + #[serde(flatten, skip_serializing_if = "ruma_common::serde::is_default")] + #[ruma_api(query)] + pub room_network: RoomNetwork<'a>, + } - #[derive(Default)] - response: { - /// A paginated chunk of public rooms. - pub chunk: Vec, + #[response] + #[derive(Default)] + pub struct Response { + /// A paginated chunk of public rooms. + pub chunk: Vec, - /// A pagination token for the response. - #[serde(skip_serializing_if = "Option::is_none")] - pub next_batch: Option, + /// A pagination token for the response. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_batch: Option, - /// A pagination token that allows fetching previous results. - #[serde(skip_serializing_if = "Option::is_none")] - pub prev_batch: Option, + /// A pagination token that allows fetching previous results. + #[serde(skip_serializing_if = "Option::is_none")] + pub prev_batch: Option, - /// An estimate on the total number of public rooms, if the server has an estimate. - pub total_room_count_estimate: Option, - } + /// An estimate on the total number of public rooms, if the server has an estimate. + pub total_room_count_estimate: Option, } impl Request<'_> { diff --git a/crates/ruma-federation-api/src/directory/get_public_rooms_filtered.rs b/crates/ruma-federation-api/src/directory/get_public_rooms_filtered.rs index 9ce43f80..9cf73d4e 100644 --- a/crates/ruma-federation-api/src/directory/get_public_rooms_filtered.rs +++ b/crates/ruma-federation-api/src/directory/get_public_rooms_filtered.rs @@ -9,54 +9,56 @@ pub mod v1 { use js_int::UInt; use ruma_common::{ - api::ruma_api, + api::{request, response, Metadata}, directory::{Filter, IncomingFilter, IncomingRoomNetwork, PublicRoomsChunk, RoomNetwork}, + metadata, }; - ruma_api! { - metadata: { - description: "Get the list of rooms in this homeserver's public directory.", - method: POST, - name: "get_public_rooms_filtered", - stable_path: "/_matrix/federation/v1/publicRooms", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Get the list of rooms in this homeserver's public directory.", + method: POST, + name: "get_public_rooms_filtered", + rate_limited: false, + authentication: ServerSignatures, + history: { + 1.0 => "/_matrix/federation/v1/publicRooms", } + }; - #[derive(Default)] - request: { - /// Limit for the number of results to return. - #[serde(skip_serializing_if = "Option::is_none")] - pub limit: Option, + #[request] + #[derive(Default)] + pub struct Request<'a> { + /// Limit for the number of results to return. + #[serde(skip_serializing_if = "Option::is_none")] + pub limit: Option, - /// Pagination token from a previous request. - #[serde(skip_serializing_if = "Option::is_none")] - pub since: Option<&'a str>, + /// Pagination token from a previous request. + #[serde(skip_serializing_if = "Option::is_none")] + pub since: Option<&'a str>, - /// Filter to apply to the results. - #[serde(default, skip_serializing_if = "Filter::is_empty")] - pub filter: Filter<'a>, + /// Filter to apply to the results. + #[serde(default, skip_serializing_if = "Filter::is_empty")] + pub filter: Filter<'a>, - /// Network to fetch the public room lists from. - #[serde(flatten, skip_serializing_if = "ruma_common::serde::is_default")] - pub room_network: RoomNetwork<'a>, - } + /// Network to fetch the public room lists from. + #[serde(flatten, skip_serializing_if = "ruma_common::serde::is_default")] + pub room_network: RoomNetwork<'a>, + } - #[derive(Default)] - response: { - /// A paginated chunk of public rooms. - pub chunk: Vec, + #[response] + #[derive(Default)] + pub struct Response { + /// A paginated chunk of public rooms. + pub chunk: Vec, - /// A pagination token for the response. - pub next_batch: Option, + /// A pagination token for the response. + pub next_batch: Option, - /// A pagination token that allows fetching previous results. - pub prev_batch: Option, + /// A pagination token that allows fetching previous results. + pub prev_batch: Option, - /// An estimate on the total number of public rooms, if the server has an estimate. - pub total_room_count_estimate: Option, - } + /// An estimate on the total number of public rooms, if the server has an estimate. + pub total_room_count_estimate: Option, } impl Request<'_> { diff --git a/crates/ruma-federation-api/src/discovery/discover_homeserver.rs b/crates/ruma-federation-api/src/discovery/discover_homeserver.rs index 40413b2d..b629d711 100644 --- a/crates/ruma-federation-api/src/discovery/discover_homeserver.rs +++ b/crates/ruma-federation-api/src/discovery/discover_homeserver.rs @@ -2,27 +2,31 @@ //! //! [spec]: https://spec.matrix.org/v1.4/server-server-api/#getwell-knownmatrixserver -use ruma_common::{api::ruma_api, OwnedServerName}; +use ruma_common::{ + api::{request, response, Metadata}, + metadata, OwnedServerName, +}; -ruma_api! { - metadata: { - description: "Get discovery information about the domain.", - method: GET, - name: "discover_homeserver", - stable_path: "/.well-known/matrix/server", - rate_limited: false, - authentication: None, - added: 1.0, +const METADATA: Metadata = metadata! { + description: "Get discovery information about the domain.", + method: GET, + name: "discover_homeserver", + rate_limited: false, + authentication: None, + history: { + 1.0 => "/.well-known/matrix/server", } +}; - #[derive(Default)] - request: {} +#[request] +#[derive(Default)] +pub struct Request {} - response: { - /// The server name to delegate server-server communications to, with optional port. - #[serde(rename = "m.server")] - pub server: OwnedServerName, - } +#[response] +pub struct Response { + /// The server name to delegate server-server communications to, with optional port. + #[serde(rename = "m.server")] + pub server: OwnedServerName, } impl Request { diff --git a/crates/ruma-federation-api/src/discovery/get_remote_server_keys.rs b/crates/ruma-federation-api/src/discovery/get_remote_server_keys.rs index e950d05f..699d602f 100644 --- a/crates/ruma-federation-api/src/discovery/get_remote_server_keys.rs +++ b/crates/ruma-federation-api/src/discovery/get_remote_server_keys.rs @@ -8,41 +8,47 @@ pub mod v2 { //! //! [spec]: https://spec.matrix.org/v1.4/server-server-api/#get_matrixkeyv2queryservernamekeyid - use ruma_common::{api::ruma_api, serde::Raw, MilliSecondsSinceUnixEpoch, ServerName}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + serde::Raw, + MilliSecondsSinceUnixEpoch, ServerName, + }; use crate::discovery::ServerSigningKeys; - ruma_api! { - metadata: { - description: "Query for another server's keys.", - method: GET, - name: "get_remote_server_keys", + const METADATA: Metadata = metadata! { + description: "Query for another server's keys.", + method: GET, + name: "get_remote_server_keys", + rate_limited: false, + authentication: None, + history: { // Note: The spec has an additional, deprecated path parameter on this. We may want to // support an additional parameter at the end, even if it is ignored. - stable_path: "/_matrix/key/v2/query/:server_name", - rate_limited: false, - authentication: None, - added: 1.0, + 1.0 => "/_matrix/key/v2/query/:server_name", } + }; - request: { - /// The server's DNS name to query - #[ruma_api(path)] - pub server_name: &'a ServerName, + #[request] + pub struct Request<'a> { + /// The server's DNS name to query + #[ruma_api(path)] + pub server_name: &'a ServerName, - /// A millisecond POSIX timestamp in milliseconds indicating when the returned certificates - /// will need to be valid until to be useful to the requesting server. - /// - /// If not supplied, the current time as determined by the receiving server is used. - #[ruma_api(query)] - #[serde(default = "MilliSecondsSinceUnixEpoch::now")] - pub minimum_valid_until_ts: MilliSecondsSinceUnixEpoch, - } + /// A millisecond POSIX timestamp in milliseconds indicating when the returned certificates + /// will need to be valid until to be useful to the requesting server. + /// + /// If not supplied, the current time as determined by the receiving server is used. + #[ruma_api(query)] + #[serde(default = "MilliSecondsSinceUnixEpoch::now")] + pub minimum_valid_until_ts: MilliSecondsSinceUnixEpoch, + } - response: { - /// The queried server's keys, signed by the notary server. - pub server_keys: Vec>, - } + #[response] + pub struct Response { + /// The queried server's keys, signed by the notary server. + pub server_keys: Vec>, } impl<'a> Request<'a> { diff --git a/crates/ruma-federation-api/src/discovery/get_remote_server_keys_batch.rs b/crates/ruma-federation-api/src/discovery/get_remote_server_keys_batch.rs index 5f9db2e1..e3e81afa 100644 --- a/crates/ruma-federation-api/src/discovery/get_remote_server_keys_batch.rs +++ b/crates/ruma-federation-api/src/discovery/get_remote_server_keys_batch.rs @@ -11,41 +11,44 @@ pub mod v2 { use std::collections::BTreeMap; use ruma_common::{ - api::ruma_api, serde::Raw, MilliSecondsSinceUnixEpoch, OwnedServerName, - OwnedServerSigningKeyId, + api::{request, response, Metadata}, + metadata, + serde::Raw, + MilliSecondsSinceUnixEpoch, OwnedServerName, OwnedServerSigningKeyId, }; use serde::{Deserialize, Serialize}; use crate::discovery::ServerSigningKeys; - ruma_api! { - metadata: { - description: "Query for keys from multiple servers in a batch format.", - method: POST, - name: "get_remote_server_keys_batch", - stable_path: "/_matrix/key/v2/query", - rate_limited: false, - authentication: None, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Query for keys from multiple servers in a batch format.", + method: POST, + name: "get_remote_server_keys_batch", + rate_limited: false, + authentication: None, + history: { + 1.0 => "/_matrix/key/v2/query", } + }; - request: { - /// The query criteria. - /// - /// The outer string key on the object is the server name (eg: matrix.org). The inner - /// string key is the Key ID to query for the particular server. If no key IDs are given to - /// be queried, the notary server should query for all keys. If no servers are given, the - /// notary server must return an empty server_keys array in the response. - /// - /// The notary server may return multiple keys regardless of the Key IDs given. - pub server_keys: BTreeMap>, + #[request] + pub struct Request { + /// The query criteria. + /// + /// The outer string key on the object is the server name (eg: matrix.org). The inner + /// string key is the Key ID to query for the particular server. If no key IDs are given to + /// be queried, the notary server should query for all keys. If no servers are given, the + /// notary server must return an empty server_keys array in the response. + /// + /// The notary server may return multiple keys regardless of the Key IDs given. + pub server_keys: + BTreeMap>, + } - } - - response: { - /// The queried server's keys, signed by the notary server. - pub server_keys: Vec>, - } + #[response] + pub struct Response { + /// The queried server's keys, signed by the notary server. + pub server_keys: Vec>, } impl Request { diff --git a/crates/ruma-federation-api/src/discovery/get_server_keys.rs b/crates/ruma-federation-api/src/discovery/get_server_keys.rs index 39f83180..f23333f5 100644 --- a/crates/ruma-federation-api/src/discovery/get_server_keys.rs +++ b/crates/ruma-federation-api/src/discovery/get_server_keys.rs @@ -10,29 +10,34 @@ pub mod v2 { //! //! [spec]: https://spec.matrix.org/v1.4/server-server-api/#get_matrixkeyv2serverkeyid - use ruma_common::{api::ruma_api, serde::Raw}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + serde::Raw, + }; use crate::discovery::ServerSigningKeys; - ruma_api! { - metadata: { - description: "Gets the homeserver's published signing keys.", - method: GET, - name: "get_server_keys", - stable_path: "/_matrix/key/v2/server", - rate_limited: false, - authentication: None, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Gets the homeserver's published signing keys.", + method: GET, + name: "get_server_keys", + rate_limited: false, + authentication: None, + history: { + 1.0 => "/_matrix/key/v2/server", } + }; - #[derive(Default)] - request: {} + #[request] + #[derive(Default)] + pub struct Request {} - response: { - /// Queried server key, signed by the notary server. - #[ruma_api(body)] - pub server_key: Raw, - } + #[response] + pub struct Response { + /// Queried server key, signed by the notary server. + #[ruma_api(body)] + pub server_key: Raw, } impl Request { diff --git a/crates/ruma-federation-api/src/discovery/get_server_version.rs b/crates/ruma-federation-api/src/discovery/get_server_version.rs index 9e86ef2d..93465422 100644 --- a/crates/ruma-federation-api/src/discovery/get_server_version.rs +++ b/crates/ruma-federation-api/src/discovery/get_server_version.rs @@ -7,29 +7,33 @@ pub mod v1 { //! //! [spec]: https://spec.matrix.org/v1.4/server-server-api/#get_matrixfederationv1version - use ruma_common::api::ruma_api; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + }; use serde::{Deserialize, Serialize}; - ruma_api! { - metadata: { - description: "Get the implementation name and version of this homeserver.", - method: GET, - name: "get_server_version", - stable_path: "/_matrix/federation/v1/version", - rate_limited: false, - authentication: None, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Get the implementation name and version of this homeserver.", + method: GET, + name: "get_server_version", + rate_limited: false, + authentication: None, + history: { + 1.0 => "/_matrix/federation/v1/version", } + }; - #[derive(Default)] - request: {} + #[request] + #[derive(Default)] + pub struct Request {} - #[derive(Default)] - response: { - /// Information about the homeserver implementation - #[serde(skip_serializing_if = "Option::is_none")] - pub server: Option, - } + #[response] + #[derive(Default)] + pub struct Response { + /// Information about the homeserver implementation + #[serde(skip_serializing_if = "Option::is_none")] + pub server: Option, } impl Request { diff --git a/crates/ruma-federation-api/src/discovery/get_server_versions.rs b/crates/ruma-federation-api/src/discovery/get_server_versions.rs index fc6799b8..d5aedd95 100644 --- a/crates/ruma-federation-api/src/discovery/get_server_versions.rs +++ b/crates/ruma-federation-api/src/discovery/get_server_versions.rs @@ -3,26 +3,31 @@ pub mod msc3723 { //! [GET /_matrix/federation/versions](https://github.com/matrix-org/matrix-spec-proposals/pull/3723) - use ruma_common::api::ruma_api; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + }; - ruma_api! { - metadata: { - description: "Get the supported matrix versions of this homeserver", - method: GET, - name: "get_server_versions", - unstable_path: "/_matrix/federation/unstable/org.matrix.msc3723/versions", - rate_limited: false, - authentication: None, + const METADATA: Metadata = metadata! { + description: "Get the supported matrix versions of this homeserver", + method: GET, + name: "get_server_versions", + rate_limited: false, + authentication: None, + history: { + unstable => "/_matrix/federation/unstable/org.matrix.msc3723/versions", } + }; - #[derive(Default)] - request: {} + #[request] + #[derive(Default)] + pub struct Request {} - #[derive(Default)] - response: { - /// A list of Matrix Server API protocol versions supported by the homeserver. - pub versions: Vec, - } + #[response] + #[derive(Default)] + pub struct Response { + /// A list of Matrix Server API protocol versions supported by the homeserver. + pub versions: Vec, } impl Request { diff --git a/crates/ruma-federation-api/src/event/get_event.rs b/crates/ruma-federation-api/src/event/get_event.rs index 1b22ede4..117109b7 100644 --- a/crates/ruma-federation-api/src/event/get_event.rs +++ b/crates/ruma-federation-api/src/event/get_event.rs @@ -7,37 +7,41 @@ pub mod v1 { //! //! [spec]: https://spec.matrix.org/v1.4/server-server-api/#get_matrixfederationv1eventeventid - use ruma_common::{api::ruma_api, EventId, MilliSecondsSinceUnixEpoch, OwnedServerName}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, EventId, MilliSecondsSinceUnixEpoch, OwnedServerName, + }; use serde_json::value::RawValue as RawJsonValue; - ruma_api! { - metadata: { - description: "Retrieves a single event.", - method: GET, - name: "get_event", - stable_path: "/_matrix/federation/v1/event/:event_id", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Retrieves a single event.", + method: GET, + name: "get_event", + rate_limited: false, + authentication: ServerSignatures, + history: { + 1.0 => "/_matrix/federation/v1/event/:event_id", } + }; - request: { - /// The event ID to get. - #[ruma_api(path)] - pub event_id: &'a EventId, - } + #[request] + pub struct Request<'a> { + /// The event ID to get. + #[ruma_api(path)] + pub event_id: &'a EventId, + } - response: { - /// The `server_name` of the homeserver sending this transaction. - pub origin: OwnedServerName, + #[response] + pub struct Response { + /// The `server_name` of the homeserver sending this transaction. + pub origin: OwnedServerName, - /// Time on originating homeserver when this transaction started. - pub origin_server_ts: MilliSecondsSinceUnixEpoch, + /// Time on originating homeserver when this transaction started. + pub origin_server_ts: MilliSecondsSinceUnixEpoch, - /// The event. - #[serde(rename = "pdus", with = "ruma_common::serde::single_element_seq")] - pub pdu: Box, - } + /// The event. + #[serde(rename = "pdus", with = "ruma_common::serde::single_element_seq")] + pub pdu: Box, } impl<'a> Request<'a> { diff --git a/crates/ruma-federation-api/src/event/get_missing_events.rs b/crates/ruma-federation-api/src/event/get_missing_events.rs index 87085109..627edead 100644 --- a/crates/ruma-federation-api/src/event/get_missing_events.rs +++ b/crates/ruma-federation-api/src/event/get_missing_events.rs @@ -8,51 +8,55 @@ pub mod v1 { //! [spec]: https://spec.matrix.org/v1.4/server-server-api/#post_matrixfederationv1get_missing_eventsroomid use js_int::{uint, UInt}; - use ruma_common::{api::ruma_api, OwnedEventId, RoomId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, OwnedEventId, RoomId, + }; use serde_json::value::RawValue as RawJsonValue; - ruma_api! { - metadata: { - description: "Retrieves previous events that the sender is missing.", - method: POST, - name: "get_missing_events", - stable_path: "/_matrix/federation/v1/get_missing_events/:room_id", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Retrieves previous events that the sender is missing.", + method: POST, + name: "get_missing_events", + rate_limited: false, + authentication: ServerSignatures, + history: { + 1.0 => "/_matrix/federation/v1/get_missing_events/:room_id", } + }; - request: { - /// The room ID to search in. - #[ruma_api(path)] - pub room_id: &'a RoomId, + #[request] + pub struct Request<'a> { + /// The room ID to search in. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The maximum number of events to retrieve. - /// - /// Defaults to 10. - #[serde(default = "default_limit", skip_serializing_if = "is_default_limit")] - pub limit: UInt, + /// The maximum number of events to retrieve. + /// + /// Defaults to 10. + #[serde(default = "default_limit", skip_serializing_if = "is_default_limit")] + pub limit: UInt, - /// The minimum depth of events to retrieve. - /// - /// Defaults to 0. - #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")] - pub min_depth: UInt, + /// The minimum depth of events to retrieve. + /// + /// Defaults to 0. + #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")] + pub min_depth: UInt, - /// The latest event IDs that the sender already has. - /// - /// These are skipped when retrieving the previous events of `latest_events`. - pub earliest_events: &'a [OwnedEventId], + /// The latest event IDs that the sender already has. + /// + /// These are skipped when retrieving the previous events of `latest_events`. + pub earliest_events: &'a [OwnedEventId], - /// The event IDs to retrieve the previous events for. - pub latest_events: &'a [OwnedEventId], - } + /// The event IDs to retrieve the previous events for. + pub latest_events: &'a [OwnedEventId], + } - #[derive(Default)] - response: { - /// The missing PDUs. - pub events: Vec>, - } + #[response] + #[derive(Default)] + pub struct Response { + /// The missing PDUs. + pub events: Vec>, } impl<'a> Request<'a> { diff --git a/crates/ruma-federation-api/src/event/get_room_state.rs b/crates/ruma-federation-api/src/event/get_room_state.rs index e088ce6c..f77e6188 100644 --- a/crates/ruma-federation-api/src/event/get_room_state.rs +++ b/crates/ruma-federation-api/src/event/get_room_state.rs @@ -7,38 +7,42 @@ pub mod v1 { //! //! [spec]: https://spec.matrix.org/v1.4/server-server-api/#get_matrixfederationv1stateroomid - use ruma_common::{api::ruma_api, EventId, RoomId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, EventId, RoomId, + }; use serde_json::value::RawValue as RawJsonValue; - ruma_api! { - metadata: { - description: "Retrieves a snapshot of a room's state at a given event.", - method: GET, - name: "get_room_state", - stable_path: "/_matrix/federation/v1/state/:room_id", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Retrieves a snapshot of a room's state at a given event.", + method: GET, + name: "get_room_state", + rate_limited: false, + authentication: ServerSignatures, + history: { + 1.0 => "/_matrix/federation/v1/state/:room_id", } + }; - request: { - /// The room ID to get state for. - #[ruma_api(path)] - pub room_id: &'a RoomId, + #[request] + pub struct Request<'a> { + /// The room ID to get state for. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// An event ID in the room to retrieve the state at. - #[ruma_api(query)] - pub event_id: &'a EventId, - } + /// An event ID in the room to retrieve the state at. + #[ruma_api(query)] + pub event_id: &'a EventId, + } - response: { - /// The full set of authorization events that make up the state of the - /// room, and their authorization events, recursively. - pub auth_chain: Vec>, + #[response] + pub struct Response { + /// The full set of authorization events that make up the state of the + /// room, and their authorization events, recursively. + pub auth_chain: Vec>, - /// The fully resolved state of the room at the given event. - pub pdus: Vec>, - } + /// The fully resolved state of the room at the given event. + pub pdus: Vec>, } impl<'a> Request<'a> { diff --git a/crates/ruma-federation-api/src/event/get_room_state_ids.rs b/crates/ruma-federation-api/src/event/get_room_state_ids.rs index 494eee77..371b0c8b 100644 --- a/crates/ruma-federation-api/src/event/get_room_state_ids.rs +++ b/crates/ruma-federation-api/src/event/get_room_state_ids.rs @@ -7,37 +7,41 @@ pub mod v1 { //! //! [spec]: https://spec.matrix.org/v1.4/server-server-api/#get_matrixfederationv1state_idsroomid - use ruma_common::{api::ruma_api, EventId, OwnedEventId, RoomId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, EventId, OwnedEventId, RoomId, + }; - ruma_api! { - metadata: { - description: "Retrieves a snapshot of a room's state at a given event, in the form of event IDs", - method: GET, - name: "get_room_state_ids", - stable_path: "/_matrix/federation/v1/state_ids/:room_id", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Retrieves a snapshot of a room's state at a given event, in the form of event IDs", + method: GET, + name: "get_room_state_ids", + rate_limited: false, + authentication: ServerSignatures, + history: { + 1.0 => "/_matrix/federation/v1/state_ids/:room_id", } + }; - request: { - /// The room ID to get state for. - #[ruma_api(path)] - pub room_id: &'a RoomId, + #[request] + pub struct Request<'a> { + /// The room ID to get state for. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// An event ID in the room to retrieve the state at. - #[ruma_api(query)] - pub event_id: &'a EventId, - } + /// An event ID in the room to retrieve the state at. + #[ruma_api(query)] + pub event_id: &'a EventId, + } - response: { - /// The full set of authorization events that make up the state of the - /// room, and their authorization events, recursively. - pub auth_chain_ids: Vec, + #[response] + pub struct Response { + /// The full set of authorization events that make up the state of the + /// room, and their authorization events, recursively. + pub auth_chain_ids: Vec, - /// The fully resolved state of the room at the given event. - pub pdu_ids: Vec, - } + /// The fully resolved state of the room at the given event. + pub pdu_ids: Vec, } impl<'a> Request<'a> { diff --git a/crates/ruma-federation-api/src/keys/claim_keys.rs b/crates/ruma-federation-api/src/keys/claim_keys.rs index 187f4cd9..da0b3e59 100644 --- a/crates/ruma-federation-api/src/keys/claim_keys.rs +++ b/crates/ruma-federation-api/src/keys/claim_keys.rs @@ -10,33 +10,35 @@ pub mod v1 { use std::collections::BTreeMap; use ruma_common::{ - api::ruma_api, + api::{request, response, Metadata}, encryption::OneTimeKey, + metadata, serde::{Base64, Raw}, DeviceKeyAlgorithm, OwnedDeviceId, OwnedDeviceKeyId, OwnedUserId, }; use serde::{Deserialize, Serialize}; - ruma_api! { - metadata: { - description: "Claims one-time keys for use in pre-key messages.", - method: POST, - name: "claim_keys", - stable_path: "/_matrix/federation/v1/user/keys/claim", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Claims one-time keys for use in pre-key messages.", + method: POST, + name: "claim_keys", + rate_limited: false, + authentication: ServerSignatures, + history: { + 1.0 => "/_matrix/federation/v1/user/keys/claim", } + }; - request: { - /// The keys to be claimed. - pub one_time_keys: OneTimeKeyClaims, - } + #[request] + pub struct Request { + /// The keys to be claimed. + pub one_time_keys: OneTimeKeyClaims, + } - response: { - /// One-time keys for the queried devices - pub one_time_keys: OneTimeKeys, - } + #[response] + pub struct Response { + /// One-time keys for the queried devices + pub one_time_keys: OneTimeKeys, } impl Request { diff --git a/crates/ruma-federation-api/src/keys/get_keys.rs b/crates/ruma-federation-api/src/keys/get_keys.rs index 6fa62157..22dcb66f 100644 --- a/crates/ruma-federation-api/src/keys/get_keys.rs +++ b/crates/ruma-federation-api/src/keys/get_keys.rs @@ -10,43 +10,45 @@ pub mod v1 { use std::collections::BTreeMap; use ruma_common::{ - api::ruma_api, + api::{request, response, Metadata}, encryption::{CrossSigningKey, DeviceKeys}, + metadata, serde::Raw, OwnedDeviceId, OwnedUserId, }; - ruma_api! { - metadata: { - description: "Returns the current devices and identity keys for the given users.", - method: POST, - name: "get_keys", - stable_path: "/_matrix/federation/v1/user/keys/query", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Returns the current devices and identity keys for the given users.", + method: POST, + name: "get_keys", + rate_limited: false, + authentication: ServerSignatures, + history: { + 1.0 => "/_matrix/federation/v1/user/keys/query", } + }; - request: { - /// The keys to be downloaded. - /// - /// Gives all keys for a given user if the list of device ids is empty. - pub device_keys: BTreeMap>, - } + #[request] + pub struct Request { + /// The keys to be downloaded. + /// + /// Gives all keys for a given user if the list of device ids is empty. + pub device_keys: BTreeMap>, + } - #[derive(Default)] - response: { - /// Keys from the queried devices. - pub device_keys: BTreeMap>>, + #[response] + #[derive(Default)] + pub struct Response { + /// Keys from the queried devices. + pub device_keys: BTreeMap>>, - /// Information on the master cross-signing keys of the queried users. - #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] - pub master_keys: BTreeMap>, + /// Information on the master cross-signing keys of the queried users. + #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] + pub master_keys: BTreeMap>, - /// Information on the self-signing keys of the queried users. - #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] - pub self_signing_keys: BTreeMap>, - } + /// Information on the self-signing keys of the queried users. + #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] + pub self_signing_keys: BTreeMap>, } impl Request { diff --git a/crates/ruma-federation-api/src/knock/create_knock_event_template.rs b/crates/ruma-federation-api/src/knock/create_knock_event_template.rs index e54c6dcc..d0136858 100644 --- a/crates/ruma-federation-api/src/knock/create_knock_event_template.rs +++ b/crates/ruma-federation-api/src/knock/create_knock_event_template.rs @@ -7,46 +7,50 @@ pub mod v1 { //! //! [spec]: https://spec.matrix.org/v1.4/server-server-api/#get_matrixfederationv1make_knockroomiduserid - use ruma_common::{api::ruma_api, RoomId, RoomVersionId, UserId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, RoomId, RoomVersionId, UserId, + }; use serde_json::value::RawValue as RawJsonValue; - ruma_api! { - metadata: { - description: "Send a request for a knock event template to a resident server.", - name: "create_knock_event_template", - method: GET, - unstable_path: "/_matrix/federation/unstable/xyz.amorgan.knock/make_knock/:room_id/:user_id", - stable_path: "/_matrix/federation/v1/make_knock/:room_id/:user_id", - rate_limited: false, - authentication: ServerSignatures, - added: 1.1, + const METADATA: Metadata = metadata! { + description: "Send a request for a knock event template to a resident server.", + name: "create_knock_event_template", + method: GET, + rate_limited: false, + authentication: ServerSignatures, + history: { + unstable => "/_matrix/federation/unstable/xyz.amorgan.knock/make_knock/:room_id/:user_id", + 1.1 => "/_matrix/federation/v1/make_knock/:room_id/:user_id", } + }; - request: { - /// The room ID that should receive the knock. - #[ruma_api(path)] - pub room_id: &'a RoomId, + #[request] + pub struct Request<'a> { + /// The room ID that should receive the knock. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The user ID the knock event will be for. - #[ruma_api(path)] - pub user_id: &'a UserId, + /// The user ID the knock event will be for. + #[ruma_api(path)] + pub user_id: &'a UserId, - /// The room versions the sending has support for. - /// - /// Defaults to `&[RoomVersionId::V1]`. - #[ruma_api(query)] - pub ver: &'a [RoomVersionId], - } + /// The room versions the sending has support for. + /// + /// Defaults to `&[RoomVersionId::V1]`. + #[ruma_api(query)] + pub ver: &'a [RoomVersionId], + } - response: { - /// The version of the room where the server is trying to knock. - pub room_version: RoomVersionId, + #[response] + pub struct Response { + /// The version of the room where the server is trying to knock. + pub room_version: RoomVersionId, - /// An unsigned template event. - /// - /// May differ between room versions. - pub event: Box, - } + /// An unsigned template event. + /// + /// May differ between room versions. + pub event: Box, } impl<'a> Request<'a> { diff --git a/crates/ruma-federation-api/src/knock/send_knock.rs b/crates/ruma-federation-api/src/knock/send_knock.rs index b21b9dfd..c6ffce6f 100644 --- a/crates/ruma-federation-api/src/knock/send_knock.rs +++ b/crates/ruma-federation-api/src/knock/send_knock.rs @@ -7,39 +7,46 @@ pub mod v1 { //! //! [spec]: https://spec.matrix.org/v1.4/server-server-api/#put_matrixfederationv1send_knockroomideventid - use ruma_common::{api::ruma_api, events::AnyStrippedStateEvent, serde::Raw, EventId, RoomId}; + use ruma_common::{ + api::{request, response, Metadata}, + events::AnyStrippedStateEvent, + metadata, + serde::Raw, + EventId, RoomId, + }; use serde_json::value::RawValue as RawJsonValue; - ruma_api! { - metadata: { - description: "Submits a signed knock event to the resident homeserver for it to accept into the room's graph.", - name: "send_knock", - method: PUT, - unstable_path: "/_matrix/federation/unstable/xyz.amorgan.knock/send_knock/:room_id/:event_id", - stable_path: "/_matrix/federation/v1/send_knock/:room_id/:event_id", - rate_limited: false, - authentication: ServerSignatures, - added: 1.1, + const METADATA: Metadata = metadata! { + description: "Submits a signed knock event to the resident homeserver for it to accept into the room's graph.", + name: "send_knock", + method: PUT, + rate_limited: false, + authentication: ServerSignatures, + history: { + unstable => "/_matrix/federation/unstable/xyz.amorgan.knock/send_knock/:room_id/:event_id", + 1.1 => "/_matrix/federation/v1/send_knock/:room_id/:event_id", } + }; - request: { - /// The room ID that should receive the knock. - #[ruma_api(path)] - pub room_id: &'a RoomId, + #[request] + pub struct Request<'a> { + /// The room ID that should receive the knock. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The event ID for the knock event. - #[ruma_api(path)] - pub event_id: &'a EventId, + /// The event ID for the knock event. + #[ruma_api(path)] + pub event_id: &'a EventId, - /// The PDU. - #[ruma_api(body)] - pub pdu: &'a RawJsonValue, - } + /// The PDU. + #[ruma_api(body)] + pub pdu: &'a RawJsonValue, + } - response: { - /// State events providing public room metadata. - pub knock_room_state: Vec>, - } + #[response] + pub struct Response { + /// State events providing public room metadata. + pub knock_room_state: Vec>, } impl<'a> Request<'a> { diff --git a/crates/ruma-federation-api/src/lib.rs b/crates/ruma-federation-api/src/lib.rs index bc65528f..b5d17993 100644 --- a/crates/ruma-federation-api/src/lib.rs +++ b/crates/ruma-federation-api/src/lib.rs @@ -5,7 +5,7 @@ //! //! [federation-api]: https://spec.matrix.org/v1.4/server-server-api/ -#![warn(missing_docs)] +// #![warn(missing_docs)] FIXME #![cfg_attr(docsrs, feature(doc_auto_cfg))] use std::fmt; diff --git a/crates/ruma-federation-api/src/membership/create_invite/v1.rs b/crates/ruma-federation-api/src/membership/create_invite/v1.rs index a07496e3..7f2b59d4 100644 --- a/crates/ruma-federation-api/src/membership/create_invite/v1.rs +++ b/crates/ruma-federation-api/src/membership/create_invite/v1.rs @@ -3,64 +3,66 @@ //! [spec]: https://spec.matrix.org/v1.4/server-server-api/#put_matrixfederationv1inviteroomideventid use ruma_common::{ - api::ruma_api, + api::{request, response, Metadata}, events::{room::member::RoomMemberEventContent, AnyStrippedStateEvent, StateEventType}, + metadata, serde::Raw, EventId, MilliSecondsSinceUnixEpoch, RoomId, ServerName, UserId, }; use serde::{Deserialize, Serialize}; use serde_json::value::RawValue as RawJsonValue; -ruma_api! { - metadata: { - description: "Invites a remote user to a room.", - method: PUT, - name: "create_invite", - stable_path: "/_matrix/federation/v1/invite/:room_id/:event_id", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, +const METADATA: Metadata = metadata! { + description: "Invites a remote user to a room.", + method: PUT, + name: "create_invite", + rate_limited: false, + authentication: ServerSignatures, + history: { + 1.0 => "/_matrix/federation/v1/invite/:room_id/:event_id", } +}; - request: { - /// The room ID that the user is being invited to. - #[ruma_api(path)] - pub room_id: &'a RoomId, +#[request] +pub struct Request<'a> { + /// The room ID that the user is being invited to. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The event ID for the invite event, generated by the inviting server. - #[ruma_api(path)] - pub event_id: &'a EventId, + /// The event ID for the invite event, generated by the inviting server. + #[ruma_api(path)] + pub event_id: &'a EventId, - /// The matrix ID of the user who sent the original `m.room.third_party_invite`. - pub sender: &'a UserId, + /// The matrix ID of the user who sent the original `m.room.third_party_invite`. + pub sender: &'a UserId, - /// The name of the inviting homeserver. - pub origin: &'a ServerName, + /// The name of the inviting homeserver. + pub origin: &'a ServerName, - /// A timestamp added by the inviting homeserver. - pub origin_server_ts: MilliSecondsSinceUnixEpoch, + /// A timestamp added by the inviting homeserver. + pub origin_server_ts: MilliSecondsSinceUnixEpoch, - /// The value `m.room.member`. - #[serde(rename = "type")] - pub kind: StateEventType, + /// The value `m.room.member`. + #[serde(rename = "type")] + pub kind: StateEventType, - /// The user ID of the invited member. - pub state_key: &'a UserId, + /// The user ID of the invited member. + pub state_key: &'a UserId, - /// The content of the event. - pub content: RoomMemberEventContent, + /// The content of the event. + pub content: RoomMemberEventContent, - /// Information included alongside the event that is not signed. - #[serde(default, skip_serializing_if = "UnsignedEventContent::is_empty")] - pub unsigned: UnsignedEventContent, - } + /// Information included alongside the event that is not signed. + #[serde(default, skip_serializing_if = "UnsignedEventContent::is_empty")] + pub unsigned: UnsignedEventContent, +} - response: { - /// The signed invite event. - #[ruma_api(body)] - #[serde(with = "crate::serde::v1_pdu")] - pub event: Box, - } +#[response] +pub struct Response { + /// The signed invite event. + #[ruma_api(body)] + #[serde(with = "crate::serde::v1_pdu")] + pub event: Box, } /// Information included alongside an event that is not signed. diff --git a/crates/ruma-federation-api/src/membership/create_invite/v2.rs b/crates/ruma-federation-api/src/membership/create_invite/v2.rs index 974e9c29..049c219b 100644 --- a/crates/ruma-federation-api/src/membership/create_invite/v2.rs +++ b/crates/ruma-federation-api/src/membership/create_invite/v2.rs @@ -3,44 +3,49 @@ //! [spec]: https://spec.matrix.org/v1.4/server-server-api/#put_matrixfederationv2inviteroomideventid use ruma_common::{ - api::ruma_api, events::AnyStrippedStateEvent, serde::Raw, EventId, RoomId, RoomVersionId, + api::{request, response, Metadata}, + events::AnyStrippedStateEvent, + metadata, + serde::Raw, + EventId, RoomId, RoomVersionId, }; use serde_json::value::RawValue as RawJsonValue; -ruma_api! { - metadata: { - description: "Invites a remote user to a room.", - method: PUT, - name: "create_invite", - stable_path: "/_matrix/federation/v2/invite/:room_id/:event_id", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, +const METADATA: Metadata = metadata! { + description: "Invites a remote user to a room.", + method: PUT, + name: "create_invite", + rate_limited: false, + authentication: ServerSignatures, + history: { + 1.0 => "/_matrix/federation/v2/invite/:room_id/:event_id", } +}; - request: { - /// The room ID that the user is being invited to. - #[ruma_api(path)] - pub room_id: &'a RoomId, +#[request] +pub struct Request<'a> { + /// The room ID that the user is being invited to. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The event ID for the invite event, generated by the inviting server. - #[ruma_api(path)] - pub event_id: &'a EventId, + /// The event ID for the invite event, generated by the inviting server. + #[ruma_api(path)] + pub event_id: &'a EventId, - /// The version of the room where the user is being invited to. - pub room_version: &'a RoomVersionId, + /// The version of the room where the user is being invited to. + pub room_version: &'a RoomVersionId, - /// The invite event which needs to be signed. - pub event: &'a RawJsonValue, + /// The invite event which needs to be signed. + pub event: &'a RawJsonValue, - /// An optional list of simplified events to help the receiver of the invite identify the room. - pub invite_room_state: &'a [Raw], - } + /// An optional list of simplified events to help the receiver of the invite identify the room. + pub invite_room_state: &'a [Raw], +} - response: { - /// The signed invite event. - pub event: Box, - } +#[response] +pub struct Response { + /// The signed invite event. + pub event: Box, } impl<'a> Request<'a> { diff --git a/crates/ruma-federation-api/src/membership/create_join_event/v1.rs b/crates/ruma-federation-api/src/membership/create_join_event/v1.rs index 6bb2c4ae..a8c9691a 100644 --- a/crates/ruma-federation-api/src/membership/create_join_event/v1.rs +++ b/crates/ruma-federation-api/src/membership/create_join_event/v1.rs @@ -2,44 +2,48 @@ //! //! [spec]: https://spec.matrix.org/v1.4/server-server-api/#put_matrixfederationv1send_joinroomideventid -use ruma_common::{api::ruma_api, EventId, RoomId}; +use ruma_common::{ + api::{request, response, Metadata}, + metadata, EventId, RoomId, +}; use serde_json::value::RawValue as RawJsonValue; use super::RoomState; -ruma_api! { - metadata: { - description: "Send a join event to a resident server.", - name: "create_join_event", - method: PUT, - stable_path: "/_matrix/federation/v1/send_join/:room_id/:event_id", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, +const METADATA: Metadata = metadata! { + description: "Send a join event to a resident server.", + name: "create_join_event", + method: PUT, + rate_limited: false, + authentication: ServerSignatures, + history: { + 1.0 => "/_matrix/federation/v1/send_join/:room_id/:event_id", } +}; - request: { - /// The room ID that is about to be joined. - /// - /// Do not use this. Instead, use the `room_id` field inside the PDU. - #[ruma_api(path)] - pub room_id: &'a RoomId, +#[request] +pub struct Request<'a> { + /// The room ID that is about to be joined. + /// + /// Do not use this. Instead, use the `room_id` field inside the PDU. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The event ID for the join event. - #[ruma_api(path)] - pub event_id: &'a EventId, + /// The event ID for the join event. + #[ruma_api(path)] + pub event_id: &'a EventId, - /// The PDU. - #[ruma_api(body)] - pub pdu: &'a RawJsonValue, - } + /// The PDU. + #[ruma_api(body)] + pub pdu: &'a RawJsonValue, +} - response: { - /// Full state and auth chain of the room prior to the join event. - #[ruma_api(body)] - #[serde(with = "crate::serde::v1_pdu")] - pub room_state: RoomState, - } +#[response] +pub struct Response { + /// Full state and auth chain of the room prior to the join event. + #[ruma_api(body)] + #[serde(with = "crate::serde::v1_pdu")] + pub room_state: RoomState, } impl<'a> Request<'a> { diff --git a/crates/ruma-federation-api/src/membership/create_join_event/v2.rs b/crates/ruma-federation-api/src/membership/create_join_event/v2.rs index c487c96f..605475a9 100644 --- a/crates/ruma-federation-api/src/membership/create_join_event/v2.rs +++ b/crates/ruma-federation-api/src/membership/create_join_event/v2.rs @@ -2,43 +2,47 @@ //! //! [spec]: https://spec.matrix.org/v1.4/server-server-api/#put_matrixfederationv2send_joinroomideventid -use ruma_common::{api::ruma_api, EventId, RoomId}; +use ruma_common::{ + api::{request, response, Metadata}, + metadata, EventId, RoomId, +}; use serde_json::value::RawValue as RawJsonValue; use super::RoomState; -ruma_api! { - metadata: { - description: "Send a join event to a resident server.", - name: "create_join_event", - method: PUT, - stable_path: "/_matrix/federation/v2/send_join/:room_id/:event_id", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, +const METADATA: Metadata = metadata! { + description: "Send a join event to a resident server.", + name: "create_join_event", + method: PUT, + rate_limited: false, + authentication: ServerSignatures, + history: { + 1.0 => "/_matrix/federation/v2/send_join/:room_id/:event_id", } +}; - request: { - /// The room ID that is about to be joined. - /// - /// Do not use this. Instead, use the `room_id` field inside the PDU. - #[ruma_api(path)] - pub room_id: &'a RoomId, +#[request] +pub struct Request<'a> { + /// The room ID that is about to be joined. + /// + /// Do not use this. Instead, use the `room_id` field inside the PDU. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The event ID for the join event. - #[ruma_api(path)] - pub event_id: &'a EventId, + /// The event ID for the join event. + #[ruma_api(path)] + pub event_id: &'a EventId, - /// The PDU. - #[ruma_api(body)] - pub pdu: &'a RawJsonValue, - } + /// The PDU. + #[ruma_api(body)] + pub pdu: &'a RawJsonValue, +} - response: { - /// Full state of the room. - #[ruma_api(body)] - pub room_state: RoomState, - } +#[response] +pub struct Response { + /// Full state of the room. + #[ruma_api(body)] + pub room_state: RoomState, } impl<'a> Request<'a> { diff --git a/crates/ruma-federation-api/src/membership/create_leave_event/v1.rs b/crates/ruma-federation-api/src/membership/create_leave_event/v1.rs index aab90b72..2b03ea6b 100644 --- a/crates/ruma-federation-api/src/membership/create_leave_event/v1.rs +++ b/crates/ruma-federation-api/src/membership/create_leave_event/v1.rs @@ -4,72 +4,74 @@ use js_int::UInt; use ruma_common::{ - api::ruma_api, + api::{request, response, Metadata}, events::{room::member::RoomMemberEventContent, StateEventType}, + metadata, serde::Raw, EventId, MilliSecondsSinceUnixEpoch, RoomId, ServerName, UserId, }; use serde::{Deserialize, Serialize}; -ruma_api! { - metadata: { - description: "Submits a signed leave event to the receiving server for it to accept it into the room's graph.", - name: "create_leave_event", - method: PUT, - stable_path: "/_matrix/federation/v1/send_leave/:room_id/:event_id", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, +const METADATA: Metadata = metadata! { + description: "Submits a signed leave event to the receiving server for it to accept it into the room's graph.", + name: "create_leave_event", + method: PUT, + rate_limited: false, + authentication: ServerSignatures, + history: { + 1.0 => "/_matrix/federation/v1/send_leave/:room_id/:event_id", } +}; - request: { - /// The room ID that is about to be left. - #[ruma_api(path)] - pub room_id: &'a RoomId, +#[request] +pub struct Request<'a> { + /// The room ID that is about to be left. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The event ID for the leave event. - #[ruma_api(path)] - pub event_id: &'a EventId, + /// The event ID for the leave event. + #[ruma_api(path)] + pub event_id: &'a EventId, - /// The user ID of the leaving member. - #[ruma_api(query)] - pub sender: &'a UserId, + /// The user ID of the leaving member. + #[ruma_api(query)] + pub sender: &'a UserId, - /// The name of the leaving homeserver. - #[ruma_api(query)] - pub origin: &'a ServerName, + /// The name of the leaving homeserver. + #[ruma_api(query)] + pub origin: &'a ServerName, - /// A timestamp added by the leaving homeserver. - #[ruma_api(query)] - pub origin_server_ts: MilliSecondsSinceUnixEpoch, + /// A timestamp added by the leaving homeserver. + #[ruma_api(query)] + pub origin_server_ts: MilliSecondsSinceUnixEpoch, - /// The value `m.room.member`. - #[ruma_api(query)] - #[serde(rename = "type")] - pub event_type: StateEventType, + /// The value `m.room.member`. + #[ruma_api(query)] + #[serde(rename = "type")] + pub event_type: StateEventType, - /// The user ID of the leaving member. - #[ruma_api(query)] - pub state_key: &'a str, + /// The user ID of the leaving member. + #[ruma_api(query)] + pub state_key: &'a str, - /// The content of the event. - #[ruma_api(query)] - pub content: Raw, + /// The content of the event. + #[ruma_api(query)] + pub content: Raw, - /// This field must be present but is ignored; it may be 0. - #[ruma_api(query)] - pub depth: UInt, - } + /// This field must be present but is ignored; it may be 0. + #[ruma_api(query)] + pub depth: UInt, +} - #[derive(Default)] - response: { - /// An empty object. - /// - /// Indicates that the event was accepted into the event graph. - #[ruma_api(body)] - #[serde(with = "crate::serde::v1_pdu")] - pub empty: Empty, - } +#[response] +#[derive(Default)] +pub struct Response { + /// An empty object. + /// + /// Indicates that the event was accepted into the event graph. + #[ruma_api(body)] + #[serde(with = "crate::serde::v1_pdu")] + pub empty: Empty, } /// Initial set of fields of `Request`. diff --git a/crates/ruma-federation-api/src/membership/create_leave_event/v2.rs b/crates/ruma-federation-api/src/membership/create_leave_event/v2.rs index c4339fba..f9a3525d 100644 --- a/crates/ruma-federation-api/src/membership/create_leave_event/v2.rs +++ b/crates/ruma-federation-api/src/membership/create_leave_event/v2.rs @@ -2,40 +2,44 @@ //! //! [spec]: https://spec.matrix.org/v1.4/server-server-api/#put_matrixfederationv2send_leaveroomideventid -use ruma_common::{api::ruma_api, EventId, RoomId}; +use ruma_common::{ + api::{request, response, Metadata}, + metadata, EventId, RoomId, +}; use serde_json::value::RawValue as RawJsonValue; -ruma_api! { - metadata: { - description: "Submits a signed leave event to the receiving server for it to accept it into the room's graph.", - name: "create_leave_event", - method: PUT, - stable_path: "/_matrix/federation/v2/send_leave/:room_id/:event_id", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, +const METADATA: Metadata = metadata! { + description: "Submits a signed leave event to the receiving server for it to accept it into the room's graph.", + name: "create_leave_event", + method: PUT, + rate_limited: false, + authentication: ServerSignatures, + history: { + 1.0 => "/_matrix/federation/v2/send_leave/:room_id/:event_id", } +}; - request: { - /// The room ID that is about to be left. - /// - /// Do not use this. Instead, use the `room_id` field inside the PDU. - #[ruma_api(path)] - pub room_id: &'a RoomId, +#[request] +pub struct Request<'a> { + /// The room ID that is about to be left. + /// + /// Do not use this. Instead, use the `room_id` field inside the PDU. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The event ID for the leave event. - #[ruma_api(path)] - pub event_id: &'a EventId, + /// The event ID for the leave event. + #[ruma_api(path)] + pub event_id: &'a EventId, - /// The PDU. - #[ruma_api(body)] - pub pdu: &'a RawJsonValue, - } - - #[derive(Default)] - response: {} + /// The PDU. + #[ruma_api(body)] + pub pdu: &'a RawJsonValue, } +#[response] +#[derive(Default)] +pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` from the given room ID, event ID and PDU. pub fn new(room_id: &'a RoomId, event_id: &'a EventId, pdu: &'a RawJsonValue) -> Self { diff --git a/crates/ruma-federation-api/src/membership/prepare_join_event.rs b/crates/ruma-federation-api/src/membership/prepare_join_event.rs index 3d4ed768..43d1d76c 100644 --- a/crates/ruma-federation-api/src/membership/prepare_join_event.rs +++ b/crates/ruma-federation-api/src/membership/prepare_join_event.rs @@ -7,45 +7,49 @@ pub mod v1 { //! //! [spec]: https://spec.matrix.org/v1.4/server-server-api/#get_matrixfederationv1make_joinroomiduserid - use ruma_common::{api::ruma_api, RoomId, RoomVersionId, UserId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, RoomId, RoomVersionId, UserId, + }; use serde_json::value::RawValue as RawJsonValue; - ruma_api! { - metadata: { - description: "Send a request for a join event template to a resident server.", - name: "create_join_event_template", - method: GET, - stable_path: "/_matrix/federation/v1/make_join/:room_id/:user_id", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Send a request for a join event template to a resident server.", + method: GET, + name: "create_join_event_template", + rate_limited: false, + authentication: ServerSignatures, + history: { + 1.0 => "/_matrix/federation/v1/make_join/:room_id/:user_id", } + }; - request: { - /// The room ID that is about to be joined. - #[ruma_api(path)] - pub room_id: &'a RoomId, + #[request] + pub struct Request<'a> { + /// The room ID that is about to be joined. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The user ID the join event will be for. - #[ruma_api(path)] - pub user_id: &'a UserId, + /// The user ID the join event will be for. + #[ruma_api(path)] + pub user_id: &'a UserId, - /// The room versions the sending server has support for. - /// - /// Defaults to `&[RoomVersionId::V1]`. - #[ruma_api(query)] - #[serde(default = "default_ver", skip_serializing_if = "is_default_ver")] - pub ver: &'a [RoomVersionId], - } + /// The room versions the sending server has support for. + /// + /// Defaults to `&[RoomVersionId::V1]`. + #[ruma_api(query)] + #[serde(default = "default_ver", skip_serializing_if = "is_default_ver")] + pub ver: &'a [RoomVersionId], + } - response: { - /// The version of the room where the server is trying to join. - #[serde(skip_serializing_if = "Option::is_none")] - pub room_version: Option, + #[response] + pub struct Response { + /// The version of the room where the server is trying to join. + #[serde(skip_serializing_if = "Option::is_none")] + pub room_version: Option, - /// An unsigned template event. - pub event: Box, - } + /// An unsigned template event. + pub event: Box, } fn default_ver() -> Vec { diff --git a/crates/ruma-federation-api/src/membership/prepare_leave_event.rs b/crates/ruma-federation-api/src/membership/prepare_leave_event.rs index 8158b6c4..30b003af 100644 --- a/crates/ruma-federation-api/src/membership/prepare_leave_event.rs +++ b/crates/ruma-federation-api/src/membership/prepare_leave_event.rs @@ -8,42 +8,46 @@ pub mod v1 { //! //! [spec]: https://spec.matrix.org/v1.4/server-server-api/#get_matrixfederationv1make_leaveroomiduserid - use ruma_common::{api::ruma_api, RoomId, RoomVersionId, UserId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, RoomId, RoomVersionId, UserId, + }; use serde_json::value::RawValue as RawJsonValue; - ruma_api! { - metadata: { - description: "Asks the receiving server to return information that the sending server will need to prepare a leave event to get out of the room.", - name: "get_leave_event", - method: GET, - stable_path: "/_matrix/federation/v1/make_leave/:room_id/:user_id", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Asks the receiving server to return information that the sending server will need to prepare a leave event to get out of the room.", + method: GET, + name: "get_leave_event", + rate_limited: false, + authentication: ServerSignatures, + history: { + 1.0 => "/_matrix/federation/v1/make_leave/:room_id/:user_id", } + }; - request: { - /// The room ID that is about to be left. - #[ruma_api(path)] - pub room_id: &'a RoomId, + #[request] + pub struct Request<'a> { + /// The room ID that is about to be left. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The user ID the leave event will be for. - #[ruma_api(path)] - pub user_id: &'a UserId, - } + /// The user ID the leave event will be for. + #[ruma_api(path)] + pub user_id: &'a UserId, + } - response: { - /// The version of the room where the server is trying to leave. - /// - /// If not provided, the room version is assumed to be either "1" or "2". - pub room_version: Option, + #[response] + pub struct Response { + /// The version of the room where the server is trying to leave. + /// + /// If not provided, the room version is assumed to be either "1" or "2". + pub room_version: Option, - /// An unsigned template event. - /// - /// Note that events have a different format depending on the room version - check the room - /// version specification for precise event formats. - pub event: Box, - } + /// An unsigned template event. + /// + /// Note that events have a different format depending on the room version - check the room + /// version specification for precise event formats. + pub event: Box, } impl<'a> Request<'a> { diff --git a/crates/ruma-federation-api/src/openid/get_openid_userinfo.rs b/crates/ruma-federation-api/src/openid/get_openid_userinfo.rs index f03afdbf..9bfb8455 100644 --- a/crates/ruma-federation-api/src/openid/get_openid_userinfo.rs +++ b/crates/ruma-federation-api/src/openid/get_openid_userinfo.rs @@ -7,29 +7,33 @@ pub mod v1 { //! //! [spec]: https://spec.matrix.org/v1.4/server-server-api/#get_matrixfederationv1openiduserinfo - use ruma_common::{api::ruma_api, OwnedUserId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, OwnedUserId, + }; - ruma_api! { - metadata: { - description: "Exchanges an OpenID access token for information about the user who generated the token.", - method: GET, - name: "get_openid_userinfo", - stable_path: "/_matrix/federation/v1/openid/userinfo", - rate_limited: false, - authentication: None, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Exchanges an OpenID access token for information about the user who generated the token.", + method: GET, + name: "get_openid_userinfo", + rate_limited: false, + authentication: None, + history: { + 1.0 => "/_matrix/federation/v1/openid/userinfo", } + }; - request: { - /// The OpenID access token to get information about the owner for. - #[ruma_api(query)] - pub access_token: &'a str, - } + #[request] + pub struct Request<'a> { + /// The OpenID access token to get information about the owner for. + #[ruma_api(query)] + pub access_token: &'a str, + } - response: { - /// The Matrix User ID who generated the token. - pub sub: OwnedUserId, - } + #[response] + pub struct Response { + /// The Matrix User ID who generated the token. + pub sub: OwnedUserId, } impl<'a> Request<'a> { diff --git a/crates/ruma-federation-api/src/query/get_custom_information.rs b/crates/ruma-federation-api/src/query/get_custom_information.rs index 1c76a43a..d8755237 100644 --- a/crates/ruma-federation-api/src/query/get_custom_information.rs +++ b/crates/ruma-federation-api/src/query/get_custom_information.rs @@ -9,35 +9,39 @@ pub mod v1 { use std::collections::BTreeMap; - use ruma_common::api::ruma_api; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + }; use serde_json::Value as JsonValue; - ruma_api! { - metadata: { - description: "Performs a single query request on the receiving homeserver. The query string arguments are dependent on which type of query is being made.", - method: GET, - name: "get_custom_information", - stable_path: "/_matrix/federation/v1/query/:query_type", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Performs a single query request on the receiving homeserver. The query string arguments are dependent on which type of query is being made.", + method: GET, + name: "get_custom_information", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/federation/v1/query/:query_type", } + }; - request: { - /// The type of query to make. - #[ruma_api(path)] - pub query_type: &'a str, + #[request] + pub struct Request<'a> { + /// The type of query to make. + #[ruma_api(path)] + pub query_type: &'a str, - /// The query parameters. - #[ruma_api(query_map)] - pub params: BTreeMap, - } + /// The query parameters. + #[ruma_api(query_map)] + pub params: BTreeMap, + } - response: { - /// The body of the response. - #[ruma_api(body)] - pub body: JsonValue, - } + #[response] + pub struct Response { + /// The body of the response. + #[ruma_api(body)] + pub body: JsonValue, } impl<'a> Request<'a> { diff --git a/crates/ruma-federation-api/src/query/get_profile_information.rs b/crates/ruma-federation-api/src/query/get_profile_information.rs index 39292fa9..c38149a9 100644 --- a/crates/ruma-federation-api/src/query/get_profile_information.rs +++ b/crates/ruma-federation-api/src/query/get_profile_information.rs @@ -7,57 +7,63 @@ pub mod v1 { //! //! [spec]: https://spec.matrix.org/v1.4/server-server-api/#get_matrixfederationv1queryprofile - use ruma_common::{api::ruma_api, serde::StringEnum, OwnedMxcUri, UserId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + serde::StringEnum, + OwnedMxcUri, UserId, + }; use crate::PrivOwnedStr; - ruma_api! { - metadata: { - description: "Get profile information, such as a display name or avatar, for a given user.", - name: "get_profile_information", - method: GET, - stable_path: "/_matrix/federation/v1/query/profile", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Get profile information, such as a display name or avatar, for a given user.", + method: GET, + name: "get_profile_information", + rate_limited: false, + authentication: ServerSignatures, + history: { + 1.0 => "/_matrix/federation/v1/query/profile", } + }; - request: { - /// User ID to query. - #[ruma_api(query)] - pub user_id: &'a UserId, + #[request] + pub struct Request<'a> { + /// User ID to query. + #[ruma_api(query)] + pub user_id: &'a UserId, - /// Profile field to query. - #[serde(skip_serializing_if = "Option::is_none")] - #[ruma_api(query)] - pub field: Option<&'a ProfileField>, - } + /// Profile field to query. + #[serde(skip_serializing_if = "Option::is_none")] + #[ruma_api(query)] + pub field: Option<&'a ProfileField>, + } - #[derive(Default)] - response: { - /// Display name of the user. - #[serde(skip_serializing_if = "Option::is_none")] - pub displayname: Option, + #[response] + #[derive(Default)] + pub struct Response { + /// Display name of the user. + #[serde(skip_serializing_if = "Option::is_none")] + pub displayname: Option, - /// Avatar URL for the user's avatar. - /// - /// If you activate the `compat` feature, this field being an empty string in JSON will result - /// in `None` here during deserialization. - #[serde(skip_serializing_if = "Option::is_none")] - #[cfg_attr( - feature = "compat", - serde(default, deserialize_with = "ruma_common::serde::empty_string_as_none") - )] - pub avatar_url: Option, + /// Avatar URL for the user's avatar. + /// + /// If you activate the `compat` feature, this field being an empty string in JSON will + /// result in `None` here during deserialization. + #[serde(skip_serializing_if = "Option::is_none")] + #[cfg_attr( + feature = "compat", + serde(default, deserialize_with = "ruma_common::serde::empty_string_as_none") + )] + pub avatar_url: Option, - /// The [BlurHash](https://blurha.sh) for the avatar pointed to by `avatar_url`. - /// - /// This uses the unstable prefix in - /// [MSC2448](https://github.com/matrix-org/matrix-spec-proposals/pull/2448). - #[cfg(feature = "unstable-msc2448")] - #[serde(rename = "xyz.amorgan.blurhash", skip_serializing_if = "Option::is_none")] - pub blurhash: Option, - } + /// The [BlurHash](https://blurha.sh) for the avatar pointed to by `avatar_url`. + /// + /// This uses the unstable prefix in + /// [MSC2448](https://github.com/matrix-org/matrix-spec-proposals/pull/2448). + #[cfg(feature = "unstable-msc2448")] + #[serde(rename = "xyz.amorgan.blurhash", skip_serializing_if = "Option::is_none")] + pub blurhash: Option, } impl<'a> Request<'a> { diff --git a/crates/ruma-federation-api/src/query/get_room_information.rs b/crates/ruma-federation-api/src/query/get_room_information.rs index 288bcb33..d6e687a8 100644 --- a/crates/ruma-federation-api/src/query/get_room_information.rs +++ b/crates/ruma-federation-api/src/query/get_room_information.rs @@ -7,32 +7,36 @@ pub mod v1 { //! //! [spec]: https://spec.matrix.org/v1.4/server-server-api/#get_matrixfederationv1querydirectory - use ruma_common::{api::ruma_api, OwnedRoomId, OwnedServerName, RoomAliasId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, OwnedRoomId, OwnedServerName, RoomAliasId, + }; - ruma_api! { - metadata: { - description: "Get mapped room ID and resident homeservers for a given room alias.", - name: "get_room_information", - method: GET, - stable_path: "/_matrix/federation/v1/query/directory", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Get mapped room ID and resident homeservers for a given room alias.", + method: GET, + name: "get_room_information", + rate_limited: false, + authentication: ServerSignatures, + history: { + 1.0 => "/_matrix/federation/v1/query/directory", } + }; - request: { - /// Room alias to query. - #[ruma_api(query)] - pub room_alias: &'a RoomAliasId, - } + #[request] + pub struct Request<'a> { + /// Room alias to query. + #[ruma_api(query)] + pub room_alias: &'a RoomAliasId, + } - response: { - /// Room ID mapped to queried alias. - pub room_id: OwnedRoomId, + #[response] + pub struct Response { + /// Room ID mapped to queried alias. + pub room_id: OwnedRoomId, - /// An array of server names that are likely to hold the given room. - pub servers: Vec, - } + /// An array of server names that are likely to hold the given room. + pub servers: Vec, } impl<'a> Request<'a> { diff --git a/crates/ruma-federation-api/src/space/get_hierarchy.rs b/crates/ruma-federation-api/src/space/get_hierarchy.rs index 985e0303..1b6d32b3 100644 --- a/crates/ruma-federation-api/src/space/get_hierarchy.rs +++ b/crates/ruma-federation-api/src/space/get_hierarchy.rs @@ -7,50 +7,54 @@ pub mod v1 { //! //! [spec]: https://spec.matrix.org/v1.4/server-server-api/#get_matrixfederationv1hierarchyroomid - use ruma_common::{api::ruma_api, OwnedRoomId, RoomId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, OwnedRoomId, RoomId, + }; use crate::space::{SpaceHierarchyChildSummary, SpaceHierarchyParentSummary}; - ruma_api! { - metadata: { - description: "Get the space tree in a depth-first manner to locate child rooms of a given space.", - name: "hierarchy", - method: GET, - unstable_path: "/_matrix/federation/unstable/org.matrix.msc2946/hierarchy/:room_id", - stable_path: "/_matrix/federation/v1/hierarchy/:room_id", - rate_limited: false, - authentication: ServerSignatures, - added: 1.2, + const METADATA: Metadata = metadata! { + description: "Get the space tree in a depth-first manner to locate child rooms of a given space.", + name: "hierarchy", + method: GET, + rate_limited: false, + authentication: ServerSignatures, + history: { + unstable => "/_matrix/federation/unstable/org.matrix.msc2946/hierarchy/:room_id", + 1.2 => "/_matrix/federation/v1/hierarchy/:room_id", } + }; - request: { - /// The room ID of the space to get a hierarchy for. - #[ruma_api(path)] - pub room_id: &'a RoomId, + #[request] + pub struct Request<'a> { + /// The room ID of the space to get a hierarchy for. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// Whether or not the server should only consider suggested rooms. - /// - /// Suggested rooms are annotated in their `m.space.child` event contents. - #[ruma_api(query)] - #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")] - pub suggested_only: bool, - } + /// Whether or not the server should only consider suggested rooms. + /// + /// Suggested rooms are annotated in their `m.space.child` event contents. + #[ruma_api(query)] + #[serde(default, skip_serializing_if = "ruma_common::serde::is_default")] + pub suggested_only: bool, + } - response: { - /// A summary of the space’s children. - /// - /// Rooms which the requesting server cannot peek/join will be excluded. - pub children: Vec, + #[response] + pub struct Response { + /// A summary of the space’s children. + /// + /// Rooms which the requesting server cannot peek/join will be excluded. + pub children: Vec, - /// The list of room IDs the requesting server doesn’t have a viable way to peek/join. - /// - /// Rooms which the responding server cannot provide details on will be outright - /// excluded from the response instead. - pub inaccessible_children: Vec, + /// The list of room IDs the requesting server doesn’t have a viable way to peek/join. + /// + /// Rooms which the responding server cannot provide details on will be outright + /// excluded from the response instead. + pub inaccessible_children: Vec, - /// A summary of the requested room. - pub room: SpaceHierarchyParentSummary, - } + /// A summary of the requested room. + pub room: SpaceHierarchyParentSummary, } impl<'a> Request<'a> { diff --git a/crates/ruma-federation-api/src/thirdparty/bind_callback.rs b/crates/ruma-federation-api/src/thirdparty/bind_callback.rs index 820ec363..64304866 100644 --- a/crates/ruma-federation-api/src/thirdparty/bind_callback.rs +++ b/crates/ruma-federation-api/src/thirdparty/bind_callback.rs @@ -12,43 +12,46 @@ pub mod v1 { use std::collections::BTreeMap; use ruma_common::{ - api::ruma_api, thirdparty::Medium, OwnedRoomId, OwnedServerName, OwnedServerSigningKeyId, - OwnedUserId, UserId, + api::{request, response, Metadata}, + metadata, + thirdparty::Medium, + OwnedRoomId, OwnedServerName, OwnedServerSigningKeyId, OwnedUserId, UserId, }; use serde::{Deserialize, Serialize}; - ruma_api! { - metadata: { - description: "Used by identity servers to notify the homeserver that one of its users has bound a third party identifier successfully", - method: PUT, - name: "bind_callback", - stable_path: "/_matrix/federation/v1/3pid/onbind", - rate_limited: false, - authentication: None, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Used by identity servers to notify the homeserver that one of its users has bound a third party identifier successfully", + method: PUT, + name: "bind_callback", + rate_limited: false, + authentication: None, + history: { + 1.0 => "/_matrix/federation/v1/3pid/onbind", } + }; - request: { - /// The type of third party identifier. - /// - /// Currently only `Medium::Email` is supported. - pub medium: &'a Medium, + #[request] + pub struct Request<'a> { + /// The type of third party identifier. + /// + /// Currently only `Medium::Email` is supported. + pub medium: &'a Medium, - /// The third party identifier itself. - /// - /// For example: an email address. - pub address: &'a str, + /// The third party identifier itself. + /// + /// For example: an email address. + pub address: &'a str, - /// The user that is now bound to the third party identifier. - pub mxid: &'a UserId, + /// The user that is now bound to the third party identifier. + pub mxid: &'a UserId, - /// A list of pending invites that the third party identifier has received. - pub invites: &'a [ThirdPartyInvite], - } - - response: {} + /// A list of pending invites that the third party identifier has received. + pub invites: &'a [ThirdPartyInvite], } + #[response] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` with the given medium, address, user ID and third party invites. pub fn new( diff --git a/crates/ruma-federation-api/src/thirdparty/exchange_invite.rs b/crates/ruma-federation-api/src/thirdparty/exchange_invite.rs index d6fd2402..b3eb7a85 100644 --- a/crates/ruma-federation-api/src/thirdparty/exchange_invite.rs +++ b/crates/ruma-federation-api/src/thirdparty/exchange_invite.rs @@ -12,47 +12,48 @@ pub mod v1 { //! [spec]: https://spec.matrix.org/v1.4/server-server-api/#put_matrixfederationv1exchange_third_party_inviteroomid use ruma_common::{ - api::ruma_api, + api::{request, response, Metadata}, events::{room::member::ThirdPartyInvite, StateEventType}, - RoomId, UserId, + metadata, RoomId, UserId, }; - ruma_api! { - metadata: { - description: "The receiving server will verify the partial m.room.member event given in the request body.", - method: PUT, - name: "exchange_invite", - stable_path: "/_matrix/federation/v1/exchange_third_party_invite/:room_id", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "The receiving server will verify the partial m.room.member event given in the request body.", + method: PUT, + name: "exchange_invite", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/federation/v1/exchange_third_party_invite/:room_id", } + }; - request: { - /// The room ID to exchange a third party invite in. - #[ruma_api(path)] - pub room_id: &'a RoomId, + #[request] + pub struct Request<'a> { + /// The room ID to exchange a third party invite in. + #[ruma_api(path)] + pub room_id: &'a RoomId, - /// The event type. - /// - /// Must be `StateEventType::RoomMember`. - #[serde(rename = "type")] - pub kind: StateEventType, + /// The event type. + /// + /// Must be `StateEventType::RoomMember`. + #[serde(rename = "type")] + pub kind: StateEventType, - /// The user ID of the user who sent the original invite event. - pub sender: &'a UserId, + /// The user ID of the user who sent the original invite event. + pub sender: &'a UserId, - /// The user ID of the invited user. - pub state_key: &'a UserId, + /// The user ID of the invited user. + pub state_key: &'a UserId, - /// The content of the invite event. - pub content: &'a ThirdPartyInvite, - } - - #[derive(Default)] - response: {} + /// The content of the invite event. + pub content: &'a ThirdPartyInvite, } + #[response] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a new `Request` for a third party invite exchange pub fn new( diff --git a/crates/ruma-federation-api/src/transactions/send_transaction_message.rs b/crates/ruma-federation-api/src/transactions/send_transaction_message.rs index 02666872..b662ca96 100644 --- a/crates/ruma-federation-api/src/transactions/send_transaction_message.rs +++ b/crates/ruma-federation-api/src/transactions/send_transaction_message.rs @@ -10,62 +10,68 @@ pub mod v1 { use std::collections::BTreeMap; use ruma_common::{ - api::ruma_api, serde::Raw, MilliSecondsSinceUnixEpoch, OwnedEventId, ServerName, - TransactionId, + api::{request, response, Metadata}, + metadata, + serde::Raw, + MilliSecondsSinceUnixEpoch, OwnedEventId, ServerName, TransactionId, }; use serde_json::value::RawValue as RawJsonValue; use crate::transactions::edu::Edu; - ruma_api! { - metadata: { - description: "Send transaction messages to another server", - name: "send_transaction_message", - method: PUT, - stable_path: "/_matrix/federation/v1/send/:transaction_id", - rate_limited: false, - authentication: ServerSignatures, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Send transaction messages to another server", + method: PUT, + name: "send_transaction_message", + rate_limited: false, + authentication: ServerSignatures, + history: { + 1.0 => "/_matrix/federation/v1/send/:transaction_id", } + }; - request: { - /// A transaction ID unique between sending and receiving homeservers. - #[ruma_api(path)] - pub transaction_id: &'a TransactionId, + #[request] + pub struct Request<'a> { + /// A transaction ID unique between sending and receiving homeservers. + #[ruma_api(path)] + pub transaction_id: &'a TransactionId, - /// The server_name of the homeserver sending this transaction. - pub origin: &'a ServerName, + /// The server_name of the homeserver sending this transaction. + pub origin: &'a ServerName, - /// POSIX timestamp in milliseconds on the originating homeserver when this transaction - /// started. - pub origin_server_ts: MilliSecondsSinceUnixEpoch, + /// POSIX timestamp in milliseconds on the originating homeserver when this transaction + /// started. + pub origin_server_ts: MilliSecondsSinceUnixEpoch, - /// List of persistent updates to rooms. - /// - /// Must not be more than 50 items. - /// - /// With the `unstable-unspecified` feature, sending `pdus` is optional. - /// See [matrix-spec#705](https://github.com/matrix-org/matrix-spec/issues/705). - #[cfg_attr(feature = "unstable-unspecified", serde(default, skip_serializing_if = "<[_]>::is_empty"))] - pub pdus: &'a [Box], + /// List of persistent updates to rooms. + /// + /// Must not be more than 50 items. + /// + /// With the `unstable-unspecified` feature, sending `pdus` is optional. + /// See [matrix-spec#705](https://github.com/matrix-org/matrix-spec/issues/705). + #[cfg_attr( + feature = "unstable-unspecified", + serde(default, skip_serializing_if = "<[_]>::is_empty") + )] + pub pdus: &'a [Box], - /// List of ephemeral messages. - /// - /// Must not be more than 100 items. - #[serde(default, skip_serializing_if = "<[_]>::is_empty")] - pub edus: &'a [Raw], - } + /// List of ephemeral messages. + /// + /// Must not be more than 100 items. + #[serde(default, skip_serializing_if = "<[_]>::is_empty")] + pub edus: &'a [Raw], + } - #[derive(Default)] - response: { - /// Map of event IDs and response for each PDU given in the request. - /// - /// With the `unstable-msc3618` feature, returning `pdus` is optional. - /// See [MSC3618](https://github.com/matrix-org/matrix-spec-proposals/pull/3618). - #[cfg_attr(feature = "unstable-msc3618", serde(default))] - #[serde(with = "crate::serde::pdu_process_response")] - pub pdus: BTreeMap>, - } + #[response] + #[derive(Default)] + pub struct Response { + /// Map of event IDs and response for each PDU given in the request. + /// + /// With the `unstable-msc3618` feature, returning `pdus` is optional. + /// See [MSC3618](https://github.com/matrix-org/matrix-spec-proposals/pull/3618). + #[cfg_attr(feature = "unstable-msc3618", serde(default))] + #[serde(with = "crate::serde::pdu_process_response")] + pub pdus: BTreeMap>, } impl<'a> Request<'a> { diff --git a/crates/ruma-identity-service-api/src/association/bind_3pid.rs b/crates/ruma-identity-service-api/src/association/bind_3pid.rs index ac55d20b..3456392d 100644 --- a/crates/ruma-identity-service-api/src/association/bind_3pid.rs +++ b/crates/ruma-identity-service-api/src/association/bind_3pid.rs @@ -8,55 +8,58 @@ pub mod v2 { //! [spec]: https://spec.matrix.org/v1.4/identity-service-api/#post_matrixidentityv23pidbind use ruma_common::{ - api::ruma_api, thirdparty::Medium, ClientSecret, MilliSecondsSinceUnixEpoch, OwnedUserId, - ServerSignatures, SessionId, UserId, + api::{request, response, Metadata}, + metadata, + thirdparty::Medium, + ClientSecret, MilliSecondsSinceUnixEpoch, OwnedUserId, ServerSignatures, SessionId, UserId, }; - ruma_api! { - metadata: { - description: "Publish an association between a session and a Matrix user ID.", - method: POST, - name: "bind_3pid", - stable_path: "/_matrix/identity/v2/3pid/bind", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Publish an association between a session and a Matrix user ID.", + method: POST, + name: "bind_3pid", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/identity/v2/3pid/bind", } + }; - request: { - /// The session ID generated by the `requestToken` call. - pub sid: &'a SessionId, + #[request] + pub struct Request<'a> { + /// The session ID generated by the `requestToken` call. + pub sid: &'a SessionId, - /// The client secret passed to the `requestToken` call. - pub client_secret: &'a ClientSecret, + /// The client secret passed to the `requestToken` call. + pub client_secret: &'a ClientSecret, - /// The Matrix user ID to associate with the 3PIDs. - pub mxid: &'a UserId, - } + /// The Matrix user ID to associate with the 3PIDs. + pub mxid: &'a UserId, + } - response: { - /// The 3PID address of the user being looked up. - pub address: String, + #[response] + pub struct Response { + /// The 3PID address of the user being looked up. + pub address: String, - /// The medium type of the 3PID. - pub medium: Medium, + /// The medium type of the 3PID. + pub medium: Medium, - /// The Matrix user ID associated with the 3PID. - pub mxid: OwnedUserId, + /// The Matrix user ID associated with the 3PID. + pub mxid: OwnedUserId, - /// A UNIX timestamp before which the association is not known to be valid. - pub not_before: MilliSecondsSinceUnixEpoch, + /// A UNIX timestamp before which the association is not known to be valid. + pub not_before: MilliSecondsSinceUnixEpoch, - /// A UNIX timestamp after which the association is not known to be valid. - pub not_after: MilliSecondsSinceUnixEpoch, + /// A UNIX timestamp after which the association is not known to be valid. + pub not_after: MilliSecondsSinceUnixEpoch, - /// The UNIX timestamp at which the association was verified. - pub ts: MilliSecondsSinceUnixEpoch, + /// The UNIX timestamp at which the association was verified. + pub ts: MilliSecondsSinceUnixEpoch, - /// The signatures of the verifiying identity servers which show that the - /// association should be trusted, if you trust the verifying identity services. - pub signatures: ServerSignatures, - } + /// The signatures of the verifiying identity servers which show that the + /// association should be trusted, if you trust the verifying identity services. + pub signatures: ServerSignatures, } impl<'a> Request<'a> { diff --git a/crates/ruma-identity-service-api/src/association/check_3pid_validity.rs b/crates/ruma-identity-service-api/src/association/check_3pid_validity.rs index 1268132b..6af1164c 100644 --- a/crates/ruma-identity-service-api/src/association/check_3pid_validity.rs +++ b/crates/ruma-identity-service-api/src/association/check_3pid_validity.rs @@ -8,39 +8,45 @@ pub mod v2 { //! [spec]: https://spec.matrix.org/v1.4/identity-service-api/#get_matrixidentityv23pidgetvalidated3pid use js_int::UInt; - use ruma_common::{api::ruma_api, thirdparty::Medium, ClientSecret, SessionId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + thirdparty::Medium, + ClientSecret, SessionId, + }; - ruma_api! { - metadata: { - description: "Determines if a given 3PID has been validated by a user.", - method: GET, - name: "check_3pid_validity", - stable_path: "/_matrix/identity/v2/3pid/getValidated3pid/", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Determines if a given 3PID has been validated by a user.", + method: GET, + name: "check_3pid_validity", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/identity/v2/3pid/getValidated3pid/", } + }; - request: { - /// The Session ID generated by the `requestToken` call. - #[ruma_api(query)] - pub sid: &'a SessionId, + #[request] + pub struct Request<'a> { + /// The Session ID generated by the `requestToken` call. + #[ruma_api(query)] + pub sid: &'a SessionId, - /// The client secret passed to the `requestToken` call. - #[ruma_api(query)] - pub client_secret: &'a ClientSecret, - } + /// The client secret passed to the `requestToken` call. + #[ruma_api(query)] + pub client_secret: &'a ClientSecret, + } - response: { - /// The medium type of the 3PID. - pub medium: Medium, + #[response] + pub struct Response { + /// The medium type of the 3PID. + pub medium: Medium, - /// The address of the 3PID being looked up. - pub address: String, + /// The address of the 3PID being looked up. + pub address: String, - /// Timestamp, in milliseconds, indicating the time that the 3PID was validated. - pub validated_at: UInt, - } + /// Timestamp, in milliseconds, indicating the time that the 3PID was validated. + pub validated_at: UInt, } impl<'a> Request<'a> { diff --git a/crates/ruma-identity-service-api/src/association/email/create_email_validation_session.rs b/crates/ruma-identity-service-api/src/association/email/create_email_validation_session.rs index feeb6969..70e9d302 100644 --- a/crates/ruma-identity-service-api/src/association/email/create_email_validation_session.rs +++ b/crates/ruma-identity-service-api/src/association/email/create_email_validation_session.rs @@ -8,42 +8,46 @@ pub mod v2 { //! [spec]: https://spec.matrix.org/v1.4/identity-service-api/#post_matrixidentityv2validateemailrequesttoken use js_int::UInt; - use ruma_common::{api::ruma_api, ClientSecret, OwnedSessionId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, ClientSecret, OwnedSessionId, + }; - ruma_api! { - metadata: { - description: "Creates a session for validating an email address.", - method: POST, - name: "create_email_validation_session", - stable_path: "/_matrix/identity/v2/validate/email/requestToken", - authentication: AccessToken, - rate_limited: false, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Creates a session for validating an email address.", + method: POST, + name: "create_email_validation_session", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/identity/v2/validate/email/requestToken", } + }; - request: { - /// A unique string generated by the client, and used to identify the validation attempt. - pub client_secret: &'a ClientSecret, + #[request] + pub struct Request<'a> { + /// A unique string generated by the client, and used to identify the validation attempt. + pub client_secret: &'a ClientSecret, - /// The email address to validate. - pub email: &'a str, + /// The email address to validate. + pub email: &'a str, - /// The server will only send an email if the send_attempt is a number greater than the - /// most recent one which it has seen, scoped to that email + client_secret pair. - pub send_attempt: UInt, + /// The server will only send an email if the send_attempt is a number greater than the + /// most recent one which it has seen, scoped to that email + client_secret pair. + pub send_attempt: UInt, - /// When the validation is completed, the identity server will redirect the user to this - /// URL. - #[serde(skip_serializing_if = "Option::is_none")] - pub next_link: Option<&'a str>, - } + /// When the validation is completed, the identity server will redirect the user to this + /// URL. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_link: Option<&'a str>, + } - response: { - /// The session ID. - /// - /// Session IDs are opaque strings generated by the identity server. - pub sid: OwnedSessionId, - } + #[response] + pub struct Response { + /// The session ID. + /// + /// Session IDs are opaque strings generated by the identity server. + pub sid: OwnedSessionId, } impl<'a> Request<'a> { diff --git a/crates/ruma-identity-service-api/src/association/email/validate_email.rs b/crates/ruma-identity-service-api/src/association/email/validate_email.rs index b93d4ad2..08cb6ab3 100644 --- a/crates/ruma-identity-service-api/src/association/email/validate_email.rs +++ b/crates/ruma-identity-service-api/src/association/email/validate_email.rs @@ -7,34 +7,38 @@ pub mod v2 { //! //! [spec]: https://spec.matrix.org/v1.4/identity-service-api/#post_matrixidentityv2validateemailsubmittoken - use ruma_common::{api::ruma_api, ClientSecret, SessionId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, ClientSecret, SessionId, + }; - ruma_api! { - metadata: { - description: "Validate ownership of an email address.", - method: POST, - name: "validate_email", - stable_path: "/_matrix/identity/v2/validate/email/submitToken", - authentication: AccessToken, - rate_limited: false, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Validate ownership of an email address.", + method: POST, + name: "validate_email", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/identity/v2/validate/email/submitToken", } + }; - request: { - /// The session ID, generated by the `requestToken` call. - pub sid: &'a SessionId, + #[request] + pub struct Request<'a> { + /// The session ID, generated by the `requestToken` call. + pub sid: &'a SessionId, - /// The client secret that was supplied to the `requestToken` call. - pub client_secret: &'a ClientSecret, + /// The client secret that was supplied to the `requestToken` call. + pub client_secret: &'a ClientSecret, - /// The token generated by the `requestToken` call and emailed to the user. - pub token: &'a str, - } + /// The token generated by the `requestToken` call and emailed to the user. + pub token: &'a str, + } - response: { - /// Whether the validation was successful or not. - pub success: bool, - } + #[response] + pub struct Response { + /// Whether the validation was successful or not. + pub success: bool, } impl<'a> Request<'a> { diff --git a/crates/ruma-identity-service-api/src/association/email/validate_email_by_end_user.rs b/crates/ruma-identity-service-api/src/association/email/validate_email_by_end_user.rs index ab4aec29..311defd9 100644 --- a/crates/ruma-identity-service-api/src/association/email/validate_email_by_end_user.rs +++ b/crates/ruma-identity-service-api/src/association/email/validate_email_by_end_user.rs @@ -7,37 +7,41 @@ pub mod v2 { //! //! [spec]: https://spec.matrix.org/v1.4/identity-service-api/#get_matrixidentityv2validateemailsubmittoken - use ruma_common::{api::ruma_api, ClientSecret, SessionId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, ClientSecret, SessionId, + }; - ruma_api! { - metadata: { - description: "Validate ownership of an email address.", - method: GET, - name: "validate_email_by_end_user", - stable_path: "/_matrix/identity/v2/validate/email/submitToken", - authentication: AccessToken, - rate_limited: false, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Validate ownership of an email address.", + method: GET, + name: "validate_email_by_end_user", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/identity/v2/validate/email/submitToken", } + }; - request: { - /// The session ID, generated by the `requestToken` call. - #[ruma_api(query)] - pub sid: &'a SessionId, + #[request] + pub struct Request<'a> { + /// The session ID, generated by the `requestToken` call. + #[ruma_api(query)] + pub sid: &'a SessionId, - /// The client secret that was supplied to the `requestToken` call. - #[ruma_api(query)] - pub client_secret: &'a ClientSecret, + /// The client secret that was supplied to the `requestToken` call. + #[ruma_api(query)] + pub client_secret: &'a ClientSecret, - /// The token generated by the `requestToken` call and emailed to the user. - #[ruma_api(query)] - pub token: &'a str, - } - - #[derive(Default)] - response: {} + /// The token generated by the `requestToken` call and emailed to the user. + #[ruma_api(query)] + pub token: &'a str, } + #[response] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Create a new `Request` with the given session ID, client secret and token. pub fn new(sid: &'a SessionId, client_secret: &'a ClientSecret, token: &'a str) -> Self { diff --git a/crates/ruma-identity-service-api/src/association/msisdn/create_msisdn_validation_session.rs b/crates/ruma-identity-service-api/src/association/msisdn/create_msisdn_validation_session.rs index 69d48e77..ff9e9bba 100644 --- a/crates/ruma-identity-service-api/src/association/msisdn/create_msisdn_validation_session.rs +++ b/crates/ruma-identity-service-api/src/association/msisdn/create_msisdn_validation_session.rs @@ -8,47 +8,51 @@ pub mod v2 { //! [spec]: https://spec.matrix.org/v1.4/identity-service-api/#post_matrixidentityv2validatemsisdnrequesttoken use js_int::UInt; - use ruma_common::{api::ruma_api, ClientSecret, OwnedSessionId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, ClientSecret, OwnedSessionId, + }; - ruma_api! { - metadata: { - description: "Creates a session for validating a phone number.", - method: POST, - name: "create_msisdn_validation_session", - stable_path: "/_matrix/identity/v2/validate/msisdn/requestToken", - authentication: AccessToken, - rate_limited: false, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Creates a session for validating a phone number.", + method: POST, + name: "create_msisdn_validation_session", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/identity/v2/validate/msisdn/requestToken", } + }; - request: { - /// A unique string generated by the client, and used to identify the validation attempt. - pub client_secret: &'a ClientSecret, + #[request] + pub struct Request<'a> { + /// A unique string generated by the client, and used to identify the validation attempt. + pub client_secret: &'a ClientSecret, - /// The two-letter uppercase ISO-3166-1 alpha-2 country code that the number in - /// `phone_number` should be parsed as if it were dialled from. - pub country: &'a str, + /// The two-letter uppercase ISO-3166-1 alpha-2 country code that the number in + /// `phone_number` should be parsed as if it were dialled from. + pub country: &'a str, - /// The phone number to validate. - pub phone_number: &'a str, + /// The phone number to validate. + pub phone_number: &'a str, - /// The server will only send an SMS if the send_attempt is a number greater than the most - /// recent one which it has seen, scoped to that `country` + `phone_number` + - /// `client_secret` triple. - pub send_attempt: UInt, + /// The server will only send an SMS if the send_attempt is a number greater than the most + /// recent one which it has seen, scoped to that `country` + `phone_number` + + /// `client_secret` triple. + pub send_attempt: UInt, - /// When the validation is completed, the identity server will redirect the user to this - /// URL. - #[serde(skip_serializing_if = "Option::is_none")] - pub next_link: Option<&'a str>, - } + /// When the validation is completed, the identity server will redirect the user to this + /// URL. + #[serde(skip_serializing_if = "Option::is_none")] + pub next_link: Option<&'a str>, + } - response: { - /// The session ID. - /// - /// Session IDs are opaque strings generated by the identity server. - pub sid: OwnedSessionId, - } + #[response] + pub struct Response { + /// The session ID. + /// + /// Session IDs are opaque strings generated by the identity server. + pub sid: OwnedSessionId, } impl<'a> Request<'a> { diff --git a/crates/ruma-identity-service-api/src/association/msisdn/validate_msisdn.rs b/crates/ruma-identity-service-api/src/association/msisdn/validate_msisdn.rs index 52d9d1fe..74193b0f 100644 --- a/crates/ruma-identity-service-api/src/association/msisdn/validate_msisdn.rs +++ b/crates/ruma-identity-service-api/src/association/msisdn/validate_msisdn.rs @@ -7,34 +7,38 @@ pub mod v2 { //! //! [spec]: https://spec.matrix.org/v1.4/identity-service-api/#post_matrixidentityv2validatemsisdnsubmittoken - use ruma_common::{api::ruma_api, ClientSecret, SessionId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, ClientSecret, SessionId, + }; - ruma_api! { - metadata: { - description: "Validate ownership of an phone number.", - method: POST, - name: "validate_msisdn", - stable_path: "/_matrix/identity/v2/validate/msisdn/submitToken", - authentication: AccessToken, - rate_limited: false, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Validate ownership of an phone number.", + method: POST, + name: "validate_msisdn", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/identity/v2/validate/msisdn/submitToken", } + }; - request: { - /// The session ID, generated by the `requestToken` call. - pub sid: &'a SessionId, + #[request] + pub struct Request<'a> { + /// The session ID, generated by the `requestToken` call. + pub sid: &'a SessionId, - /// The client secret that was supplied to the `requestToken` call. - pub client_secret: &'a ClientSecret, + /// The client secret that was supplied to the `requestToken` call. + pub client_secret: &'a ClientSecret, - /// The token generated by the `requestToken` call and sent to the user. - pub token: &'a str, - } + /// The token generated by the `requestToken` call and sent to the user. + pub token: &'a str, + } - response: { - /// Whether the validation was successful or not. - pub success: bool, - } + #[response] + pub struct Response { + /// Whether the validation was successful or not. + pub success: bool, } impl<'a> Request<'a> { diff --git a/crates/ruma-identity-service-api/src/association/msisdn/validate_msisdn_by_phone_number.rs b/crates/ruma-identity-service-api/src/association/msisdn/validate_msisdn_by_phone_number.rs index 464494e6..68b8a577 100644 --- a/crates/ruma-identity-service-api/src/association/msisdn/validate_msisdn_by_phone_number.rs +++ b/crates/ruma-identity-service-api/src/association/msisdn/validate_msisdn_by_phone_number.rs @@ -7,37 +7,41 @@ pub mod v2 { //! //! [spec]: https://spec.matrix.org/v1.4/identity-service-api/#get_matrixidentityv2validatemsisdnsubmittoken - use ruma_common::{api::ruma_api, ClientSecret, SessionId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, ClientSecret, SessionId, + }; - ruma_api! { - metadata: { - description: "Validate ownership of an email address.", - method: GET, - name: "validate_email_by_end_user", - stable_path: "/_matrix/identity/v2/validate/msisdn/submitToken", - authentication: AccessToken, - rate_limited: false, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Validate ownership of an email address.", + method: GET, + name: "validate_email_by_end_user", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/identity/v2/validate/msisdn/submitToken", } + }; - request: { - /// The session ID, generated by the `requestToken` call. - #[ruma_api(query)] - pub sid: &'a SessionId, + #[request] + pub struct Request<'a> { + /// The session ID, generated by the `requestToken` call. + #[ruma_api(query)] + pub sid: &'a SessionId, - /// The client secret that was supplied to the `requestToken` call. - #[ruma_api(query)] - pub client_secret: &'a ClientSecret, + /// The client secret that was supplied to the `requestToken` call. + #[ruma_api(query)] + pub client_secret: &'a ClientSecret, - /// The token generated by the `requestToken` call and sent to the user. - #[ruma_api(query)] - pub token: &'a str, - } - - #[derive(Default)] - response: {} + /// The token generated by the `requestToken` call and sent to the user. + #[ruma_api(query)] + pub token: &'a str, } + #[response] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Create a new `Request` with the given session ID, client secret and token. pub fn new(sid: &'a SessionId, client_secret: &'a ClientSecret, token: &'a str) -> Self { diff --git a/crates/ruma-identity-service-api/src/association/unbind_3pid.rs b/crates/ruma-identity-service-api/src/association/unbind_3pid.rs index 013ab622..a07deaca 100644 --- a/crates/ruma-identity-service-api/src/association/unbind_3pid.rs +++ b/crates/ruma-identity-service-api/src/association/unbind_3pid.rs @@ -8,43 +8,48 @@ pub mod v2 { //! [spec]: https://spec.matrix.org/v1.4/identity-service-api/#post_matrixidentityv23pidunbind use ruma_common::{ - api::ruma_api, thirdparty::Medium, user_id::UserId, ClientSecret, OwnedSessionId, + api::{request, response, Metadata}, + metadata, + thirdparty::Medium, + user_id::UserId, + ClientSecret, OwnedSessionId, }; use serde::{Deserialize, Serialize}; - ruma_api! { - metadata: { - description: "Remove an association between a session and a Matrix user ID.", - method: POST, - name: "unbind_3pid", - stable_path: "/_matrix/identity/v2/3pid/unbind", - rate_limited: false, - authentication: AccessToken, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Remove an association between a session and a Matrix user ID.", + method: POST, + name: "unbind_3pid", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/identity/v2/3pid/unbind", } + }; - request: { - /// The proof that the client owns the 3PID. - /// - /// If this is not provided, the request must be signed by the homeserver which controls - /// the `mxid`. - #[serde(flatten, skip_serializing_if = "Option::is_none")] - pub threepid_ownership_proof: Option<&'a ThreePidOwnershipProof>, + #[request] + pub struct Request<'a> { + /// The proof that the client owns the 3PID. + /// + /// If this is not provided, the request must be signed by the homeserver which controls + /// the `mxid`. + #[serde(flatten, skip_serializing_if = "Option::is_none")] + pub threepid_ownership_proof: Option<&'a ThreePidOwnershipProof>, - /// The Matrix user ID to remove from the 3PIDs. - pub mxid: &'a UserId, + /// The Matrix user ID to remove from the 3PIDs. + pub mxid: &'a UserId, - /// The 3PID to remove. - /// - /// Must match the 3PID used to generate the session if using `sid` and `client_secret` to - /// authenticate this request. - pub threepid: &'a ThirdPartyId, - } - - #[derive(Default)] - response: {} + /// The 3PID to remove. + /// + /// Must match the 3PID used to generate the session if using `sid` and `client_secret` to + /// authenticate this request. + pub threepid: &'a ThirdPartyId, } + #[response] + #[derive(Default)] + pub struct Response {} + impl<'a> Request<'a> { /// Creates a `Request` with the given Session ID, client secret, Matrix user ID and 3PID. pub fn new( diff --git a/crates/ruma-identity-service-api/src/authentication/get_account_information.rs b/crates/ruma-identity-service-api/src/authentication/get_account_information.rs index cc837baa..96a8ff73 100644 --- a/crates/ruma-identity-service-api/src/authentication/get_account_information.rs +++ b/crates/ruma-identity-service-api/src/authentication/get_account_information.rs @@ -7,26 +7,30 @@ pub mod v2 { //! //! [spec]: https://spec.matrix.org/v1.4/identity-service-api/#get_matrixidentityv2account - use ruma_common::{api::ruma_api, OwnedUserId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, OwnedUserId, + }; - ruma_api! { - metadata: { - description: "Gets information about what user owns the access token used in the request.", - method: POST, - name: "get_account_information", - stable_path: "/_matrix/identity/v2/account", - authentication: AccessToken, - rate_limited: false, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Gets information about what user owns the access token used in the request.", + method: POST, + name: "get_account_information", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/identity/v2/account", } + }; - #[derive(Default)] - request: {} + #[request] + #[derive(Default)] + pub struct Request {} - response: { - /// The user ID which registered the token. - pub user_id: OwnedUserId, - } + #[response] + pub struct Response { + /// The user ID which registered the token. + pub user_id: OwnedUserId, } impl Request { diff --git a/crates/ruma-identity-service-api/src/authentication/logout.rs b/crates/ruma-identity-service-api/src/authentication/logout.rs index be2dd26e..63e3dadc 100644 --- a/crates/ruma-identity-service-api/src/authentication/logout.rs +++ b/crates/ruma-identity-service-api/src/authentication/logout.rs @@ -8,25 +8,29 @@ pub mod v2 { //! //! [spec]: https://spec.matrix.org/v1.4/identity-service-api/#post_matrixidentityv2accountlogout - use ruma_common::api::ruma_api; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + }; - ruma_api! { - metadata: { - description: "Logs out the access token, preventing it from being used to authenticate future requests to the server.", - method: POST, - name: "logout", - stable_path: "/_matrix/identity/v2/account/logout", - authentication: AccessToken, - rate_limited: false, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Logs out the access token, preventing it from being used to authenticate future requests to the server.", + method: POST, + name: "logout", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/identity/v2/account/logout", } + }; - #[derive(Default)] - request: {} + #[request] + #[derive(Default)] + pub struct Request {} - #[derive(Default)] - response: {} - } + #[response] + #[derive(Default)] + pub struct Response {} impl Request { /// Creates an empty `Request`. diff --git a/crates/ruma-identity-service-api/src/authentication/register.rs b/crates/ruma-identity-service-api/src/authentication/register.rs index 892aeb89..bfba4c89 100644 --- a/crates/ruma-identity-service-api/src/authentication/register.rs +++ b/crates/ruma-identity-service-api/src/authentication/register.rs @@ -9,44 +9,49 @@ pub mod v2 { use std::time::Duration; - use ruma_common::{api::ruma_api, authentication::TokenType, ServerName}; + use ruma_common::{ + api::{request, response, Metadata}, + authentication::TokenType, + metadata, ServerName, + }; - ruma_api! { - metadata: { - description: "Exchanges an OpenID token from the homeserver for an access token to access the identity server.", - method: POST, - name: "register_account", - stable_path: "/_matrix/identity/v2/account/register", - authentication: None, - rate_limited: false, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Exchanges an OpenID token from the homeserver for an access token to access the identity server.", + method: POST, + name: "register_account", + rate_limited: false, + authentication: None, + history: { + 1.0 => "/_matrix/identity/v2/account/register", } + }; - request: { - /// An access token the consumer may use to verify the identity of the person who generated - /// the token. - /// - /// This is given to the federation API `GET /openid/userinfo` to verify the user's - /// identity. - pub access_token: &'a str, + #[request] + pub struct Request<'a> { + /// An access token the consumer may use to verify the identity of the person who generated + /// the token. + /// + /// This is given to the federation API `GET /openid/userinfo` to verify the user's + /// identity. + pub access_token: &'a str, - /// The string `Bearer`. - pub token_type: TokenType, + /// The string `Bearer`. + pub token_type: TokenType, - /// The homeserver domain the consumer should use when attempting to verify the user's - /// identity. - pub matrix_server_name: &'a ServerName, + /// The homeserver domain the consumer should use when attempting to verify the user's + /// identity. + pub matrix_server_name: &'a ServerName, - /// The number of seconds before this token expires and a new one must be generated. - #[serde(with = "ruma_common::serde::duration::secs")] - pub expires_in: Duration, - } + /// The number of seconds before this token expires and a new one must be generated. + #[serde(with = "ruma_common::serde::duration::secs")] + pub expires_in: Duration, + } - response: { - /// An opaque string representing the token to authenticate future requests to the identity - /// server with. - pub token: String, - } + #[response] + pub struct Response { + /// An opaque string representing the token to authenticate future requests to the identity + /// server with. + pub token: String, } impl<'a> Request<'a> { diff --git a/crates/ruma-identity-service-api/src/discovery/get_server_status.rs b/crates/ruma-identity-service-api/src/discovery/get_server_status.rs index c689539c..e5e2c1e4 100644 --- a/crates/ruma-identity-service-api/src/discovery/get_server_status.rs +++ b/crates/ruma-identity-service-api/src/discovery/get_server_status.rs @@ -7,25 +7,29 @@ pub mod v2 { //! //! [spec]: https://spec.matrix.org/v1.4/identity-service-api/#get_matrixidentityv2 - use ruma_common::api::ruma_api; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + }; - ruma_api! { - metadata: { - description: "Checks that an identity server is available at this API endpoint.", - method: GET, - name: "status", - stable_path: "/_matrix/identity/v2", - authentication: None, - rate_limited: false, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Checks that an identity server is available at this API endpoint.", + method: GET, + name: "status", + rate_limited: false, + authentication: None, + history: { + 1.0 => "/_matrix/identity/v2", } + }; - #[derive(Default)] - request: {} + #[request] + #[derive(Default)] + pub struct Request {} - #[derive(Default)] - response: {} - } + #[response] + #[derive(Default)] + pub struct Response {} impl Request { /// Creates an empty `Request`. diff --git a/crates/ruma-identity-service-api/src/discovery/get_supported_versions.rs b/crates/ruma-identity-service-api/src/discovery/get_supported_versions.rs index ef5052a1..764ff274 100644 --- a/crates/ruma-identity-service-api/src/discovery/get_supported_versions.rs +++ b/crates/ruma-identity-service-api/src/discovery/get_supported_versions.rs @@ -10,26 +10,30 @@ use std::collections::BTreeMap; -use ruma_common::api::{ruma_api, MatrixVersion}; +use ruma_common::{ + api::{request, response, MatrixVersion, Metadata}, + metadata, +}; -ruma_api! { - metadata: { - description: "Get the versions of the identity service API supported by this endpoint.", - method: GET, - name: "versions", - stable_path: "/_matrix/identity/versions", - rate_limited: false, - authentication: None, - added: 1.1, +const METADATA: Metadata = metadata! { + description: "Get the versions of the identity service API supported by this endpoint.", + method: GET, + name: "versions", + rate_limited: false, + authentication: None, + history: { + 1.1 => "/_matrix/identity/versions", } +}; - #[derive(Default)] - request: {} +#[request] +#[derive(Default)] +pub struct Request {} - response: { - /// A list of Matrix client API protocol versions supported by the endpoint. - pub versions: Vec, - } +#[response] +pub struct Response { + /// A list of Matrix client API protocol versions supported by the endpoint. + pub versions: Vec, } impl Request { diff --git a/crates/ruma-identity-service-api/src/invitation/sign_invitation_ed25519.rs b/crates/ruma-identity-service-api/src/invitation/sign_invitation_ed25519.rs index d107b050..debcf6a4 100644 --- a/crates/ruma-identity-service-api/src/invitation/sign_invitation_ed25519.rs +++ b/crates/ruma-identity-service-api/src/invitation/sign_invitation_ed25519.rs @@ -7,43 +7,49 @@ pub mod v2 { //! //! [spec]: https://spec.matrix.org/v1.4/identity-service-api/#post_matrixidentityv2sign-ed25519 - use ruma_common::{api::ruma_api, serde::Base64, OwnedUserId, ServerSignatures, UserId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + serde::Base64, + OwnedUserId, ServerSignatures, UserId, + }; - ruma_api! { - metadata: { - description: "Sign invitation details.", - method: POST, - name: "sign_invitation_ed25519", - stable_path: "/_matrix/identity/v2/sign-ed25519", - authentication: AccessToken, - rate_limited: false, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Sign invitation details.", + method: POST, + name: "sign_invitation_ed25519", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/identity/v2/sign-ed25519", } + }; - request: { - /// The Matrix user ID of the user accepting the invitation. - pub mxid: &'a UserId, + #[request] + pub struct Request<'a> { + /// The Matrix user ID of the user accepting the invitation. + pub mxid: &'a UserId, - /// The token from the call to store-invite. - pub token: &'a str, + /// The token from the call to store-invite. + pub token: &'a str, - /// The private key, encoded as unpadded base64. - pub private_key: &'a Base64, - } + /// The private key, encoded as unpadded base64. + pub private_key: &'a Base64, + } - response: { - /// The Matrix user ID of the user accepting the invitation. - pub mxid: OwnedUserId, + #[response] + pub struct Response { + /// The Matrix user ID of the user accepting the invitation. + pub mxid: OwnedUserId, - /// The Matrix user ID of the user who sent the invitation. - pub sender: OwnedUserId, + /// The Matrix user ID of the user who sent the invitation. + pub sender: OwnedUserId, - /// The signature of the mxid, sender and token. - pub signatures: ServerSignatures, + /// The signature of the mxid, sender and token. + pub signatures: ServerSignatures, - /// The token for the invitation. - pub token: String, - } + /// The token for the invitation. + pub token: String, } impl<'a> Request<'a> { diff --git a/crates/ruma-identity-service-api/src/invitation/store_invitation.rs b/crates/ruma-identity-service-api/src/invitation/store_invitation.rs index 2226ce3e..4f823994 100644 --- a/crates/ruma-identity-service-api/src/invitation/store_invitation.rs +++ b/crates/ruma-identity-service-api/src/invitation/store_invitation.rs @@ -8,90 +8,95 @@ pub mod v2 { //! [spec]: https://spec.matrix.org/v1.4/identity-service-api/#post_matrixidentityv2store-invite use ruma_common::{ - api::ruma_api, room::RoomType, thirdparty::Medium, MxcUri, RoomAliasId, RoomId, UserId, + api::{request, response, Metadata}, + metadata, + room::RoomType, + thirdparty::Medium, + MxcUri, RoomAliasId, RoomId, UserId, }; use serde::{ser::SerializeSeq, Deserialize, Serialize}; - ruma_api! { - metadata: { - description: "Store pending invitations to a user's 3PID.", - method: POST, - name: "store_invitation", - stable_path: "/_matrix/identity/v2/store-invite", - authentication: AccessToken, - rate_limited: false, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Store pending invitations to a user's 3PID.", + method: POST, + name: "store_invitation", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/identity/v2/store-invite", } + }; - request: { - /// The type of the third party identifier for the invited user. - /// - /// Currently, only `Medium::Email` is supported. - pub medium: &'a Medium, + #[request] + pub struct Request<'a> { + /// The type of the third party identifier for the invited user. + /// + /// Currently, only `Medium::Email` is supported. + pub medium: &'a Medium, - /// The email address of the invited user. - pub address: &'a str, + /// The email address of the invited user. + pub address: &'a str, - /// The Matrix room ID to which the user is invited. - pub room_id: &'a RoomId, + /// The Matrix room ID to which the user is invited. + pub room_id: &'a RoomId, - /// The Matrix user ID of the inviting user. - pub sender: &'a UserId, + /// The Matrix user ID of the inviting user. + pub sender: &'a UserId, - /// The Matrix room alias for the room to which the user is invited. - /// - /// This should be retrieved from the `m.room.canonical` state event. - #[serde(skip_serializing_if = "Option::is_none")] - pub room_alias: Option<&'a RoomAliasId>, + /// The Matrix room alias for the room to which the user is invited. + /// + /// This should be retrieved from the `m.room.canonical` state event. + #[serde(skip_serializing_if = "Option::is_none")] + pub room_alias: Option<&'a RoomAliasId>, - /// The Content URI for the room to which the user is invited. - /// - /// This should be retrieved from the `m.room.avatar` state event. - #[serde(skip_serializing_if = "Option::is_none")] - pub room_avatar_url: Option<&'a MxcUri>, + /// The Content URI for the room to which the user is invited. + /// + /// This should be retrieved from the `m.room.avatar` state event. + #[serde(skip_serializing_if = "Option::is_none")] + pub room_avatar_url: Option<&'a MxcUri>, - /// The `join_rule` for the room to which the user is invited. - /// - /// This should be retrieved from the `m.room.join_rules` state event. - #[serde(skip_serializing_if = "Option::is_none")] - pub room_join_rules: Option<&'a str>, + /// The `join_rule` for the room to which the user is invited. + /// + /// This should be retrieved from the `m.room.join_rules` state event. + #[serde(skip_serializing_if = "Option::is_none")] + pub room_join_rules: Option<&'a str>, - /// The name of the room to which the user is invited. - /// - /// This should be retrieved from the `m.room.name` state event. - #[serde(skip_serializing_if = "Option::is_none")] - pub room_name: Option<&'a str>, + /// The name of the room to which the user is invited. + /// + /// This should be retrieved from the `m.room.name` state event. + #[serde(skip_serializing_if = "Option::is_none")] + pub room_name: Option<&'a str>, - /// The type of the room to which the user is invited. - /// - /// This should be retrieved from the `m.room.create` state event. - #[serde(skip_serializing_if = "Option::is_none")] - pub room_type: Option<&'a RoomType>, + /// The type of the room to which the user is invited. + /// + /// This should be retrieved from the `m.room.create` state event. + #[serde(skip_serializing_if = "Option::is_none")] + pub room_type: Option<&'a RoomType>, - /// The display name of the user ID initiating the invite. - #[serde(skip_serializing_if = "Option::is_none")] - pub sender_display_name: Option<&'a str>, + /// The display name of the user ID initiating the invite. + #[serde(skip_serializing_if = "Option::is_none")] + pub sender_display_name: Option<&'a str>, - /// The Content URI for the avater of the user ID initiating the invite. - #[serde(skip_serializing_if = "Option::is_none")] - pub sender_avatar_url: Option<&'a MxcUri>, - } + /// The Content URI for the avater of the user ID initiating the invite. + #[serde(skip_serializing_if = "Option::is_none")] + pub sender_avatar_url: Option<&'a MxcUri>, + } - response: { - /// The generated token. - /// - /// Must be a string consisting of the characters `[0-9a-zA-Z.=_-]`. Its length must not - /// exceed 255 characters and it must not be empty. - pub token: String, + #[response] + pub struct Response { + /// The generated token. + /// + /// Must be a string consisting of the characters `[0-9a-zA-Z.=_-]`. Its length must not + /// exceed 255 characters and it must not be empty. + pub token: String, - /// A list of [server's long-term public key, generated ephemeral public key]. - pub public_keys: PublicKeys, + /// A list of [server's long-term public key, generated ephemeral public key]. + pub public_keys: PublicKeys, - /// The generated (redacted) display_name. - /// - /// An example is `f...@b...`. - pub display_name: String, - } + /// The generated (redacted) display_name. + /// + /// An example is `f...@b...`. + pub display_name: String, } impl<'a> Request<'a> { diff --git a/crates/ruma-identity-service-api/src/keys/check_public_key_validity.rs b/crates/ruma-identity-service-api/src/keys/check_public_key_validity.rs index 71159f52..c16e6bb6 100644 --- a/crates/ruma-identity-service-api/src/keys/check_public_key_validity.rs +++ b/crates/ruma-identity-service-api/src/keys/check_public_key_validity.rs @@ -7,29 +7,34 @@ pub mod v2 { //! //! [spec]: https://spec.matrix.org/v1.4/identity-service-api/#get_matrixidentityv2pubkeyisvalid - use ruma_common::{api::ruma_api, serde::Base64}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + serde::Base64, + }; - ruma_api! { - metadata: { - description: "Check whether a long-term public key is valid. The response should always be the same, provided the key exists.", - method: GET, - name: "check_public_key_validity", - stable_path: "/_matrix/identity/v2/pubkey/isvalid", - authentication: None, - rate_limited: false, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Check whether a long-term public key is valid. The response should always be the same, provided the key exists.", + method: GET, + name: "check_public_key_validity", + rate_limited: false, + authentication: None, + history: { + 1.0 => "/_matrix/identity/v2/pubkey/isvalid", } + }; - request: { - /// Base64-encoded (no padding) public key to check for validity. - #[ruma_api(query)] - pub public_key: &'a Base64, - } + #[request] + pub struct Request<'a> { + /// Base64-encoded (no padding) public key to check for validity. + #[ruma_api(query)] + pub public_key: &'a Base64, + } - response: { - /// Whether the public key is recognised and is currently valid. - pub valid: bool, - } + #[response] + pub struct Response { + /// Whether the public key is recognised and is currently valid. + pub valid: bool, } impl<'a> Request<'a> { diff --git a/crates/ruma-identity-service-api/src/keys/get_public_key.rs b/crates/ruma-identity-service-api/src/keys/get_public_key.rs index bd0e15f7..0f178fc9 100644 --- a/crates/ruma-identity-service-api/src/keys/get_public_key.rs +++ b/crates/ruma-identity-service-api/src/keys/get_public_key.rs @@ -7,29 +7,35 @@ pub mod v2 { //! //! [spec]: https://spec.matrix.org/v1.4/identity-service-api/#get_matrixidentityv2pubkeykeyid - use ruma_common::{api::ruma_api, serde::Base64, ServerSigningKeyId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + serde::Base64, + ServerSigningKeyId, + }; - ruma_api! { - metadata: { - description: "Get the public key for the given key ID.", - method: GET, - name: "get_public_key", - stable_path: "/_matrix/identity/v2/pubkey/:key_id", - rate_limited: false, - authentication: None, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Get the public key for the given key ID.", + method: GET, + name: "get_public_key", + rate_limited: false, + authentication: None, + history: { + 1.0 => "/_matrix/identity/v2/pubkey/:key_id", } + }; - request: { - /// The ID of the key. - #[ruma_api(path)] - pub key_id: &'a ServerSigningKeyId, - } + #[request] + pub struct Request<'a> { + /// The ID of the key. + #[ruma_api(path)] + pub key_id: &'a ServerSigningKeyId, + } - response: { - /// Unpadded base64-encoded public key. - pub public_key: Base64, - } + #[response] + pub struct Response { + /// Unpadded base64-encoded public key. + pub public_key: Base64, } impl<'a> Request<'a> { diff --git a/crates/ruma-identity-service-api/src/keys/validate_ephemeral_key.rs b/crates/ruma-identity-service-api/src/keys/validate_ephemeral_key.rs index 3ee01012..6431ef8e 100644 --- a/crates/ruma-identity-service-api/src/keys/validate_ephemeral_key.rs +++ b/crates/ruma-identity-service-api/src/keys/validate_ephemeral_key.rs @@ -7,29 +7,34 @@ pub mod v2 { //! //! [spec]: https://spec.matrix.org/v1.4/identity-service-api/#get_matrixidentityv2pubkeyephemeralisvalid - use ruma_common::{api::ruma_api, serde::Base64}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + serde::Base64, + }; - ruma_api! { - metadata: { - description: "Check whether a short-term public key is valid.", - method: GET, - name: "validate_ephemeral_key", - stable_path: "/_matrix/identity/v2/pubkey/ephemeral/isvalid", - authentication: None, - rate_limited: false, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Check whether a short-term public key is valid.", + method: GET, + name: "validate_ephemeral_key", + rate_limited: false, + authentication: None, + history: { + 1.0 => "/_matrix/identity/v2/pubkey/ephemeral/isvalid", } + }; - request: { - /// The unpadded base64-encoded short-term public key to check. - #[ruma_api(query)] - pub public_key: &'a Base64, - } + #[request] + pub struct Request<'a> { + /// The unpadded base64-encoded short-term public key to check. + #[ruma_api(query)] + pub public_key: &'a Base64, + } - response: { - /// Whether the short-term public key is recognised and is currently valid. - pub valid: bool, - } + #[response] + pub struct Response { + /// Whether the short-term public key is recognised and is currently valid. + pub valid: bool, } impl<'a> Request<'a> { diff --git a/crates/ruma-identity-service-api/src/lib.rs b/crates/ruma-identity-service-api/src/lib.rs index 88e78b4b..b585b561 100644 --- a/crates/ruma-identity-service-api/src/lib.rs +++ b/crates/ruma-identity-service-api/src/lib.rs @@ -5,7 +5,7 @@ //! //! [identity-api]: https://spec.matrix.org/v1.4/identity-service-api/ -#![warn(missing_docs)] +// #![warn(missing_docs)] FIXME use std::fmt; diff --git a/crates/ruma-identity-service-api/src/lookup/get_hash_parameters.rs b/crates/ruma-identity-service-api/src/lookup/get_hash_parameters.rs index 7d608efe..c8405ea5 100644 --- a/crates/ruma-identity-service-api/src/lookup/get_hash_parameters.rs +++ b/crates/ruma-identity-service-api/src/lookup/get_hash_parameters.rs @@ -7,35 +7,40 @@ pub mod v2 { //! //! [spec]: https://spec.matrix.org/v1.4/identity-service-api/#get_matrixidentityv2hash_details - use ruma_common::api::ruma_api; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + }; use crate::lookup::IdentifierHashingAlgorithm; - ruma_api! { - metadata: { - description: "Gets parameters for hashing identifiers from the server. This can include any of the algorithms defined in the spec.", - method: GET, - name: "get_hash_parameters", - stable_path: "/_matrix/identity/v2/hash_details", - authentication: AccessToken, - rate_limited: false, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Gets parameters for hashing identifiers from the server. This can include any of the algorithms defined in the spec.", + method: GET, + name: "get_hash_parameters", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/identity/v2/hash_details", } + }; - #[derive(Default)] - request: {} + #[request] + #[derive(Default)] + pub struct Request {} - response: { - /// The pepper the client MUST use in hashing identifiers, and MUST supply to the /lookup endpoint when performing lookups. - /// - /// Servers SHOULD rotate this string often. - pub lookup_pepper: String, + #[response] + pub struct Response { + /// The pepper the client MUST use in hashing identifiers, and MUST supply to the /lookup + /// endpoint when performing lookups. + /// + /// Servers SHOULD rotate this string often. + pub lookup_pepper: String, - /// The algorithms the server supports. - /// - /// Must contain at least `sha256`. - pub algorithms: Vec, - } + /// The algorithms the server supports. + /// + /// Must contain at least `sha256`. + pub algorithms: Vec, } impl Request { diff --git a/crates/ruma-identity-service-api/src/lookup/lookup_3pid.rs b/crates/ruma-identity-service-api/src/lookup/lookup_3pid.rs index 75603b5a..4a9bfb97 100644 --- a/crates/ruma-identity-service-api/src/lookup/lookup_3pid.rs +++ b/crates/ruma-identity-service-api/src/lookup/lookup_3pid.rs @@ -9,44 +9,48 @@ pub mod v2 { use std::collections::BTreeMap; - use ruma_common::{api::ruma_api, OwnedUserId}; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, OwnedUserId, + }; use crate::lookup::IdentifierHashingAlgorithm; - ruma_api! { - metadata: { - description: "Looks up the set of Matrix User IDs which have bound the 3PIDs given, if bindings are available.", - method: POST, - name: "lookup_3pid", - stable_path: "/_matrix/identity/v2/lookup", - authentication: AccessToken, - rate_limited: false, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Looks up the set of Matrix User IDs which have bound the 3PIDs given, if bindings are available.", + method: POST, + name: "lookup_3pid", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/identity/v2/lookup", } + }; - request: { - /// The algorithm the client is using to encode the `addresses`. This should be one of the - /// available options from `/hash_details`. - pub algorithm: &'a IdentifierHashingAlgorithm, + #[request] + pub struct Request<'a> { + /// The algorithm the client is using to encode the `addresses`. This should be one of the + /// available options from `/hash_details`. + pub algorithm: &'a IdentifierHashingAlgorithm, - /// The pepper from `/hash_details`. This is required even when the `algorithm` does not - /// make use of it. - pub pepper: &'a str, + /// The pepper from `/hash_details`. This is required even when the `algorithm` does not + /// make use of it. + pub pepper: &'a str, - /// The addresses to look up. - /// - /// The format of the entries here depend on the `algorithm` used. Note that queries which - /// have been incorrectly hashed or formatted will lead to no matches. - pub addresses: &'a [String], - } + /// The addresses to look up. + /// + /// The format of the entries here depend on the `algorithm` used. Note that queries which + /// have been incorrectly hashed or formatted will lead to no matches. + pub addresses: &'a [String], + } - response: { - /// Any applicable mappings of `addresses` to Matrix User IDs. - /// - /// Addresses which do not have associations will not be included, which can make this - /// property be an empty object. - pub mappings: BTreeMap, - } + #[response] + pub struct Response { + /// Any applicable mappings of `addresses` to Matrix User IDs. + /// + /// Addresses which do not have associations will not be included, which can make this + /// property be an empty object. + pub mappings: BTreeMap, } impl<'a> Request<'a> { diff --git a/crates/ruma-identity-service-api/src/tos/accept_terms_of_service.rs b/crates/ruma-identity-service-api/src/tos/accept_terms_of_service.rs index 051196c8..59a0d79f 100644 --- a/crates/ruma-identity-service-api/src/tos/accept_terms_of_service.rs +++ b/crates/ruma-identity-service-api/src/tos/accept_terms_of_service.rs @@ -7,33 +7,37 @@ pub mod v2 { //! //! [spec]: https://spec.matrix.org/v1.4/identity-service-api/#post_matrixidentityv2terms - use ruma_common::api::ruma_api; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + }; - ruma_api! { - metadata: { - description: "Called by a client to indicate that the user has accepted/agreed to the included set of URLs.", - method: POST, - name: "accept_terms_of_service", - stable_path: "/_matrix/identity/v2/terms", - authentication: AccessToken, - rate_limited: false, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Called by a client to indicate that the user has accepted/agreed to the included set of URLs.", + method: POST, + name: "accept_terms_of_service", + rate_limited: false, + authentication: AccessToken, + history: { + 1.0 => "/_matrix/identity/v2/terms", } + }; - request: { - /// The URLs the user is accepting in this request. - /// - /// An example is `https://example.org/somewhere/terms-2.0-en.html`. - pub user_accepts: Vec, - } - - #[derive(Default)] - response: {} + #[request] + pub struct Request<'a> { + /// The URLs the user is accepting in this request. + /// + /// An example is `https://example.org/somewhere/terms-2.0-en.html`. + pub user_accepts: &'a [String], } - impl Request { + #[response] + #[derive(Default)] + pub struct Response {} + + impl<'a> Request<'a> { /// Creates a new `Request` with the given URLs which the user accepts. - pub fn new(user_accepts: Vec) -> Self { + pub fn new(user_accepts: &'a [String]) -> Self { Self { user_accepts } } } diff --git a/crates/ruma-identity-service-api/src/tos/get_terms_of_service.rs b/crates/ruma-identity-service-api/src/tos/get_terms_of_service.rs index de2591a5..35c9e3b5 100644 --- a/crates/ruma-identity-service-api/src/tos/get_terms_of_service.rs +++ b/crates/ruma-identity-service-api/src/tos/get_terms_of_service.rs @@ -9,29 +9,34 @@ pub mod v2 { use std::collections::BTreeMap; - use ruma_common::api::ruma_api; + use ruma_common::{ + api::{request, response, Metadata}, + metadata, + }; use serde::{Deserialize, Serialize}; - ruma_api! { - metadata: { - description: "Gets all the terms of service offered by the server.", - method: GET, - name: "get_terms_of_service", - stable_path: "/_matrix/identity/v2/terms", - authentication: None, - rate_limited: false, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Gets all the terms of service offered by the server.", + method: GET, + name: "get_terms_of_service", + rate_limited: false, + authentication: None, + history: { + 1.0 => "/_matrix/identity/v2/terms", } + }; - #[derive(Default)] - request: {} + #[request] + #[derive(Default)] + pub struct Request {} - response: { - /// The policies the server offers. - /// - /// Mapped from arbitrary ID (unused in this version of the specification) to a Policy Object. - pub policies: BTreeMap, - } + #[response] + pub struct Response { + /// The policies the server offers. + /// + /// Mapped from arbitrary ID (unused in this version of the specification) to a Policy + /// Object. + pub policies: BTreeMap, } impl Request { diff --git a/crates/ruma-push-gateway-api/src/lib.rs b/crates/ruma-push-gateway-api/src/lib.rs index 751e08a9..5ea8d8a4 100644 --- a/crates/ruma-push-gateway-api/src/lib.rs +++ b/crates/ruma-push-gateway-api/src/lib.rs @@ -5,7 +5,7 @@ //! //! [push-api]: https://spec.matrix.org/v1.4/push-gateway-api/ -#![warn(missing_docs)] +// #![warn(missing_docs)] // FIXME use std::fmt; diff --git a/crates/ruma-push-gateway-api/src/send_event_notification.rs b/crates/ruma-push-gateway-api/src/send_event_notification.rs index 6bf74374..6fbf47b8 100644 --- a/crates/ruma-push-gateway-api/src/send_event_notification.rs +++ b/crates/ruma-push-gateway-api/src/send_event_notification.rs @@ -10,8 +10,9 @@ pub mod v1 { use js_int::{uint, UInt}; use ruma_common::{ - api::ruma_api, + api::{request, response, Metadata}, events::RoomEventType, + metadata, push::{PushFormat, Tweak}, serde::{Incoming, StringEnum}, EventId, RoomAliasId, RoomId, SecondsSinceUnixEpoch, UserId, @@ -23,33 +24,34 @@ pub mod v1 { use crate::PrivOwnedStr; - ruma_api! { - metadata: { - description: "Notify a push gateway about an event or update the number of unread notifications a user has", - name: "send_event_notification", - method: POST, - stable_path: "/_matrix/push/v1/notify", - rate_limited: false, - authentication: None, - added: 1.0, + const METADATA: Metadata = metadata! { + description: "Notify a push gateway about an event or update the number of unread notifications a user has", + method: POST, + name: "send_event_notification", + rate_limited: false, + authentication: None, + history: { + 1.0 => "/_matrix/push/v1/notify", } + }; - request: { - /// Information about the push notification - pub notification: Notification<'a>, - } + #[request] + pub struct Request<'a> { + /// Information about the push notification + pub notification: Notification<'a>, + } - #[derive(Default)] - response: { - /// A list of all pushkeys given in the notification request that are not valid. - /// - /// These could have been rejected by an upstream gateway because they have expired or have - /// never been valid. Homeservers must cease sending notification requests for these - /// pushkeys and remove the associated pushers. It may not necessarily be the notification - /// in the request that failed: it could be that a previous notification to the same pushkey - /// failed. May be empty. - pub rejected: Vec, - } + #[response] + #[derive(Default)] + pub struct Response { + /// A list of all pushkeys given in the notification request that are not valid. + /// + /// These could have been rejected by an upstream gateway because they have expired or have + /// never been valid. Homeservers must cease sending notification requests for these + /// pushkeys and remove the associated pushers. It may not necessarily be the notification + /// in the request that failed: it could be that a previous notification to the same + /// pushkey failed. May be empty. + pub rejected: Vec, } impl<'a> Request<'a> {