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
use serde::{Deserialize, Serialize};
use crate::{field_access, impl_cow, impl_default, impl_display};
/// Represents data about what value the user filled in the custom profile field with that ID.
///
/// 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 ProfileData {
#[serde(skip_serializing_if = "Option::is_none")]
value: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
rendered_value: Option<String>,
}
impl ProfileData {
/// Creates a new [ProfileData].
pub const fn new() -> ProfileData {
ProfileData {
value: None,
rendered_value: None,
}
}
}
field_access! {
ProfileData {
/// User's personal value for this custom profile field.
value: option_cow_deref { str, String },
/// The `value` rendered in HTML.
///
/// Will only be present for custom profile field types that support Markdown rendering.
///
/// This user-generated HTML content should be rendered using the same CSS and client-side security protections as are used for message content.
///
/// See [Markdown message formatting](https://zulip.com/api/message-formatting) for details on Zulip's HTML format.
rendered_value: option_cow_deref { str, String },
}
}
impl_cow!(ProfileData);
impl_default!(ProfileData);
impl_display!(ProfileData);
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_profile_data() {
let value = "test value";
let rendered_value = "<p>test value</p>";
let data = ProfileData::new()
.with_value(value)
.with_rendered_value(rendered_value);
let data_json = data.to_string();
assert_eq!(serde_json::to_string(&data).unwrap(), data_json);
assert_eq!(
serde_json::from_str::<ProfileData>(&data_json).unwrap(),
data
);
assert_eq!(data.value(), Some(value));
assert_eq!(data.rendered_value(), Some(rendered_value));
}
}