Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .generator/schemas/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19700,11 +19700,12 @@ components:
- id
type: object
DeploymentRulesOptions:
description: Options for deployment rule response representing either faulty
deployment detection or monitor options.
oneOf:
anyOf:
- $ref: '#/components/schemas/DeploymentRuleOptionsFaultyDeploymentDetection'
- $ref: '#/components/schemas/DeploymentRuleOptionsMonitor'
description: Options for deployment rule response representing either faulty
deployment detection or monitor options. The actual type is determined by
the parent's 'type' field.
DetachCaseRequest:
description: Request for detaching security findings from their case.
properties:
Expand Down
2 changes: 1 addition & 1 deletion LICENSE-3rdparty.csv
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ num-traits,https://github.com/rust-num/num-traits,MIT OR Apache-2.0,The Rust Pro
once_cell,https://github.com/matklad/once_cell,MIT OR Apache-2.0,Aleksey Kladov <aleksey.kladov@gmail.com>
openssl,https://github.com/rust-openssl/rust-openssl,Apache-2.0,Steven Fackler <sfackler@gmail.com>
openssl-macros,https://github.com/sfackler/rust-openssl,MIT OR Apache-2.0,The openssl-macros Authors
openssl-probe,https://github.com/alexcrichton/openssl-probe,MIT OR Apache-2.0,Alex Crichton <alex@alexcrichton.com>
openssl-probe,https://github.com/rustls/openssl-probe,MIT OR Apache-2.0,Alex Crichton <alex@alexcrichton.com>
openssl-sys,https://github.com/rust-openssl/rust-openssl,MIT,"Alex Crichton <alex@alexcrichton.com>, Steven Fackler <sfackler@gmail.com>"
parking_lot,https://github.com/Amanieu/parking_lot,Apache-2.0 OR MIT,Amanieu d'Antras <amanieu@gmail.com>
parking_lot_core,https://github.com/Amanieu/parking_lot,Apache-2.0 OR MIT,Amanieu d'Antras <amanieu@gmail.com>
Expand Down
5 changes: 1 addition & 4 deletions examples/v2_deployment-gates_CreateDeploymentRule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use datadog_api_client::datadogV2::model::CreateDeploymentRuleParams;
use datadog_api_client::datadogV2::model::CreateDeploymentRuleParamsData;
use datadog_api_client::datadogV2::model::CreateDeploymentRuleParamsDataAttributes;
use datadog_api_client::datadogV2::model::DeploymentRuleDataType;
use datadog_api_client::datadogV2::model::DeploymentRuleOptionsFaultyDeploymentDetection;
use datadog_api_client::datadogV2::model::DeploymentRulesOptions;

