datadog_api_client/datadogV2/model/
model_spec.rs

1// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
2// This product includes software developed at Datadog (https://www.datadoghq.com/).
3// Copyright 2019-Present Datadog, Inc.
4use serde::de::{Error, MapAccess, Visitor};
5use serde::{Deserialize, Deserializer, Serialize};
6use serde_with::skip_serializing_none;
7use std::fmt::{self, Formatter};
8
9/// The spec defines what the workflow does.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct Spec {
14    /// A list of annotations used in the workflow. These are like sticky notes for your workflow!
15    #[serde(rename = "annotations")]
16    pub annotations: Option<Vec<crate::datadogV2::model::Annotation>>,
17    /// A list of connections or connection groups used in the workflow.
18    #[serde(rename = "connectionEnvs")]
19    pub connection_envs: Option<Vec<crate::datadogV2::model::ConnectionEnv>>,
20    /// Unique identifier used to trigger workflows automatically in Datadog.
21    #[serde(rename = "handle")]
22    pub handle: Option<String>,
23    /// A list of input parameters for the workflow. These can be used as dynamic runtime values in your workflow.
24    #[serde(rename = "inputSchema")]
25    pub input_schema: Option<crate::datadogV2::model::InputSchema>,
26    /// A list of output parameters for the workflow.
27    #[serde(rename = "outputSchema")]
28    pub output_schema: Option<crate::datadogV2::model::OutputSchema>,
29    /// A `Step` is a sub-component of a workflow. Each `Step` performs an action.
30    #[serde(rename = "steps")]
31    pub steps: Option<Vec<crate::datadogV2::model::Step>>,
32    /// The list of triggers that activate this workflow. At least one trigger is required, and each trigger type may appear at most once.
33    #[serde(rename = "triggers")]
34    pub triggers: Option<Vec<crate::datadogV2::model::Trigger>>,
35    #[serde(flatten)]
36    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
37    #[serde(skip)]
38    #[serde(default)]
39    pub(crate) _unparsed: bool,
40}
41
42impl Spec {
43    pub fn new() -> Spec {
44        Spec {
45            annotations: None,
46            connection_envs: None,
47            handle: None,
48            input_schema: None,
49            output_schema: None,
50            steps: None,
51            triggers: None,
52            additional_properties: std::collections::BTreeMap::new(),
53            _unparsed: false,
54        }
55    }
56
57    pub fn annotations(mut self, value: Vec<crate::datadogV2::model::Annotation>) -> Self {
58        self.annotations = Some(value);
59        self
60    }
61
62    pub fn connection_envs(mut self, value: Vec<crate::datadogV2::model::ConnectionEnv>) -> Self {
63        self.connection_envs = Some(value);
64        self
65    }
66
67    pub fn handle(mut self, value: String) -> Self {
68        self.handle = Some(value);
69        self
70    }
71
72    pub fn input_schema(mut self, value: crate::datadogV2::model::InputSchema) -> Self {
73        self.input_schema = Some(value);
74        self
75    }
76
77    pub fn output_schema(mut self, value: crate::datadogV2::model::OutputSchema) -> Self {
78        self.output_schema = Some(value);
79        self
80    }
81
82    pub fn steps(mut self, value: Vec<crate::datadogV2::model::Step>) -> Self {
83        self.steps = Some(value);
84        self
85    }
86
87    pub fn triggers(mut self, value: Vec<crate::datadogV2::model::Trigger>) -> Self {
88        self.triggers = Some(value);
89        self
90    }
91
92    pub fn additional_properties(
93        mut self,
94        value: std::collections::BTreeMap<String, serde_json::Value>,
95    ) -> Self {
96        self.additional_properties = value;
97        self
98    }
99}
100
101impl Default for Spec {
102    fn default() -> Self {
103        Self::new()
104    }
105}
106
107impl<'de> Deserialize<'de> for Spec {
108    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
109    where
110        D: Deserializer<'de>,
111    {
112        struct SpecVisitor;
113        impl<'a> Visitor<'a> for SpecVisitor {
114            type Value = Spec;
115
116            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
117                f.write_str("a mapping")
118            }
119
120            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
121            where
122                M: MapAccess<'a>,
123            {
124                let mut annotations: Option<Vec<crate::datadogV2::model::Annotation>> = None;
125                let mut connection_envs: Option<Vec<crate::datadogV2::model::ConnectionEnv>> = None;
126                let mut handle: Option<String> = None;
127                let mut input_schema: Option<crate::datadogV2::model::InputSchema> = None;
128                let mut output_schema: Option<crate::datadogV2::model::OutputSchema> = None;
129                let mut steps: Option<Vec<crate::datadogV2::model::Step>> = None;
130                let mut triggers: Option<Vec<crate::datadogV2::model::Trigger>> = None;
131                let mut additional_properties: std::collections::BTreeMap<
132                    String,
133                    serde_json::Value,
134                > = std::collections::BTreeMap::new();
135                let mut _unparsed = false;
136
137                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
138                    match k.as_str() {
139                        "annotations" => {
140                            if v.is_null() {
141                                continue;
142                            }
143                            annotations =
144                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
145                        }
146                        "connectionEnvs" => {
147                            if v.is_null() {
148                                continue;
149                            }
150                            connection_envs =
151                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
152                        }
153                        "handle" => {
154                            if v.is_null() {
155                                continue;
156                            }
157                            handle = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
158                        }
159                        "inputSchema" => {
160                            if v.is_null() {
161                                continue;
162                            }
163                            input_schema =
164                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
165                        }
166                        "outputSchema" => {
167                            if v.is_null() {
168                                continue;
169                            }
170                            output_schema =
171                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
172                        }
173                        "steps" => {
174                            if v.is_null() {
175                                continue;
176                            }
177                            steps = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
178                        }
179                        "triggers" => {
180                            if v.is_null() {
181                                continue;
182                            }
183                            triggers = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
184                        }
185                        &_ => {
186                            if let Ok(value) = serde_json::from_value(v.clone()) {
187                                additional_properties.insert(k, value);
188                            }
189                        }
190                    }
191                }
192
193                let content = Spec {
194                    annotations,
195                    connection_envs,
196                    handle,
197                    input_schema,
198                    output_schema,
199                    steps,
200                    triggers,
201                    additional_properties,
202                    _unparsed,
203                };
204
205                Ok(content)
206            }
207        }
208
209        deserializer.deserialize_any(SpecVisitor)
210    }
211}