datadog_api_client/datadogV2/model/
model_ci_app_pipelines_aggregate_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 object sent with the request to retrieve aggregation buckets of pipeline events from your organization.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct CIAppPipelinesAggregateRequest {
14    /// The list of metrics or timeseries to compute for the retrieved buckets.
15    #[serde(rename = "compute")]
16    pub compute: Option<Vec<crate::datadogV2::model::CIAppCompute>>,
17    /// The search and filter query settings.
18    #[serde(rename = "filter")]
19    pub filter: Option<crate::datadogV2::model::CIAppPipelinesQueryFilter>,
20    /// The rules for the group-by.
21    #[serde(rename = "group_by")]
22    pub group_by: Option<Vec<crate::datadogV2::model::CIAppPipelinesGroupBy>>,
23    /// Global query options that are used during the query.
24    /// Only supply timezone or time offset, not both. Otherwise, the query fails.
25    #[serde(rename = "options")]
26    pub options: Option<crate::datadogV2::model::CIAppQueryOptions>,
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 CIAppPipelinesAggregateRequest {
35    pub fn new() -> CIAppPipelinesAggregateRequest {
36        CIAppPipelinesAggregateRequest {
37            compute: None,
38            filter: None,
39            group_by: None,
40            options: None,
41            additional_properties: std::collections::BTreeMap::new(),
42            _unparsed: false,
43        }
44    }
45
46    pub fn compute(mut self, value: Vec<crate::datadogV2::model::CIAppCompute>) -> Self {
47        self.compute = Some(value);
48        self
49    }
50
51    pub fn filter(mut self, value: crate::datadogV2::model::CIAppPipelinesQueryFilter) -> Self {
52        self.filter = Some(value);
53        self
54    }
55
56    pub fn group_by(mut self, value: Vec<crate::datadogV2::model::CIAppPipelinesGroupBy>) -> Self {
57        self.group_by = Some(value);
58        self
59    }
60
61    pub fn options(mut self, value: crate::datadogV2::model::CIAppQueryOptions) -> Self {
62        self.options = 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 CIAppPipelinesAggregateRequest {
76    fn default() -> Self {
77        Self::new()
78    }
79}
80
81impl<'de> Deserialize<'de> for CIAppPipelinesAggregateRequest {
82    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
83    where
84        D: Deserializer<'de>,
85    {
86        struct CIAppPipelinesAggregateRequestVisitor;
87        impl<'a> Visitor<'a> for CIAppPipelinesAggregateRequestVisitor {
88            type Value = CIAppPipelinesAggregateRequest;
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 compute: Option<Vec<crate::datadogV2::model::CIAppCompute>> = None;
99                let mut filter: Option<crate::datadogV2::model::CIAppPipelinesQueryFilter> = None;
100                let mut group_by: Option<Vec<crate::datadogV2::model::CIAppPipelinesGroupBy>> =
101                    None;
102                let mut options: Option<crate::datadogV2::model::CIAppQueryOptions> = None;
103                let mut additional_properties: std::collections::BTreeMap<
104                    String,
105                    serde_json::Value,
106                > = std::collections::BTreeMap::new();
107                let mut _unparsed = false;
108
109                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
110                    match k.as_str() {
111                        "compute" => {
112                            if v.is_null() {
113                                continue;
114                            }
115                            compute = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
116                        }
117                        "filter" => {
118                            if v.is_null() {
119                                continue;
120                            }
121                            filter = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
122                        }
123                        "group_by" => {
124                            if v.is_null() {
125                                continue;
126                            }
127                            group_by = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
128                        }
129                        "options" => {
130                            if v.is_null() {
131                                continue;
132                            }
133                            options = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
134                        }
135                        &_ => {
136                            if let Ok(value) = serde_json::from_value(v.clone()) {
137                                additional_properties.insert(k, value);
138                            }
139                        }
140                    }
141                }
142
143                let content = CIAppPipelinesAggregateRequest {
144                    compute,
145                    filter,
146                    group_by,
147                    options,
148                    additional_properties,
149                    _unparsed,
150                };
151
152                Ok(content)
153            }
154        }
155
156        deserializer.deserialize_any(CIAppPipelinesAggregateRequestVisitor)
157    }
158}