1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
use serde::{Deserialize, Serialize};
use crate::{field_access, impl_cow, impl_default, impl_display};
/// Represents details of a default channel group.
///
/// Modified from `openapi-generator-cli` output:
///
/// ```shell,no_build,no_run
/// $ openapi-generator-cli generate -g rust -i ./zerver/openapi/zulip.yaml -o zulip-openapi --skip-validate-spec
/// ```
///
/// ```text
/// /*
/// * Zulip REST API
/// *
/// * Powerful open source group chat
/// *
/// * The version of the OpenAPI document: 1.0.0
/// *
/// * Generated by: https://openapi-generator.tech
/// */
/// ```
///
/// See [zerver/openapi/zulip.yaml](https://github.com/zulip/zulip/blob/main/zerver/openapi/zulip.yaml) for the original OpenAPI configuration.
///
/// Configuration slightly modified to work with the Rust generator of [`openapi-generator-cli`](https://openapi-generator.tech).
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct DefaultChannelGroup {
#[serde(skip_serializing_if = "Option::is_none")]
name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
id: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
streams: Option<Vec<u64>>,
}
impl DefaultChannelGroup {
/// Dictionary containing details of a default channel group.
pub const fn new() -> Self {
Self {
name: None,
description: None,
id: None,
streams: None,
}
}
}
field_access! {
DefaultChannelGroup {
/// Name of the default channel group.
name: option_cow_deref { str, String },
/// Description of the default channel group.
description: option_cow_deref { str, String },
/// An array of IDs of all the channels in the default stream group.
///
/// **Changes**: Before Zulip 10.0 (feature level 330), we sent array of dictionaries where each dictionary contained details about a single stream in the default stream group.
streams: option_cow_deref { [u64], Vec<u64> },
}
}
field_access! {
DefaultChannelGroup {
/// The ID of the default channel group.
id: option { u64 },
}
}
impl_cow!(DefaultChannelGroup);
impl_default!(DefaultChannelGroup);
impl_display!(DefaultChannelGroup);
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_default_channel_group() {
let name = "test name";
let description = "test description";
let id = 1;
let streams = [1u64];
let group = DefaultChannelGroup::new()
.with_name(name)
.with_description(description)
.with_id(id)
.with_streams(streams.as_ref());
let group_json = group.to_string();
assert_eq!(serde_json::to_string(&group).unwrap(), group_json);
assert_eq!(
serde_json::from_str::<DefaultChannelGroup>(&group_json).unwrap(),
group
);
assert_eq!(group.name(), Some(name));
assert_eq!(group.description(), Some(description));
assert_eq!(group.id(), Some(id));
assert_eq!(group.streams(), Some(streams.as_ref()));
}
}