Skip to content

Commit

Permalink
Add support for multi form parameter support (#312)
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin Zou <kevin.zou@datadoghq.com>
Co-authored-by: api-clients-generation-pipeline[bot] <54105614+api-clients-generation-pipeline[bot]@users.noreply.github.com>
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
  • Loading branch information
3 people authored Nov 4, 2024
1 parent de29536 commit 7a643e5
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 58 deletions.
8 changes: 4 additions & 4 deletions .apigentools-info
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"spec_versions": {
"v1": {
"apigentools_version": "1.6.6",
"regenerated": "2024-11-04 17:58:12.003191",
"spec_repo_commit": "6ffe013b"
"regenerated": "2024-11-04 18:34:29.782864",
"spec_repo_commit": "aeb956c4"
},
"v2": {
"apigentools_version": "1.6.6",
"regenerated": "2024-11-04 17:58:12.022079",
"spec_repo_commit": "6ffe013b"
"regenerated": "2024-11-04 18:34:29.801879",
"spec_repo_commit": "aeb956c4"
}
}
}
7 changes: 7 additions & 0 deletions .generator/src/generator/templates/api.j2
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,19 @@ impl {{ structName }} {
let mut local_req_builder = local_client.request(reqwest::Method::{{ httpMethod }}, local_uri_str.as_str());

{% for name, parameter in operation|parameters if parameter.in == "query" %}
{%- set collectionFormat = parameter|collection_format %}
{%- set schema = parameter | parameter_schema %}
{%- if parameter.required and schema.type == "array" %}
local_req_builder = local_req_builder.query(&[("{{name}}", &{{name|variable_name}}.iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]);
{%- elif not parameter.required and schema.type == "array" %}
if let Some(ref local) = {{name|variable_name}} {
{%- if collectionFormat == "multi" -%}
for param in local {
local_req_builder = local_req_builder.query(&[("{{name}}", &param.to_string())]);
}
{%- else %}
local_req_builder = local_req_builder.query(&[("{{name}}", &local.iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]);
{%- endif %}
};
{%- elif parameter.required %}
local_req_builder = local_req_builder.query(&[("{{name}}", &{{name|variable_name}}.{%- if not schema.format == "date-time" %}to_string() {% else %}to_rfc3339_opts(chrono::SecondsFormat::Millis, true){% endif %})]);
Expand Down
25 changes: 25 additions & 0 deletions examples/v2_security-monitoring_ListFindings_1668290866.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// List findings with detection_type query param returns "OK" response
use datadog_api_client::datadog;
use datadog_api_client::datadogV2::api_security_monitoring::ListFindingsOptionalParams;
use datadog_api_client::datadogV2::api_security_monitoring::SecurityMonitoringAPI;
use datadog_api_client::datadogV2::model::FindingVulnerabilityType;

#[tokio::main]
async fn main() {
let mut configuration = datadog::Configuration::new();
configuration.set_unstable_operation_enabled("v2.ListFindings", true);
let api = SecurityMonitoringAPI::with_config(configuration);
let resp = api
.list_findings(
ListFindingsOptionalParams::default().filter_vulnerability_type(vec![
FindingVulnerabilityType::MISCONFIGURATION,
FindingVulnerabilityType::ATTACK_PATH,
]),
)
.await;
if let Ok(value) = resp {
println!("{:#?}", value);
} else {
println!("{:#?}", resp.unwrap_err());
}
}
24 changes: 6 additions & 18 deletions src/datadogV1/api/api_synthetics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2024,15 +2024,9 @@ impl SyntheticsAPI {
local_req_builder.query(&[("to_ts", &local_query_param.to_string())]);
};
if let Some(ref local) = probe_dc {
local_req_builder = local_req_builder.query(&[(
"probe_dc",
&local
.iter()
.map(|p| p.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]);
for param in local {
local_req_builder = local_req_builder.query(&[("probe_dc", &param.to_string())]);
}
};

// build headers
Expand Down Expand Up @@ -2390,15 +2384,9 @@ impl SyntheticsAPI {
local_req_builder.query(&[("to_ts", &local_query_param.to_string())]);
};
if let Some(ref local) = probe_dc {
local_req_builder = local_req_builder.query(&[(
"probe_dc",
&local
.iter()
.map(|p| p.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]);
for param in local {
local_req_builder = local_req_builder.query(&[("probe_dc", &param.to_string())]);
}
};

// build headers
Expand Down
24 changes: 6 additions & 18 deletions src/datadogV1/api/api_usage_metering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4018,15 +4018,9 @@ impl UsageMeteringAPI {
)]);
};
if let Some(ref local) = index_name {
local_req_builder = local_req_builder.query(&[(
"index_name",
&local
.iter()
.map(|p| p.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]);
for param in local {
local_req_builder = local_req_builder.query(&[("index_name", &param.to_string())]);
}
};

// build headers
Expand Down Expand Up @@ -6005,15 +5999,9 @@ impl UsageMeteringAPI {
)]);
};
if let Some(ref local) = names {
local_req_builder = local_req_builder.query(&[(
"names",
&local
.iter()
.map(|p| p.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]);
for param in local {
local_req_builder = local_req_builder.query(&[("names", &param.to_string())]);
}
};
if let Some(ref local_query_param) = limit {
local_req_builder =
Expand Down
13 changes: 4 additions & 9 deletions src/datadogV2/api/api_security_monitoring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2823,15 +2823,10 @@ impl SecurityMonitoringAPI {
local_req_builder.query(&[("filter[status]", &local_query_param.to_string())]);
};
if let Some(ref local) = filter_vulnerability_type {
local_req_builder = local_req_builder.query(&[(
"filter[vulnerability_type]",
&local
.iter()
.map(|p| p.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]);
for param in local {
local_req_builder =
local_req_builder.query(&[("filter[vulnerability_type]", &param.to_string())]);
}
};

// build headers
Expand Down
12 changes: 3 additions & 9 deletions src/datadogV2/api/api_teams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1838,15 +1838,9 @@ impl TeamsAPI {
local_req_builder.query(&[("sort", &local_query_param.to_string())]);
};
if let Some(ref local) = include {
local_req_builder = local_req_builder.query(&[(
"include",
&local
.iter()
.map(|p| p.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]);
for param in local {
local_req_builder = local_req_builder.query(&[("include", &param.to_string())]);
}
};
if let Some(ref local_query_param) = filter_keyword {
local_req_builder =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-10-21T20:05:58.636Z
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"http_interactions": [
{
"request": {
"body": "",
"headers": {
"Accept": [
"application/json"
]
},
"method": "get",
"uri": "https://api.datadoghq.com/api/v2/posture_management/findings?filter%5Bvulnerability_type%5D=misconfiguration&filter%5Bvulnerability_type%5D=attack_path"
},
"response": {
"body": {
"string": "{\"data\":[],\"meta\":{\"page\":{\"total_filtered_count\":0},\"snapshot_timestamp\":1729541158755}}",
"encoding": null
},
"headers": {
"Content-Type": [
"application/vnd.api+json"
]
},
"status": {
"code": 200,
"message": "OK"
}
},
"recorded_at": "Mon, 21 Oct 2024 20:05:58 GMT"
}
],
"recorded_with": "VCR 6.0.0"
}
8 changes: 8 additions & 0 deletions tests/scenarios/features/v2/security_monitoring.feature
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,14 @@ Feature: Security Monitoring
When the request with pagination is sent
Then the response status is 200 OK

@skip-terraform-config @team:DataDog/cloud-security-posture-management
Scenario: List findings with detection_type query param returns "OK" response
Given operation "ListFindings" enabled
And new "ListFindings" request
And request contains "filter[vulnerability_type]" parameter with value ["misconfiguration", "attack_path"]
When the request is sent
Then the response status is 200 OK

@generated @skip @team:DataDog/k9-cloud-security-platform
Scenario: List rules returns "Bad Request" response
Given new "ListSecurityMonitoringRules" request
Expand Down

0 comments on commit 7a643e5

Please sign in to comment.