Skip to content

Mark Cost Attribution end_month parameter as not required #310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
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-10-10 19:45:59.732627",
"spec_repo_commit": "049920eb"
"regenerated": "2024-10-16 20:07:15.312516",
"spec_repo_commit": "86072741"
},
"v2": {
"apigentools_version": "1.6.6",
"regenerated": "2024-10-10 19:45:59.753615",
"spec_repo_commit": "049920eb"
"regenerated": "2024-10-16 20:07:15.331877",
"spec_repo_commit": "86072741"
}
}
}
2 changes: 1 addition & 1 deletion .generator/schemas/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28730,7 +28730,7 @@ paths:
for cost ending this month.'
in: query
name: end_month
required: true
required: false
schema:
format: date-time
type: string
Expand Down
9 changes: 5 additions & 4 deletions examples/v2_usage-metering_GetMonthlyCostAttribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ async fn main() {
DateTime::parse_from_rfc3339("2021-11-06T11:11:11+00:00")
.expect("Failed to parse datetime")
.with_timezone(&Utc),
DateTime::parse_from_rfc3339("2021-11-08T11:11:11+00:00")
.expect("Failed to parse datetime")
.with_timezone(&Utc),
"infra_host_total_cost".to_string(),
GetMonthlyCostAttributionOptionalParams::default(),
GetMonthlyCostAttributionOptionalParams::default().end_month(
DateTime::parse_from_rfc3339("2021-11-08T11:11:11+00:00")
.expect("Failed to parse datetime")
.with_timezone(&Utc),
),
)
.await;
if let Ok(value) = resp {
Expand Down
22 changes: 15 additions & 7 deletions src/datadogV2/api/api_usage_metering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ impl GetHourlyUsageOptionalParams {
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct GetMonthlyCostAttributionOptionalParams {
/// Datetime in ISO-8601 format, UTC, precise to month: `[YYYY-MM]` for cost ending this month.
pub end_month: Option<chrono::DateTime<chrono::Utc>>,
/// The direction to sort by: `[desc, asc]`.
pub sort_direction: Option<crate::datadogV2::model::SortDirection>,
/// The billing dimension to sort by. Always sorted by total cost. Example: `infra_host`.
Expand All @@ -183,6 +185,11 @@ pub struct GetMonthlyCostAttributionOptionalParams {
}

impl GetMonthlyCostAttributionOptionalParams {
/// Datetime in ISO-8601 format, UTC, precise to month: `[YYYY-MM]` for cost ending this month.
pub fn end_month(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
self.end_month = Some(value);
self
}
/// The direction to sort by: `[desc, asc]`.
pub fn sort_direction(mut self, value: crate::datadogV2::model::SortDirection) -> Self {
self.sort_direction = Some(value);
Expand Down Expand Up @@ -1193,15 +1200,14 @@ impl UsageMeteringAPI {
pub async fn get_monthly_cost_attribution(
&self,
start_month: chrono::DateTime<chrono::Utc>,
end_month: chrono::DateTime<chrono::Utc>,
fields: String,
params: GetMonthlyCostAttributionOptionalParams,
) -> Result<
crate::datadogV2::model::MonthlyCostAttributionResponse,
datadog::Error<GetMonthlyCostAttributionError>,
> {
match self
.get_monthly_cost_attribution_with_http_info(start_month, end_month, fields, params)
.get_monthly_cost_attribution_with_http_info(start_month, fields, params)
.await
{
Ok(response_content) => {
Expand Down Expand Up @@ -1236,7 +1242,6 @@ impl UsageMeteringAPI {
pub async fn get_monthly_cost_attribution_with_http_info(
&self,
start_month: chrono::DateTime<chrono::Utc>,
end_month: chrono::DateTime<chrono::Utc>,
fields: String,
params: GetMonthlyCostAttributionOptionalParams,
) -> Result<
Expand All @@ -1255,6 +1260,7 @@ impl UsageMeteringAPI {
}

// unbox and build optional parameters
let end_month = params.end_month;
let sort_direction = params.sort_direction;
let sort_name = params.sort_name;
let tag_breakdown_keys = params.tag_breakdown_keys;
Expand All @@ -1274,11 +1280,13 @@ impl UsageMeteringAPI {
"start_month",
&start_month.to_rfc3339_opts(chrono::SecondsFormat::Millis, true),
)]);
local_req_builder = local_req_builder.query(&[(
"end_month",
&end_month.to_rfc3339_opts(chrono::SecondsFormat::Millis, true),
)]);
local_req_builder = local_req_builder.query(&[("fields", &fields.to_string())]);
if let Some(ref local_query_param) = end_month {
local_req_builder = local_req_builder.query(&[(
"end_month",
&local_query_param.to_rfc3339_opts(chrono::SecondsFormat::Millis, true),
)]);
};
if let Some(ref local_query_param) = sort_direction {
local_req_builder =
local_req_builder.query(&[("sort_direction", &local_query_param.to_string())]);
Expand Down
4 changes: 2 additions & 2 deletions tests/scenarios/features/v2/usage_metering.feature
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ Feature: Usage Metering
Given operation "GetMonthlyCostAttribution" enabled
And new "GetMonthlyCostAttribution" request
And request contains "start_month" parameter with value "{{ timeISO('now - 5d') }}"
And request contains "end_month" parameter with value "{{ timeISO('now - 3d') }}"
And request contains "fields" parameter with value "not_a_product"
And request contains "end_month" parameter with value "{{ timeISO('now - 3d') }}"
When the request is sent
Then the response status is 400 Bad Request

Expand All @@ -29,8 +29,8 @@ Feature: Usage Metering
Given operation "GetMonthlyCostAttribution" enabled
And new "GetMonthlyCostAttribution" request
And request contains "start_month" parameter with value "{{ timeISO('now - 5d') }}"
And request contains "end_month" parameter with value "{{ timeISO('now - 3d') }}"
And request contains "fields" parameter with value "infra_host_total_cost"
And request contains "end_month" parameter with value "{{ timeISO('now - 3d') }}"
When the request is sent
Then the response status is 200 OK

Expand Down
6 changes: 4 additions & 2 deletions tests/scenarios/function_mappings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13151,8 +13151,10 @@ fn test_v2_get_monthly_cost_attribution(
.expect("api instance not found");
let start_month =
serde_json::from_value(_parameters.get("start_month").unwrap().clone()).unwrap();
let end_month = serde_json::from_value(_parameters.get("end_month").unwrap().clone()).unwrap();
let fields = serde_json::from_value(_parameters.get("fields").unwrap().clone()).unwrap();
let end_month = _parameters
.get("end_month")
.and_then(|param| Some(serde_json::from_value(param.clone()).unwrap()));
let sort_direction = _parameters
.get("sort_direction")
.and_then(|param| Some(serde_json::from_value(param.clone()).unwrap()));
Expand All @@ -13170,14 +13172,14 @@ fn test_v2_get_monthly_cost_attribution(
.and_then(|param| Some(serde_json::from_value(param.clone()).unwrap()));
let mut params =
datadogV2::api_usage_metering::GetMonthlyCostAttributionOptionalParams::default();
params.end_month = end_month;
params.sort_direction = sort_direction;
params.sort_name = sort_name;
params.tag_breakdown_keys = tag_breakdown_keys;
params.next_record_id = next_record_id;
params.include_descendants = include_descendants;
let response = match block_on(api.get_monthly_cost_attribution_with_http_info(
start_month,
end_month,
fields,
params,
)) {
Expand Down
Loading