Skip to main content

zulip_api/message/
onboarding_step.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{field_access, impl_default, impl_display};
4
5/// OnboardingStep : Dictionary containing details of a single onboarding step.
6///
7/// Modified from `openapi-generator-cli` output:
8///
9/// ```shell,no_build,no_run
10/// $ openapi-generator-cli generate -g rust -i ./zerver/openapi/zulip.yaml -o zulip-openapi --skip-validate-spec
11/// ```
12///
13/// ```text
14/// /*
15/// * Zulip REST API
16/// *
17/// * Powerful open source group chat
18/// *
19/// * The version of the OpenAPI document: 1.0.0
20/// *
21/// * Generated by: https://openapi-generator.tech
22/// */
23/// ```
24///
25/// See [zerver/openapi/zulip.yaml](https://github.com/zulip/zulip/blob/main/zerver/openapi/zulip.yaml) for the original OpenAPI configuration.
26///
27/// Configuration slightly modified to work with the Rust generator of [`openapi-generator-cli`](https://openapi-generator.tech).
28#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
29pub struct OnboardingStep {
30    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
31    onboarding_type: Option<OnboardingType>,
32    #[serde(skip_serializing_if = "Option::is_none")]
33    name: Option<String>,
34}
35
36impl OnboardingStep {
37    /// Creates a new [OnboardingStep].
38    pub const fn new() -> Self {
39        OnboardingStep {
40            onboarding_type: None,
41            name: None,
42        }
43    }
44}
45
46field_access! {
47    OnboardingStep {
48        /// The type of the onboarding step.
49        onboarding_type: option { OnboardingType },
50    }
51}
52
53field_access! {
54    OnboardingStep {
55        /// The name of the onboarding step.
56        name: option_cow_deref { str, String },
57    }
58}
59
60impl_default!(OnboardingStep);
61impl_display!(OnboardingStep);
62
63/// Represents the [OnboardingStep] type.
64///
65/// Valid value is `\"one_time_notice\"`.
66///
67/// **Changes**: Removed type `\"hotspot\"` in Zulip 9.0 (feature level 259).  New in Zulip 8.0 (feature level 233).
68#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Serialize)]
69#[serde(rename_all = "snake_case")]
70pub enum OnboardingType {
71    OneTimeNotice,
72}
73
74impl OnboardingType {
75    /// Creates a new [OnboardingType].
76    pub const fn new() -> Self {
77        Self::OneTimeNotice
78    }
79}
80
81impl_default!(OnboardingType);
82impl_display!(OnboardingType);
83
84#[cfg(test)]
85mod tests {
86    use super::*;
87
88    #[test]
89    fn test_onboarding_step() {
90        let onboarding_type = OnboardingType::new();
91        let name = "test name";
92
93        let step = OnboardingStep::new()
94            .with_onboarding_type(onboarding_type)
95            .with_name(name);
96        let step_json = step.to_string();
97
98        assert_eq!(serde_json::to_string(&step).unwrap(), step_json);
99        assert_eq!(
100            serde_json::from_str::<OnboardingStep>(&step_json).unwrap(),
101            step
102        );
103
104        assert_eq!(step.onboarding_type(), Some(onboarding_type));
105        assert_eq!(step.name(), Some(name));
106    }
107}