datadog_api_client/datadogV2/model/
model_item_api_payload_array.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/// A collection of datastore items with pagination and schema metadata.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct ItemApiPayloadArray {
14    /// An array of datastore items with their content and metadata.
15    #[serde(rename = "data")]
16    pub data: Vec<crate::datadogV2::model::ItemApiPayloadData>,
17    /// Additional metadata about a collection of datastore items, including pagination and schema information.
18    #[serde(rename = "meta")]
19    pub meta: Option<crate::datadogV2::model::ItemApiPayloadMeta>,
20    #[serde(flatten)]
21    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
22    #[serde(skip)]
23    #[serde(default)]
24    pub(crate) _unparsed: bool,
25}
26
27impl ItemApiPayloadArray {
28    pub fn new(data: Vec<crate::datadogV2::model::ItemApiPayloadData>) -> ItemApiPayloadArray {
29        ItemApiPayloadArray {
30            data,
31            meta: None,
32            additional_properties: std::collections::BTreeMap::new(),
33            _unparsed: false,
34        }
35    }
36
37    pub fn meta(mut self, value: crate::datadogV2::model::ItemApiPayloadMeta) -> Self {
38        self.meta = Some(value);
39        self
40    }
41
42    pub fn additional_properties(
43        mut self,
44        value: std::collections::BTreeMap<String, serde_json::Value>,
45    ) -> Self {
46        self.additional_properties = value;
47        self
48    }
49}
50
51impl<'de> Deserialize<'de> for ItemApiPayloadArray {
52    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
53    where
54        D: Deserializer<'de>,
55    {
56        struct ItemApiPayloadArrayVisitor;
57        impl<'a> Visitor<'a> for ItemApiPayloadArrayVisitor {
58            type Value = ItemApiPayloadArray;
59
60            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
61                f.write_str("a mapping")
62            }
63
64            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
65            where
66                M: MapAccess<'a>,
67            {
68                let mut data: Option<Vec<crate::datadogV2::model::ItemApiPayloadData>> = None;
69                let mut meta: Option<crate::datadogV2::model::ItemApiPayloadMeta> = None;
70                let mut additional_properties: std::collections::BTreeMap<
71                    String,
72                    serde_json::Value,
73                > = std::collections::BTreeMap::new();
74                let mut _unparsed = false;
75
76                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
77                    match k.as_str() {
78                        "data" => {
79                            data = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
80                        }
81                        "meta" => {
82                            if v.is_null() {
83                                continue;
84                            }
85                            meta = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
86                        }
87                        &_ => {
88                            if let Ok(value) = serde_json::from_value(v.clone()) {
89                                additional_properties.insert(k, value);
90                            }
91                        }
92                    }
93                }
94                let data = data.ok_or_else(|| M::Error::missing_field("data"))?;
95
96                let content = ItemApiPayloadArray {
97                    data,
98                    meta,
99                    additional_properties,
100                    _unparsed,
101                };
102
103                Ok(content)
104            }
105        }
106
107        deserializer.deserialize_any(ItemApiPayloadArrayVisitor)
108    }
109}