#[tokio::main]
Expand All @@ -15,9 +14,7 @@ async fn main() {
let body = CreateDeploymentRuleParams::new().data(CreateDeploymentRuleParamsData::new(
CreateDeploymentRuleParamsDataAttributes::new(
"My deployment rule".to_string(),
DeploymentRulesOptions::DeploymentRuleOptionsFaultyDeploymentDetection(Box::new(
DeploymentRuleOptionsFaultyDeploymentDetection::new().excluded_resources(vec![]),
)),
DeploymentRulesOptions::new(),
"faulty_deployment_detection".to_string(),
)
.dry_run(false),
Expand Down
5 changes: 1 addition & 4 deletions examples/v2_deployment-gates_UpdateDeploymentRule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_deployment_gates::DeploymentGatesAPI;
use datadog_api_client::datadogV2::model::DeploymentRuleDataType;
use datadog_api_client::datadogV2::model::DeploymentRuleOptionsFaultyDeploymentDetection;
use datadog_api_client::datadogV2::model::DeploymentRulesOptions;
use datadog_api_client::datadogV2::model::UpdateDeploymentRuleParams;
use datadog_api_client::datadogV2::model::UpdateDeploymentRuleParamsData;
Expand All @@ -19,9 +18,7 @@ async fn main() {
UpdateDeploymentRuleParamsDataAttributes::new(
false,
"Updated deployment rule".to_string(),
DeploymentRulesOptions::DeploymentRuleOptionsFaultyDeploymentDetection(Box::new(
DeploymentRuleOptionsFaultyDeploymentDetection::new().excluded_resources(vec![]),
)),
DeploymentRulesOptions::new(),
),
DeploymentRuleDataType::DEPLOYMENT_RULE,
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct CreateDeploymentRuleParamsDataAttributes {
/// The name of the deployment rule.
#[serde(rename = "name")]
pub name: String,
/// Options for deployment rule response representing either faulty deployment detection or monitor options.
/// Options for deployment rule response representing either faulty deployment detection or monitor options. The actual type is determined by the parent's 'type' field.
#[serde(rename = "options")]
pub options: crate::datadogV2::model::DeploymentRulesOptions,
/// The type of the deployment rule (faulty_deployment_detection or monitor).
Expand Down Expand Up @@ -100,14 +100,6 @@ impl<'de> Deserialize<'de> for CreateDeploymentRuleParamsDataAttributes {
}
"options" => {
options = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
if let Some(ref _options) = options {
match _options {
crate::datadogV2::model::DeploymentRulesOptions::UnparsedObject(_options) => {
_unparsed = true;
},
_ => {}
}
}
}
"type" => {
type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct DeploymentRuleResponseDataAttributes {
/// The name of the deployment rule.
#[serde(rename = "name")]
pub name: String,
/// Options for deployment rule response representing either faulty deployment detection or monitor options.
/// Options for deployment rule response representing either faulty deployment detection or monitor options. The actual type is determined by the parent's 'type' field.
#[serde(rename = "options")]
pub options: crate::datadogV2::model::DeploymentRulesOptions,
/// The type of the deployment rule.
Expand Down Expand Up @@ -149,14 +149,6 @@ impl<'de> Deserialize<'de> for DeploymentRuleResponseDataAttributes {
}
"options" => {
options = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
if let Some(ref _options) = options {
match _options {
crate::datadogV2::model::DeploymentRulesOptions::UnparsedObject(_options) => {
_unparsed = true;
},
_ => {}
}
}
}
"type" => {
type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
Expand Down
95 changes: 68 additions & 27 deletions src/datadogV2/model/model_deployment_rules_options.rs
Original file line number Diff line number Diff line change
@@ -1,47 +1,88 @@
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2019-Present Datadog, Inc.
use serde::de::{Error, MapAccess, Visitor};
use serde::{Deserialize, Deserializer, Serialize};
use serde_with::skip_serializing_none;
use std::fmt::{self, Formatter};

/// Options for deployment rule response representing either faulty deployment detection or monitor options.
/// Options for deployment rule response representing either faulty deployment detection or monitor options. The actual type is determined by the parent's 'type' field.
#[non_exhaustive]
#[skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize)]
#[serde(untagged)]
pub enum DeploymentRulesOptions {
DeploymentRuleOptionsFaultyDeploymentDetection(
Box<crate::datadogV2::model::DeploymentRuleOptionsFaultyDeploymentDetection>,
),
DeploymentRuleOptionsMonitor(Box<crate::datadogV2::model::DeploymentRuleOptionsMonitor>),
UnparsedObject(crate::datadog::UnparsedObject),
pub struct DeploymentRulesOptions {
#[serde(flatten)]
pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
#[serde(skip)]
#[serde(default)]
pub(crate) _unparsed: bool,
}

impl DeploymentRulesOptions {
pub fn new() -> DeploymentRulesOptions {
DeploymentRulesOptions {
additional_properties: std::collections::BTreeMap::new(),
_unparsed: false,
}
}

pub fn additional_properties(
mut self,
value: std::collections::BTreeMap<String, serde_json::Value>,
) -> Self {
self.additional_properties = value;
self
}
}

impl Default for DeploymentRulesOptions {
fn default() -> Self {
Self::new()
}
}

impl<'de> Deserialize<'de> for DeploymentRulesOptions {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let value: serde_json::Value = Deserialize::deserialize(deserializer)?;
if let Ok(_v) = serde_json::from_value::<
Box<crate::datadogV2::model::DeploymentRuleOptionsFaultyDeploymentDetection>,
>(value.clone())
{
if !_v._unparsed {
return Ok(
DeploymentRulesOptions::DeploymentRuleOptionsFaultyDeploymentDetection(_v),
);
struct DeploymentRulesOptionsVisitor;
impl<'a> Visitor<'a> for DeploymentRulesOptionsVisitor {
type Value = DeploymentRulesOptions;

fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.write_str("a mapping")
}
}
if let Ok(_v) = serde_json::from_value::<
Box<crate::datadogV2::model::DeploymentRuleOptionsMonitor>,
>(value.clone())
{
if !_v._unparsed {
return Ok(DeploymentRulesOptions::DeploymentRuleOptionsMonitor(_v));

fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
where
M: MapAccess<'a>,
{
let mut additional_properties: std::collections::BTreeMap<
String,
serde_json::Value,
> = std::collections::BTreeMap::new();
let mut _unparsed = false;

while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
match k.as_str() {
&_ => {
if let Ok(value) = serde_json::from_value(v.clone()) {
additional_properties.insert(k, value);
}
}
}
}

let content = DeploymentRulesOptions {
additional_properties,
_unparsed,
};

Ok(content)
}
}

return Ok(DeploymentRulesOptions::UnparsedObject(
crate::datadog::UnparsedObject { value },
));
deserializer.deserialize_any(DeploymentRulesOptionsVisitor)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct UpdateDeploymentRuleParamsDataAttributes {
/// The name of the deployment rule.
#[serde(rename = "name")]
pub name: String,
/// Options for deployment rule response representing either faulty deployment detection or monitor options.
/// Options for deployment rule response representing either faulty deployment detection or monitor options. The actual type is determined by the parent's 'type' field.
#[serde(rename = "options")]
pub options: crate::datadogV2::model::DeploymentRulesOptions,
#[serde(flatten)]
Expand Down Expand Up @@ -87,14 +87,6 @@ impl<'de> Deserialize<'de> for UpdateDeploymentRuleParamsDataAttributes {
}
"options" => {
options = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
if let Some(ref _options) = options {
match _options {
crate::datadogV2::model::DeploymentRulesOptions::UnparsedObject(_options) => {
_unparsed = true;
},
_ => {}
}
}
}
&_ => {
if let Ok(value) = serde_json::from_value(v.clone()) {
Expand Down
6 changes: 3 additions & 3 deletions tests/scenarios/features/v2/deployment_gates.feature
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Feature: Deployment Gates
Given operation "CreateDeploymentRule" enabled
And new "CreateDeploymentRule" request
And request contains "gate_id" parameter from "REPLACE.ME"
And body with value {"data": {"attributes": {"dry_run": false, "name": "My deployment rule", "options": {"duration": 3600, "excluded_resources": ["resource1", "resource2"]}, "type": "faulty_deployment_detection"}, "type": "deployment_rule"}}
And body with value {"data": {"attributes": {"dry_run": false, "name": "My deployment rule", "type": "faulty_deployment_detection"}, "type": "deployment_rule"}}
When the request is sent
Then the response status is 400 Bad request.

Expand Down Expand Up @@ -279,7 +279,7 @@ Feature: Deployment Gates
And new "UpdateDeploymentRule" request
And request contains "gate_id" parameter from "REPLACE.ME"
And request contains "id" parameter from "REPLACE.ME"
And body with value {"data": {"attributes": {"dry_run": false, "name": "Updated deployment rule", "options": {"duration": 3600, "excluded_resources": ["resource1", "resource2"]}}, "type": "deployment_rule"}}
And body with value {"data": {"attributes": {"dry_run": false, "name": "Updated deployment rule"}, "type": "deployment_rule"}}
When the request is sent
Then the response status is 400 Bad request.

Expand All @@ -289,7 +289,7 @@ Feature: Deployment Gates
And new "UpdateDeploymentRule" request
And request contains "gate_id" parameter from "REPLACE.ME"
And request contains "id" parameter from "REPLACE.ME"
And body with value {"data": {"attributes": {"dry_run": false, "name": "Updated deployment rule", "options": {"duration": 3600, "excluded_resources": ["resource1", "resource2"]}}, "type": "deployment_rule"}}
And body with value {"data": {"attributes": {"dry_run": false, "name": "Updated deployment rule"}, "type": "deployment_rule"}}
When the request is sent
Then the response status is 404 Deployment rule not found.

Expand Down