datadog_api_client/datadogV2/model/
model_fastly_account_create_request_attributes.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/// Attributes object for creating a Fastly account.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct FastlyAccountCreateRequestAttributes {
14    /// The API key for the Fastly account.
15    #[serde(rename = "api_key")]
16    pub api_key: String,
17    /// The name of the Fastly account.
18    #[serde(rename = "name")]
19    pub name: String,
20    /// A list of services belonging to the parent account.
21    #[serde(rename = "services")]
22    pub services: Option<Vec<crate::datadogV2::model::FastlyService>>,
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 FastlyAccountCreateRequestAttributes {
31    pub fn new(api_key: String, name: String) -> FastlyAccountCreateRequestAttributes {
32        FastlyAccountCreateRequestAttributes {
33            api_key,
34            name,
35            services: None,
36            additional_properties: std::collections::BTreeMap::new(),
37            _unparsed: false,
38        }
39    }
40
41    pub fn services(mut self, value: Vec<crate::datadogV2::model::FastlyService>) -> Self {
42        self.services = Some(value);
43        self
44    }
45
46    pub fn additional_properties(
47        mut self,
48        value: std::collections::BTreeMap<String, serde_json::Value>,
49    ) -> Self {
50        self.additional_properties = value;
51        self
52    }
53}
54
55impl<'de> Deserialize<'de> for FastlyAccountCreateRequestAttributes {
56    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
57    where
58        D: Deserializer<'de>,
59    {
60        struct FastlyAccountCreateRequestAttributesVisitor;
61        impl<'a> Visitor<'a> for FastlyAccountCreateRequestAttributesVisitor {
62            type Value = FastlyAccountCreateRequestAttributes;
63
64            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
65                f.write_str("a mapping")
66            }
67
68            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
69            where
70                M: MapAccess<'a>,
71            {
72                let mut api_key: Option<String> = None;
73                let mut name: Option<String> = None;
74                let mut services: Option<Vec<crate::datadogV2::model::FastlyService>> = None;
75                let mut additional_properties: std::collections::BTreeMap<
76                    String,
77                    serde_json::Value,
78                > = std::collections::BTreeMap::new();
79                let mut _unparsed = false;
80
81                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
82                    match k.as_str() {
83                        "api_key" => {
84                            api_key = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
85                        }
86                        "name" => {
87                            name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
88                        }
89                        "services" => {
90                            if v.is_null() {
91                                continue;
92                            }
93                            services = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
94                        }
95                        &_ => {
96                            if let Ok(value) = serde_json::from_value(v.clone()) {
97                                additional_properties.insert(k, value);
98                            }
99                        }
100                    }
101                }
102                let api_key = api_key.ok_or_else(|| M::Error::missing_field("api_key"))?;
103                let name = name.ok_or_else(|| M::Error::missing_field("name"))?;
104
105                let content = FastlyAccountCreateRequestAttributes {
106                    api_key,
107                    name,
108                    services,
109                    additional_properties,
110                    _unparsed,
111                };
112
113                Ok(content)
114            }
115        }
116
117        deserializer.deserialize_any(FastlyAccountCreateRequestAttributesVisitor)
118    }
119}