datadog_api_client/datadogV2/model/
model_ci_app_pipeline_event.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/// Object description of a pipeline event after being processed and stored by Datadog.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct CIAppPipelineEvent {
14    /// JSON object containing all event attributes and their associated values.
15    #[serde(rename = "attributes")]
16    pub attributes: Option<crate::datadogV2::model::CIAppPipelineEventAttributes>,
17    /// Unique ID of the event.
18    #[serde(rename = "id")]
19    pub id: Option<String>,
20    /// Type of the event.
21    #[serde(rename = "type")]
22    pub type_: Option<crate::datadogV2::model::CIAppPipelineEventTypeName>,
23    #[serde(flatten)]
24    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
25    #[serde(skip)]
26    #[serde(default)]
27    pub(crate) _unparsed: bool,
28}
29
30impl CIAppPipelineEvent {
31    pub fn new() -> CIAppPipelineEvent {
32        CIAppPipelineEvent {
33            attributes: None,
34            id: None,
35            type_: None,
36            additional_properties: std::collections::BTreeMap::new(),
37            _unparsed: false,
38        }
39    }
40
41    pub fn attributes(
42        mut self,
43        value: crate::datadogV2::model::CIAppPipelineEventAttributes,
44    ) -> Self {
45        self.attributes = Some(value);
46        self
47    }
48
49    pub fn id(mut self, value: String) -> Self {
50        self.id = Some(value);
51        self
52    }
53
54    pub fn type_(mut self, value: crate::datadogV2::model::CIAppPipelineEventTypeName) -> Self {
55        self.type_ = Some(value);
56        self
57    }
58
59    pub fn additional_properties(
60        mut self,
61        value: std::collections::BTreeMap<String, serde_json::Value>,
62    ) -> Self {
63        self.additional_properties = value;
64        self
65    }
66}
67
68impl Default for CIAppPipelineEvent {
69    fn default() -> Self {
70        Self::new()
71    }
72}
73
74impl<'de> Deserialize<'de> for CIAppPipelineEvent {
75    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
76    where
77        D: Deserializer<'de>,
78    {
79        struct CIAppPipelineEventVisitor;
80        impl<'a> Visitor<'a> for CIAppPipelineEventVisitor {
81            type Value = CIAppPipelineEvent;
82
83            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
84                f.write_str("a mapping")
85            }
86
87            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
88            where
89                M: MapAccess<'a>,
90            {
91                let mut attributes: Option<crate::datadogV2::model::CIAppPipelineEventAttributes> =
92                    None;
93                let mut id: Option<String> = None;
94                let mut type_: Option<crate::datadogV2::model::CIAppPipelineEventTypeName> = None;
95                let mut additional_properties: std::collections::BTreeMap<
96                    String,
97                    serde_json::Value,
98                > = std::collections::BTreeMap::new();
99                let mut _unparsed = false;
100
101                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
102                    match k.as_str() {
103                        "attributes" => {
104                            if v.is_null() {
105                                continue;
106                            }
107                            attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
108                        }
109                        "id" => {
110                            if v.is_null() {
111                                continue;
112                            }
113                            id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
114                        }
115                        "type" => {
116                            if v.is_null() {
117                                continue;
118                            }
119                            type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
120                            if let Some(ref _type_) = type_ {
121                                match _type_ {
122                                    crate::datadogV2::model::CIAppPipelineEventTypeName::UnparsedObject(_type_) => {
123                                        _unparsed = true;
124                                    },
125                                    _ => {}
126                                }
127                            }
128                        }
129                        &_ => {
130                            if let Ok(value) = serde_json::from_value(v.clone()) {
131                                additional_properties.insert(k, value);
132                            }
133                        }
134                    }
135                }
136
137                let content = CIAppPipelineEvent {
138                    attributes,
139                    id,
140                    type_,
141                    additional_properties,
142                    _unparsed,
143                };
144
145                Ok(content)
146            }
147        }
148
149        deserializer.deserialize_any(CIAppPipelineEventVisitor)
150    }
151}