datadog_api_client/datadogV2/model/
model_project.rs1use serde::de::{Error, MapAccess, Visitor};
5use serde::{Deserialize, Deserializer, Serialize};
6use serde_with::skip_serializing_none;
7use std::fmt::{self, Formatter};
8
9#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct Project {
14 #[serde(rename = "attributes")]
16 pub attributes: crate::datadogV2::model::ProjectAttributes,
17 #[serde(rename = "id")]
19 pub id: String,
20 #[serde(rename = "relationships")]
22 pub relationships: Option<crate::datadogV2::model::ProjectRelationships>,
23 #[serde(rename = "type")]
25 pub type_: crate::datadogV2::model::ProjectResourceType,
26 #[serde(flatten)]
27 pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
28 #[serde(skip)]
29 #[serde(default)]
30 pub(crate) _unparsed: bool,
31}
32
33impl Project {
34 pub fn new(
35 attributes: crate::datadogV2::model::ProjectAttributes,
36 id: String,
37 type_: crate::datadogV2::model::ProjectResourceType,
38 ) -> Project {
39 Project {
40 attributes,
41 id,
42 relationships: None,
43 type_,
44 additional_properties: std::collections::BTreeMap::new(),
45 _unparsed: false,
46 }
47 }
48
49 pub fn relationships(mut self, value: crate::datadogV2::model::ProjectRelationships) -> Self {
50 self.relationships = Some(value);
51 self
52 }
53
54 pub fn additional_properties(
55 mut self,
56 value: std::collections::BTreeMap<String, serde_json::Value>,
57 ) -> Self {
58 self.additional_properties = value;
59 self
60 }
61}
62
63impl<'de> Deserialize<'de> for Project {
64 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
65 where
66 D: Deserializer<'de>,
67 {
68 struct ProjectVisitor;
69 impl<'a> Visitor<'a> for ProjectVisitor {
70 type Value = Project;
71
72 fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
73 f.write_str("a mapping")
74 }
75
76 fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
77 where
78 M: MapAccess<'a>,
79 {
80 let mut attributes: Option<crate::datadogV2::model::ProjectAttributes> = None;
81 let mut id: Option<String> = None;
82 let mut relationships: Option<crate::datadogV2::model::ProjectRelationships> = None;
83 let mut type_: Option<crate::datadogV2::model::ProjectResourceType> = None;
84 let mut additional_properties: std::collections::BTreeMap<
85 String,
86 serde_json::Value,
87 > = std::collections::BTreeMap::new();
88 let mut _unparsed = false;
89
90 while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
91 match k.as_str() {
92 "attributes" => {
93 attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
94 }
95 "id" => {
96 id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
97 }
98 "relationships" => {
99 if v.is_null() {
100 continue;
101 }
102 relationships =
103 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
104 }
105 "type" => {
106 type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
107 if let Some(ref _type_) = type_ {
108 match _type_ {
109 crate::datadogV2::model::ProjectResourceType::UnparsedObject(_type_) => {
110 _unparsed = true;
111 },
112 _ => {}
113 }
114 }
115 }
116 &_ => {
117 if let Ok(value) = serde_json::from_value(v.clone()) {
118 additional_properties.insert(k, value);
119 }
120 }
121 }
122 }
123 let attributes = attributes.ok_or_else(|| M::Error::missing_field("attributes"))?;
124 let id = id.ok_or_else(|| M::Error::missing_field("id"))?;
125 let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
126
127 let content = Project {
128 attributes,
129 id,
130 relationships,
131 type_,
132 additional_properties,
133 _unparsed,
134 };
135
136 Ok(content)
137 }
138 }
139
140 deserializer.deserialize_any(ProjectVisitor)
141 }
142}