datadog_api_client/datadogV2/model/
model_action_query_spec.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::{Deserialize, Deserializer, Serialize};
5
6/// The definition of the action query.
7#[non_exhaustive]
8#[derive(Clone, Debug, PartialEq, Serialize)]
9#[serde(untagged)]
10pub enum ActionQuerySpec {
11    String(String),
12    ActionQuerySpecObject(Box<crate::datadogV2::model::ActionQuerySpecObject>),
13    UnparsedObject(crate::datadog::UnparsedObject),
14}
15
16impl<'de> Deserialize<'de> for ActionQuerySpec {
17    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
18    where
19        D: Deserializer<'de>,
20    {
21        let value: serde_json::Value = Deserialize::deserialize(deserializer)?;
22        if let Ok(_v) = serde_json::from_value::<String>(value.clone()) {
23            return Ok(ActionQuerySpec::String(_v));
24        }
25        if let Ok(_v) = serde_json::from_value::<Box<crate::datadogV2::model::ActionQuerySpecObject>>(
26            value.clone(),
27        ) {
28            if !_v._unparsed {
29                return Ok(ActionQuerySpec::ActionQuerySpecObject(_v));
30            }
31        }
32
33        return Ok(ActionQuerySpec::UnparsedObject(
34            crate::datadog::UnparsedObject { value },
35        ));
36    }
37}