From 419031a7671567004de147f3060e4e7a110eebb2 Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Wed, 28 Dec 2016 16:16:42 +0100 Subject: [PATCH 1/6] publicRooms endpoint --- src/r0/directory.rs | 50 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/r0/directory.rs b/src/r0/directory.rs index 89428085..361cf0da 100644 --- a/src/r0/directory.rs +++ b/src/r0/directory.rs @@ -1 +1,51 @@ //! Endpoints for the public room directory. + +/// GET /_matrix/client/r0/publicRooms +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-publicrooms) +pub mod public_rooms { + use ruma_identifiers::{RoomId, RoomAliasId}; + + /// A chunk of the response, describing one room + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PublicRoomsChunk { + pub world_readable: bool, + pub topic: Option, + pub num_joined_members: u64, + pub avatar_url: Option, + pub room_id: RoomId, + pub guest_can_join: bool, + pub aliases: Vec, + pub name: Option + } + + /// This API response type + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Response { + pub start: String, + pub chunk: Vec, + pub end: String + } + + /// Details about this API endpoint. + pub struct Endpoint; + + impl ::Endpoint for Endpoint { + type BodyParams = (); + type PathParams = (); + type QueryParams = (); + type Response = Response; + + fn method() -> ::Method { + ::Method::Get + } + + fn request_path(_params: Self::PathParams) -> String { + Self::router_path() + } + + fn router_path() -> String { + "/_matrix/client/r0/publicRooms".to_string() + } + } +} From 4e7d85aa04537a7065c8e8e8b82ef97ba7fd8a03 Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Wed, 28 Dec 2016 16:34:17 +0100 Subject: [PATCH 2/6] profile endpoints --- src/r0/profile.rs | 222 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 222 insertions(+) diff --git a/src/r0/profile.rs b/src/r0/profile.rs index 29f16d1f..b5669454 100644 --- a/src/r0/profile.rs +++ b/src/r0/profile.rs @@ -1 +1,223 @@ //! Endpoints for user profiles. + +/// GET /_matrix/client/r0/profile/{userId}/displayname +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid-displayname) +pub mod get_display_name { + use ruma_identifiers::UserId; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub user_id: UserId + } + + /// This API endpoint's body parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Response { + pub displayname: Option + } + + /// Details about this API endpoint. + pub struct Endpoint; + + impl ::Endpoint for Endpoint { + type BodyParams = (); + type PathParams = PathParams; + type QueryParams = (); + type Response = Response; + + fn method() -> ::Method { + ::Method::Get + } + + fn request_path(params: Self::PathParams) -> String { + format!( + "/_matrix/client/r0/profile/{}/displayname", + params.user_id + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/profile/:user_id/displayname".to_string() + } + } +} + + +/// PUT /_matrix/client/r0/profile/{userId}/displayname +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-profile-userid-displayname) +pub mod set_display_name { + use ruma_identifiers::UserId; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub user_id: UserId + } + + /// This API endpoint's body parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct BodyParams { + pub displayname: Option + } + + /// Details about this API endpoint. + pub struct Endpoint; + + impl ::Endpoint for Endpoint { + type BodyParams = BodyParams; + type PathParams = PathParams; + type QueryParams = (); + type Response = (); + + fn method() -> ::Method { + ::Method::Put + } + + fn request_path(params: Self::PathParams) -> String { + format!( + "/_matrix/client/r0/profile/{}/displayname", + params.user_id + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/profile/:user_id/displayname".to_string() + } + } +} + +/// GET /_matrix/client/r0/profile/{userId}/avatar_url +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid-avatar-url) +pub mod get_avatar_url { + use ruma_identifiers::UserId; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub user_id: UserId + } + + /// This API endpoint's body parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Response { + pub avatar_url: Option + } + + /// Details about this API endpoint. + pub struct Endpoint; + + impl ::Endpoint for Endpoint { + type BodyParams = (); + type PathParams = PathParams; + type QueryParams = (); + type Response = Response; + + fn method() -> ::Method { + ::Method::Get + } + + fn request_path(params: Self::PathParams) -> String { + format!( + "/_matrix/client/r0/profile/{}/avatar_url", + params.user_id + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/profile/:user_id/avatar_url".to_string() + } + } +} + +/// PUT /_matrix/client/r0/profile/{userId}/avatar_url +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#put-matrix-client-r0-profile-userid-avatar-url) +pub mod set_avatar_url { + use ruma_identifiers::UserId; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub user_id: UserId + } + + /// This API endpoint's body parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct BodyParams { + pub avatar_url: Option + } + + /// Details about this API endpoint. + pub struct Endpoint; + + impl ::Endpoint for Endpoint { + type BodyParams = BodyParams; + type PathParams = PathParams; + type QueryParams = (); + type Response = (); + + fn method() -> ::Method { + ::Method::Put + } + + fn request_path(params: Self::PathParams) -> String { + format!( + "/_matrix/client/r0/profile/{}/avatar_url", + params.user_id + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/profile/:user_id/avatar_url".to_string() + } + } +} + +/// GET /_matrix/client/r0/profile/{userId} +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-profile-userid) +pub mod get_profile { + use ruma_identifiers::UserId; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub user_id: UserId + } + + /// This API endpoint's body parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Response { + pub avatar_url: Option, + pub displayname: Option + } + + /// Details about this API endpoint. + pub struct Endpoint; + + impl ::Endpoint for Endpoint { + type BodyParams = (); + type PathParams = PathParams; + type QueryParams = (); + type Response = Response; + + fn method() -> ::Method { + ::Method::Get + } + + fn request_path(params: Self::PathParams) -> String { + format!( + "/_matrix/client/r0/profile/{}", + params.user_id + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/profile/:user_id".to_string() + } + } +} From db7f614ad7a150664ce639c862ddb77916380baa Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Wed, 28 Dec 2016 17:08:22 +0100 Subject: [PATCH 3/6] filter endpoints --- src/r0/filter.rs | 143 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) diff --git a/src/r0/filter.rs b/src/r0/filter.rs index 6d52bc5c..1203a0b5 100644 --- a/src/r0/filter.rs +++ b/src/r0/filter.rs @@ -1 +1,144 @@ //! Endpoints for event filters. + +use ruma_identifiers::{RoomId, UserId}; + +/// Format to use for returned events +#[derive(Copy, Clone, Debug, Deserialize, Serialize)] +pub enum EventFormat { + /// Client format, as described in the Client API + #[serde(rename="client")] + Client, + /// Raw events from federation + #[serde(rename="federation")] + Federation +} + +/// Filters to be applied to room events +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct RoomEventFilter { + pub not_types: Option>, + pub not_rooms: Option>, + pub limit: Option, + pub rooms: Option>, + pub not_senders: Option>, + pub senders: Option>, + pub types: Option> +} + +/// Filters to be applied to room data +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct RoomFilter { + pub include_leave: Option, + pub account_data: Option, + pub timeline: Option, + pub ephemeral: Option, + pub state: Option, + pub not_rooms: Option>, + pub room: Option> +} + +/// Filter for not-room data +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Filter { + pub not_types: Option>, + pub limit: Option, + pub senders: Option>, + pub types: Option>, + pub not_senders: Option> +} + +/// A filter definition +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct FilterDefinition { + pub event_fields: Option>, + pub event_format: Option, + pub account_data: Option, + pub room: Option, + pub presence: Option +} + +/// POST /_matrix/client/r0/user/{userId}/filter +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#post-matrix-client-r0-user-userid-filter) +pub mod create_filter { + use ruma_identifiers::UserId; + use super::FilterDefinition; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub user_id: UserId + } + + /// This API Response. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Response { + pub filter_id: String + } + + impl ::Endpoint for Endpoint { + type BodyParams = FilterDefinition; + type PathParams = PathParams; + type QueryParams = (); + type Response = Response; + + fn method() -> ::Method { + ::Method::Post + } + + fn request_path(params: Self::PathParams) -> String { + format!( + "/_matrix/client/r0/user/{}/filter", + params.user_id + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/user/:user_id/filter".to_string() + } + } +} + +/// POST /_matrix/client/r0/user/{userId}/filter/{filterId} +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-user-userid-filter-filterid) +pub mod get_filter { + use ruma_identifiers::UserId; + use super::FilterDefinition; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub user_id: UserId, + pub filter_id: String + } + + impl ::Endpoint for Endpoint { + type BodyParams = (); + type PathParams = PathParams; + type QueryParams = (); + type Response = FilterDefinition; + + fn method() -> ::Method { + ::Method::Get + } + + fn request_path(params: Self::PathParams) -> String { + format!( + "/_matrix/client/r0/user/{}/filter/{}", + params.user_id, + params.filter_id + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/user/:user_id/filter/:filter_id".to_string() + } + } +} From 6e3406ea97e8863481d8dc281edb57df0fd3cfc6 Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Wed, 28 Dec 2016 17:29:54 +0100 Subject: [PATCH 4/6] events retrieveing endpoints --- src/lib.rs | 1 + src/r0/events.rs | 233 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 234 insertions(+) create mode 100644 src/r0/events.rs diff --git a/src/lib.rs b/src/lib.rs index afa7710c..177e67a7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,6 +22,7 @@ pub mod r0 { pub mod contact; pub mod context; pub mod directory; + pub mod events; pub mod filter; pub mod media; pub mod membership; diff --git a/src/r0/events.rs b/src/r0/events.rs new file mode 100644 index 00000000..955657b3 --- /dev/null +++ b/src/r0/events.rs @@ -0,0 +1,233 @@ +//! Endpoints for getting events + +/// GET /_matrix/client/r0/rooms/{roomId}/state +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-state) +pub mod get_full_state { + use ruma_identifiers::RoomId; + use ruma_events::collections::only; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub room_id: RoomId + } + + impl ::Endpoint for Endpoint { + type BodyParams = (); + type PathParams = PathParams; + type QueryParams = (); + type Response = Vec; + + fn method() -> ::Method { + ::Method::Get + } + + fn request_path(params: Self::PathParams) -> String { + format!( + "/_matrix/client/r0/rooms/{}/state", + params.room_id + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/rooms/:room_id/state".to_string() + } + } +} + +/// GET /_matrix/client/r0/rooms/{roomId}/state/{eventType} +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-state-eventtype) +pub mod get_state_for_empty_key { + use ruma_identifiers::RoomId; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub room_id: RoomId, + pub event_type: String + } + + impl ::Endpoint for Endpoint { + type BodyParams = (); + type PathParams = PathParams; + type QueryParams = (); + type Response = ::serde_json::Value; + + fn method() -> ::Method { + ::Method::Get + } + + fn request_path(params: Self::PathParams) -> String { + format!( + "/_matrix/client/r0/rooms/{}/state/{}", + params.room_id, + params.event_type + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/rooms/:room_id/state/:event_type".to_string() + } + } +} + +/// GET /_matrix/client/r0/rooms/{roomId}/state/{eventType}/{stateKey} +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-state-eventtype-state-key) +pub mod get_state_for_key { + use ruma_identifiers::RoomId; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub room_id: RoomId, + pub event_type: String, + pub state_key: String, + } + + impl ::Endpoint for Endpoint { + type BodyParams = (); + type PathParams = PathParams; + type QueryParams = (); + type Response = ::serde_json::Value; + + fn method() -> ::Method { + ::Method::Get + } + + fn request_path(params: Self::PathParams) -> String { + format!( + "/_matrix/client/r0/rooms/{}/state/{}/{}", + params.room_id, + params.event_type, + params.state_key + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/rooms/:room_id/state/:event_type/:state_key".to_string() + } + } +} + +/// GET /_matrix/client/r0/rooms/{roomId}/members +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-members) +pub mod get_members { + use ruma_identifiers::RoomId; + use ruma_events::room::member::MemberEvent; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub room_id: RoomId, + pub event_type: String + } + + /// This API endpoint's reponse. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Response { + pub chunks: Vec + } + + impl ::Endpoint for Endpoint { + type BodyParams = (); + type PathParams = PathParams; + type QueryParams = (); + type Response = Response; + + fn method() -> ::Method { + ::Method::Get + } + + fn request_path(params: Self::PathParams) -> String { + format!( + "/_matrix/client/r0/rooms/{}/members", + params.room_id, + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/rooms/:room_id/members".to_string() + } + } +} + +/// GET /_matrix/client/r0/rooms/{roomId}/messages +/// +/// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-rooms-roomid-messages) +pub mod get_messages { + use ruma_identifiers::RoomId; + use ruma_events::collections::only; + + /// Details about this API endpoint. + pub struct Endpoint; + + /// This API endpoint's path parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct PathParams { + pub room_id: RoomId, + pub event_type: String + } + + #[derive(Clone, Debug, Deserialize, Serialize)] + pub enum Direction { + #[serde(rename="b")] + Backward, + #[serde(rename="f")] + Forward + } + + /// This API endpoint's query parameters. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct QueryParams { + pub from: String, + pub to: Option, + pub dir: Direction, + pub limit: Option + } + + /// This API endpoint's reponse. + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct Response { + pub start: String, + pub chunks: Vec, + pub end: String + } + + impl ::Endpoint for Endpoint { + type BodyParams = (); + type PathParams = PathParams; + type QueryParams = QueryParams; + type Response = Response; + + fn method() -> ::Method { + ::Method::Get + } + + fn request_path(params: Self::PathParams) -> String { + format!( + "/_matrix/client/r0/rooms/{}/messages", + params.room_id, + ) + } + + fn router_path() -> String { + "/_matrix/client/r0/rooms/:room_id/messages".to_string() + } + } +} From 6da028c0fe0dedc9273aff215f2bee50c7fce0f7 Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Wed, 28 Dec 2016 17:36:25 +0100 Subject: [PATCH 5/6] fix doc error in get_filter --- src/r0/filter.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r0/filter.rs b/src/r0/filter.rs index 1203a0b5..ad1db6f1 100644 --- a/src/r0/filter.rs +++ b/src/r0/filter.rs @@ -102,7 +102,7 @@ pub mod create_filter { } } -/// POST /_matrix/client/r0/user/{userId}/filter/{filterId} +/// GET /_matrix/client/r0/user/{userId}/filter/{filterId} /// /// [Matrix spec link](http://matrix.org/docs/spec/client_server/r0.2.0.html#get-matrix-client-r0-user-userid-filter-filterid) pub mod get_filter { From 3c324d526c8cd6f4b019faa8dc7db401bcb41ffd Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Wed, 28 Dec 2016 19:38:50 +0100 Subject: [PATCH 6/6] Add serde attributes to Option and Vec, and missing #[derive]s --- src/r0/account.rs | 7 ++++- src/r0/alias.rs | 1 + src/r0/contact.rs | 2 ++ src/r0/context.rs | 2 +- src/r0/directory.rs | 3 +++ src/r0/events.rs | 2 ++ src/r0/filter.rs | 63 +++++++++++++++++++++++++++++++++++--------- src/r0/membership.rs | 4 +++ src/r0/presence.rs | 12 +++++++-- src/r0/profile.rs | 6 +++++ src/r0/redact.rs | 1 + src/r0/room.rs | 11 +++++++- src/r0/session.rs | 2 ++ src/r0/sync.rs | 5 ++++ src/r0/typing.rs | 1 + 15 files changed, 104 insertions(+), 18 deletions(-) diff --git a/src/r0/account.rs b/src/r0/account.rs index a6e3d7bb..bad73ebe 100644 --- a/src/r0/account.rs +++ b/src/r0/account.rs @@ -7,8 +7,10 @@ pub mod register { /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BodyParams { + #[serde(skip_serializing_if = "Option::is_none")] pub bind_email: Option, pub password: String, + #[serde(skip_serializing_if = "Option::is_none")] pub username: Option, } @@ -16,8 +18,9 @@ pub mod register { pub struct Endpoint; /// This API endpoint's query string parameters. - #[derive(Clone, Debug)] + #[derive(Clone, Debug, Deserialize, Serialize)] pub struct QueryParams { + #[serde(skip_serializing_if = "Option::is_none")] pub kind: Option, } @@ -67,6 +70,7 @@ pub mod request_password_change_token { pub struct BodyParams { pub client_secret: String, pub email: String, + #[serde(skip_serializing_if = "Option::is_none")] pub id_server: Option, pub send_attempt: u64, } @@ -163,6 +167,7 @@ pub mod request_register_token { pub struct BodyParams { pub client_secret: String, pub email: String, + #[serde(skip_serializing_if = "Option::is_none")] pub id_server: Option, pub send_attempt: u64, } diff --git a/src/r0/alias.rs b/src/r0/alias.rs index 12094c1f..21bc19a2 100644 --- a/src/r0/alias.rs +++ b/src/r0/alias.rs @@ -101,6 +101,7 @@ pub mod get { } /// These API endpoints' path parameters. +#[derive(Clone, Debug, Deserialize, Serialize)] pub struct PathParams { pub room_alias: RoomAliasId, } diff --git a/src/r0/contact.rs b/src/r0/contact.rs index 775a2edb..cd0d6631 100644 --- a/src/r0/contact.rs +++ b/src/r0/contact.rs @@ -7,6 +7,7 @@ pub mod add_contact { /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BodyParams { + #[serde(skip_serializing_if = "Option::is_none")] pub bind: Option, pub three_pid_creds: ThreePidCredentials, } @@ -98,6 +99,7 @@ pub mod request_contact_verification_token { pub struct BodyParams { pub client_secret: String, pub email: String, + #[serde(skip_serializing_if = "Option::is_none")] pub id_server: Option, pub send_attempt: u64, } diff --git a/src/r0/context.rs b/src/r0/context.rs index 57be070b..9bdf1da2 100644 --- a/src/r0/context.rs +++ b/src/r0/context.rs @@ -19,7 +19,7 @@ pub mod get_context { } /// This API endpoint's query string parameters. - #[derive(Clone, Debug)] + #[derive(Clone, Debug, Deserialize, Serialize)] pub struct QueryParams { pub limit: u8, } diff --git a/src/r0/directory.rs b/src/r0/directory.rs index 361cf0da..a8c3b51c 100644 --- a/src/r0/directory.rs +++ b/src/r0/directory.rs @@ -10,12 +10,15 @@ pub mod public_rooms { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct PublicRoomsChunk { pub world_readable: bool, + #[serde(skip_serializing_if = "Option::is_none")] pub topic: Option, pub num_joined_members: u64, + #[serde(skip_serializing_if = "Option::is_none")] pub avatar_url: Option, pub room_id: RoomId, pub guest_can_join: bool, pub aliases: Vec, + #[serde(skip_serializing_if = "Option::is_none")] pub name: Option } diff --git a/src/r0/events.rs b/src/r0/events.rs index 955657b3..f57a2eb5 100644 --- a/src/r0/events.rs +++ b/src/r0/events.rs @@ -196,8 +196,10 @@ pub mod get_messages { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct QueryParams { pub from: String, + #[serde(skip_serializing_if = "Option::is_none")] pub to: Option, pub dir: Direction, + #[serde(skip_serializing_if = "Option::is_none")] pub limit: Option } diff --git a/src/r0/filter.rs b/src/r0/filter.rs index ad1db6f1..6c9f883b 100644 --- a/src/r0/filter.rs +++ b/src/r0/filter.rs @@ -16,44 +16,81 @@ pub enum EventFormat { /// Filters to be applied to room events #[derive(Clone, Debug, Deserialize, Serialize)] pub struct RoomEventFilter { - pub not_types: Option>, - pub not_rooms: Option>, + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + pub not_types: Vec, + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + pub not_rooms: Vec, + #[serde(skip_serializing_if = "Option::is_none")] pub limit: Option, - pub rooms: Option>, - pub not_senders: Option>, - pub senders: Option>, - pub types: Option> + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + pub rooms: Vec, + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + pub not_senders: Vec, + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + pub senders: Vec, + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + pub types: Vec } /// Filters to be applied to room data #[derive(Clone, Debug, Deserialize, Serialize)] pub struct RoomFilter { + #[serde(skip_serializing_if = "Option::is_none")] pub include_leave: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub account_data: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub timeline: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub ephemeral: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub state: Option, - pub not_rooms: Option>, - pub room: Option> + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + pub not_rooms: Vec, + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + pub room: Vec } /// Filter for not-room data #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Filter { - pub not_types: Option>, + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + pub not_types: Vec, + #[serde(skip_serializing_if = "Option::is_none")] pub limit: Option, - pub senders: Option>, - pub types: Option>, - pub not_senders: Option> + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + pub senders: Vec, + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + pub types: Vec, + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + pub not_senders: Vec } /// A filter definition #[derive(Clone, Debug, Deserialize, Serialize)] pub struct FilterDefinition { - pub event_fields: Option>, + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + pub event_fields: Vec, + #[serde(skip_serializing_if = "Option::is_none")] pub event_format: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub account_data: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub room: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub presence: Option } diff --git a/src/r0/membership.rs b/src/r0/membership.rs index 1ce0c841..5a33ec35 100644 --- a/src/r0/membership.rs +++ b/src/r0/membership.rs @@ -69,6 +69,7 @@ pub mod join_by_room_id_or_alias { /// The request type. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BodyParams { + #[serde(skip_serializing_if = "Option::is_none")] pub third_party_signed: Option, } @@ -130,6 +131,7 @@ pub mod join_by_room_id { /// The request type. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BodyParams { + #[serde(skip_serializing_if = "Option::is_none")] pub third_party_signed: Option, } @@ -257,6 +259,7 @@ pub mod kick { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BodyParams { pub user_id: String, + #[serde(skip_serializing_if = "Option::is_none")] pub reason: Option, } @@ -345,6 +348,7 @@ pub mod ban { /// The request type. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BodyParams { + #[serde(skip_serializing_if = "Option::is_none")] pub reason: Option, pub user_id: String, } diff --git a/src/r0/presence.rs b/src/r0/presence.rs index e7bfc95d..7fc8aab0 100644 --- a/src/r0/presence.rs +++ b/src/r0/presence.rs @@ -19,6 +19,7 @@ pub mod set_presence { /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BodyParams { + #[serde(skip_serializing_if = "Option::is_none")] status_msg: Option, presence: PresenceState } @@ -65,8 +66,11 @@ pub mod get_presence { /// This API endpoint's response. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Response { + #[serde(skip_serializing_if = "Option::is_none")] pub status_msg: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub currently_active: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub last_active_ago: Option, pub presence: PresenceState } @@ -112,8 +116,12 @@ pub mod update_presence_list { /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BodyParams { - drop: Option>, - invite: Option> + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + drop: Vec, + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + invite: Vec } impl ::Endpoint for Endpoint { diff --git a/src/r0/profile.rs b/src/r0/profile.rs index b5669454..30b8370b 100644 --- a/src/r0/profile.rs +++ b/src/r0/profile.rs @@ -15,6 +15,7 @@ pub mod get_display_name { /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Response { + #[serde(skip_serializing_if = "Option::is_none")] pub displayname: Option } @@ -60,6 +61,7 @@ pub mod set_display_name { /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BodyParams { + #[serde(skip_serializing_if = "Option::is_none")] pub displayname: Option } @@ -104,6 +106,7 @@ pub mod get_avatar_url { /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Response { + #[serde(skip_serializing_if = "Option::is_none")] pub avatar_url: Option } @@ -148,6 +151,7 @@ pub mod set_avatar_url { /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BodyParams { + #[serde(skip_serializing_if = "Option::is_none")] pub avatar_url: Option } @@ -192,7 +196,9 @@ pub mod get_profile { /// This API endpoint's body parameters. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Response { + #[serde(skip_serializing_if = "Option::is_none")] pub avatar_url: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub displayname: Option } diff --git a/src/r0/redact.rs b/src/r0/redact.rs index 08e6fc94..93b19db1 100644 --- a/src/r0/redact.rs +++ b/src/r0/redact.rs @@ -20,6 +20,7 @@ pub mod send_event { /// This API endpoint's path parameters. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BodyParams { + #[serde(skip_serializing_if = "Option::is_none")] pub reason: Option } diff --git a/src/r0/room.rs b/src/r0/room.rs index 56a8b4dd..7a15f961 100644 --- a/src/r0/room.rs +++ b/src/r0/room.rs @@ -9,12 +9,20 @@ pub mod create_room { /// The request type. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BodyParams { + #[serde(skip_serializing_if = "Option::is_none")] pub creation_content: Option, - pub invite: Option>, + #[serde(skip_serializing_if = "Vec::is_empty")] + #[serde(default)] + pub invite: Vec, + #[serde(skip_serializing_if = "Option::is_none")] pub name: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub preset: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub room_alias_name: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub topic: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub visibility: Option, } @@ -22,6 +30,7 @@ pub mod create_room { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct CreationContent { #[serde(rename="m.federate")] + #[serde(skip_serializing_if = "Option::is_none")] pub federate: Option, } diff --git a/src/r0/session.rs b/src/r0/session.rs index e144123e..a06307d3 100644 --- a/src/r0/session.rs +++ b/src/r0/session.rs @@ -12,6 +12,7 @@ pub mod login { pub struct Response { pub access_token: String, pub home_server: String, + #[serde(skip_serializing_if = "Option::is_none")] pub refresh_token: Option, pub user_id: String, } @@ -80,6 +81,7 @@ pub mod refresh_access_token { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Response { pub access_token: String, + #[serde(skip_serializing_if = "Option::is_none")] pub refresh_token: Option, } diff --git a/src/r0/sync.rs b/src/r0/sync.rs index b891e22d..8f1975d5 100644 --- a/src/r0/sync.rs +++ b/src/r0/sync.rs @@ -21,10 +21,15 @@ pub mod sync { /// This API endpoint's query parameters. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct QueryParams { + #[serde(skip_serializing_if = "Option::is_none")] pub filter: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub since: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub full_state: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub set_presence: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub timeout: Option } diff --git a/src/r0/typing.rs b/src/r0/typing.rs index b4d6a19d..1aafccf4 100644 --- a/src/r0/typing.rs +++ b/src/r0/typing.rs @@ -20,6 +20,7 @@ pub mod set_typing { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct BodyParams { pub typing: bool, + #[serde(skip_serializing_if = "Option::is_none")] pub timeout: Option }