datadog_api_client/datadogV1/model/
model_notebook_cell_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::{Deserialize, Deserializer, Serialize};
5
6/// The attributes of a notebook cell in create cell request. Valid cell types are `markdown`, `timeseries`, `toplist`, `heatmap`, `distribution`,
7/// `log_stream`. [More information on each graph visualization type.](<https://docs.datadoghq.com/dashboards/widgets/>)
8#[non_exhaustive]
9#[derive(Clone, Debug, PartialEq, Serialize)]
10#[serde(untagged)]
11pub enum NotebookCellCreateRequestAttributes {
12    NotebookMarkdownCellAttributes(Box<crate::datadogV1::model::NotebookMarkdownCellAttributes>),
13    NotebookTimeseriesCellAttributes(
14        Box<crate::datadogV1::model::NotebookTimeseriesCellAttributes>,
15    ),
16    NotebookToplistCellAttributes(Box<crate::datadogV1::model::NotebookToplistCellAttributes>),
17    NotebookHeatMapCellAttributes(Box<crate::datadogV1::model::NotebookHeatMapCellAttributes>),
18    NotebookDistributionCellAttributes(
19        Box<crate::datadogV1::model::NotebookDistributionCellAttributes>,
20    ),
21    NotebookLogStreamCellAttributes(Box<crate::datadogV1::model::NotebookLogStreamCellAttributes>),
22    UnparsedObject(crate::datadog::UnparsedObject),
23}
24
25impl<'de> Deserialize<'de> for NotebookCellCreateRequestAttributes {
26    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
27    where
28        D: Deserializer<'de>,
29    {
30        let value: serde_json::Value = Deserialize::deserialize(deserializer)?;
31        if let Ok(_v) = serde_json::from_value::<
32            Box<crate::datadogV1::model::NotebookMarkdownCellAttributes>,
33        >(value.clone())
34        {
35            if !_v._unparsed {
36                return Ok(NotebookCellCreateRequestAttributes::NotebookMarkdownCellAttributes(_v));
37            }
38        }
39        if let Ok(_v) = serde_json::from_value::<
40            Box<crate::datadogV1::model::NotebookTimeseriesCellAttributes>,
41        >(value.clone())
42        {
43            if !_v._unparsed {
44                return Ok(
45                    NotebookCellCreateRequestAttributes::NotebookTimeseriesCellAttributes(_v),
46                );
47            }
48        }
49        if let Ok(_v) = serde_json::from_value::<
50            Box<crate::datadogV1::model::NotebookToplistCellAttributes>,
51        >(value.clone())
52        {
53            if !_v._unparsed {
54                return Ok(NotebookCellCreateRequestAttributes::NotebookToplistCellAttributes(_v));
55            }
56        }
57        if let Ok(_v) = serde_json::from_value::<
58            Box<crate::datadogV1::model::NotebookHeatMapCellAttributes>,
59        >(value.clone())
60        {
61            if !_v._unparsed {
62                return Ok(NotebookCellCreateRequestAttributes::NotebookHeatMapCellAttributes(_v));
63            }
64        }
65        if let Ok(_v) = serde_json::from_value::<
66            Box<crate::datadogV1::model::NotebookDistributionCellAttributes>,
67        >(value.clone())
68        {
69            if !_v._unparsed {
70                return Ok(
71                    NotebookCellCreateRequestAttributes::NotebookDistributionCellAttributes(_v),
72                );
73            }
74        }
75        if let Ok(_v) = serde_json::from_value::<
76            Box<crate::datadogV1::model::NotebookLogStreamCellAttributes>,
77        >(value.clone())
78        {
79            if !_v._unparsed {
80                return Ok(
81                    NotebookCellCreateRequestAttributes::NotebookLogStreamCellAttributes(_v),
82                );
83            }
84        }
85
86        return Ok(NotebookCellCreateRequestAttributes::UnparsedObject(
87            crate::datadog::UnparsedObject { value },
88        ));
89    }
90}