datadog_api_client/datadogV1/model/
model_synthetics_patch_test_operation.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 single [JSON Patch](<https://jsonpatch.com>) operation to perform on the test
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct SyntheticsPatchTestOperation {
14    /// The operation to perform
15    #[serde(rename = "op")]
16    pub op: Option<crate::datadogV1::model::SyntheticsPatchTestOperationName>,
17    /// The path to the value to modify
18    #[serde(rename = "path")]
19    pub path: Option<String>,
20    /// A value to use in a [JSON Patch](<https://jsonpatch.com>) operation
21    #[serde(rename = "value")]
22    pub value: Option<serde_json::Value>,
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 SyntheticsPatchTestOperation {
31    pub fn new() -> SyntheticsPatchTestOperation {
32        SyntheticsPatchTestOperation {
33            op: None,
34            path: None,
35            value: None,
36            additional_properties: std::collections::BTreeMap::new(),
37            _unparsed: false,
38        }
39    }
40
41    pub fn op(mut self, value: crate::datadogV1::model::SyntheticsPatchTestOperationName) -> Self {
42        self.op = Some(value);
43        self
44    }
45
46    pub fn path(mut self, value: String) -> Self {
47        self.path = Some(value);
48        self
49    }
50
51    pub fn value(mut self, value: serde_json::Value) -> Self {
52        self.value = Some(value);
53        self
54    }
55
56    pub fn additional_properties(
57        mut self,
58        value: std::collections::BTreeMap<String, serde_json::Value>,
59    ) -> Self {
60        self.additional_properties = value;
61        self
62    }
63}
64
65impl Default for SyntheticsPatchTestOperation {
66    fn default() -> Self {
67        Self::new()
68    }
69}
70
71impl<'de> Deserialize<'de> for SyntheticsPatchTestOperation {
72    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
73    where
74        D: Deserializer<'de>,
75    {
76        struct SyntheticsPatchTestOperationVisitor;
77        impl<'a> Visitor<'a> for SyntheticsPatchTestOperationVisitor {
78            type Value = SyntheticsPatchTestOperation;
79
80            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
81                f.write_str("a mapping")
82            }
83
84            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
85            where
86                M: MapAccess<'a>,
87            {
88                let mut op: Option<crate::datadogV1::model::SyntheticsPatchTestOperationName> =
89                    None;
90                let mut path: Option<String> = None;
91                let mut value: Option<serde_json::Value> = None;
92                let mut additional_properties: std::collections::BTreeMap<
93                    String,
94                    serde_json::Value,
95                > = std::collections::BTreeMap::new();
96                let mut _unparsed = false;
97
98                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
99                    match k.as_str() {
100                        "op" => {
101                            if v.is_null() {
102                                continue;
103                            }
104                            op = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
105                            if let Some(ref _op) = op {
106                                match _op {
107                                    crate::datadogV1::model::SyntheticsPatchTestOperationName::UnparsedObject(_op) => {
108                                        _unparsed = true;
109                                    },
110                                    _ => {}
111                                }
112                            }
113                        }
114                        "path" => {
115                            if v.is_null() {
116                                continue;
117                            }
118                            path = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
119                        }
120                        "value" => {
121                            if v.is_null() {
122                                continue;
123                            }
124                            value = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
125                        }
126                        &_ => {
127                            if let Ok(value) = serde_json::from_value(v.clone()) {
128                                additional_properties.insert(k, value);
129                            }
130                        }
131                    }
132                }
133
134                let content = SyntheticsPatchTestOperation {
135                    op,
136                    path,
137                    value,
138                    additional_properties,
139                    _unparsed,
140                };
141
142                Ok(content)
143            }
144        }
145
146        deserializer.deserialize_any(SyntheticsPatchTestOperationVisitor)
147    }
148}