datadog_api_client/datadogV2/model/
model_ci_app_test_events_request.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 request for a tests search.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct CIAppTestEventsRequest {
14    /// The search and filter query settings.
15    #[serde(rename = "filter")]
16    pub filter: Option<crate::datadogV2::model::CIAppTestsQueryFilter>,
17    /// Global query options that are used during the query.
18    /// Only supply timezone or time offset, not both. Otherwise, the query fails.
19    #[serde(rename = "options")]
20    pub options: Option<crate::datadogV2::model::CIAppQueryOptions>,
21    /// Paging attributes for listing events.
22    #[serde(rename = "page")]
23    pub page: Option<crate::datadogV2::model::CIAppQueryPageOptions>,
24    /// Sort parameters when querying events.
25    #[serde(rename = "sort")]
26    pub sort: Option<crate::datadogV2::model::CIAppSort>,
27    #[serde(flatten)]
28    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
29    #[serde(skip)]
30    #[serde(default)]
31    pub(crate) _unparsed: bool,
32}
33
34impl CIAppTestEventsRequest {
35    pub fn new() -> CIAppTestEventsRequest {
36        CIAppTestEventsRequest {
37            filter: None,
38            options: None,
39            page: None,
40            sort: None,
41            additional_properties: std::collections::BTreeMap::new(),
42            _unparsed: false,
43        }
44    }
45
46    pub fn filter(mut self, value: crate::datadogV2::model::CIAppTestsQueryFilter) -> Self {
47        self.filter = Some(value);
48        self
49    }
50
51    pub fn options(mut self, value: crate::datadogV2::model::CIAppQueryOptions) -> Self {
52        self.options = Some(value);
53        self
54    }
55
56    pub fn page(mut self, value: crate::datadogV2::model::CIAppQueryPageOptions) -> Self {
57        self.page = Some(value);
58        self
59    }
60
61    pub fn sort(mut self, value: crate::datadogV2::model::CIAppSort) -> Self {
62        self.sort = Some(value);
63        self
64    }
65
66    pub fn additional_properties(
67        mut self,
68        value: std::collections::BTreeMap<String, serde_json::Value>,
69    ) -> Self {
70        self.additional_properties = value;
71        self
72    }
73}
74
75impl Default for CIAppTestEventsRequest {
76    fn default() -> Self {
77        Self::new()
78    }
79}
80
81impl<'de> Deserialize<'de> for CIAppTestEventsRequest {
82    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
83    where
84        D: Deserializer<'de>,
85    {
86        struct CIAppTestEventsRequestVisitor;
87        impl<'a> Visitor<'a> for CIAppTestEventsRequestVisitor {
88            type Value = CIAppTestEventsRequest;
89
90            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
91                f.write_str("a mapping")
92            }
93
94            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
95            where
96                M: MapAccess<'a>,
97            {
98                let mut filter: Option<crate::datadogV2::model::CIAppTestsQueryFilter> = None;
99                let mut options: Option<crate::datadogV2::model::CIAppQueryOptions> = None;
100                let mut page: Option<crate::datadogV2::model::CIAppQueryPageOptions> = None;
101                let mut sort: Option<crate::datadogV2::model::CIAppSort> = None;
102                let mut additional_properties: std::collections::BTreeMap<
103                    String,
104                    serde_json::Value,
105                > = std::collections::BTreeMap::new();
106                let mut _unparsed = false;
107
108                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
109                    match k.as_str() {
110                        "filter" => {
111                            if v.is_null() {
112                                continue;
113                            }
114                            filter = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
115                        }
116                        "options" => {
117                            if v.is_null() {
118                                continue;
119                            }
120                            options = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
121                        }
122                        "page" => {
123                            if v.is_null() {
124                                continue;
125                            }
126                            page = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
127                        }
128                        "sort" => {
129                            if v.is_null() {
130                                continue;
131                            }
132                            sort = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
133                            if let Some(ref _sort) = sort {
134                                match _sort {
135                                    crate::datadogV2::model::CIAppSort::UnparsedObject(_sort) => {
136                                        _unparsed = true;
137                                    }
138                                    _ => {}
139                                }
140                            }
141                        }
142                        &_ => {
143                            if let Ok(value) = serde_json::from_value(v.clone()) {
144                                additional_properties.insert(k, value);
145                            }
146                        }
147                    }
148                }
149
150                let content = CIAppTestEventsRequest {
151                    filter,
152                    options,
153                    page,
154                    sort,
155                    additional_properties,
156                    _unparsed,
157                };
158
159                Ok(content)
160            }
161        }
162
163        deserializer.deserialize_any(CIAppTestEventsRequestVisitor)
164    }
165}