From d146e1f03576e299419b7f9d589127b91da3c13a Mon Sep 17 00:00:00 2001 From: Kevin Zou Date: Wed, 17 Jan 2024 14:50:15 -0500 Subject: [PATCH] fix inline oneOfs and primitive oneOf types --- .generator/src/generator/openapi.py | 2 ++ .generator/src/generator/templates/model_oneof.j2 | 4 ++++ src/datadogV1/model/model_distribution_point_item.rs | 4 ++-- src/datadogV1/model/model_distribution_points_series.rs | 7 +++++-- .../model/model_shared_dashboard_invites_data.rs | 4 +--- .../model/model_ci_app_aggregate_bucket_value.rs | 6 +++--- src/datadogV2/model/model_ci_app_group_by_missing.rs | 4 ++-- src/datadogV2/model/model_ci_app_group_by_total.rs | 6 +++--- src/datadogV2/model/model_incident_todo_assignee.rs | 2 +- src/datadogV2/model/model_logs_aggregate_bucket_value.rs | 8 +++----- src/datadogV2/model/model_logs_group_by_missing.rs | 4 ++-- src/datadogV2/model/model_logs_group_by_total.rs | 6 +++--- src/datadogV2/model/model_rum_aggregate_bucket_value.rs | 8 +++----- src/datadogV2/model/model_rum_group_by_missing.rs | 4 ++-- src/datadogV2/model/model_rum_group_by_total.rs | 6 +++--- .../model/model_service_definitions_create_request.rs | 2 +- .../model/model_spans_aggregate_bucket_value.rs | 6 +++--- src/datadogV2/model/model_spans_group_by_missing.rs | 4 ++-- src/datadogV2/model/model_spans_group_by_total.rs | 6 +++--- tests/main.rs | 9 +++++++-- 20 files changed, 55 insertions(+), 47 deletions(-) diff --git a/.generator/src/generator/openapi.py b/.generator/src/generator/openapi.py index 2dc9a479c..23f0ebffe 100644 --- a/.generator/src/generator/openapi.py +++ b/.generator/src/generator/openapi.py @@ -59,6 +59,8 @@ def type_to_rust(schema, alternative_name=None, render_nullable=False, render_op type_ = "array" elif "properties" in schema: type_ = "object" + elif "oneOf" in schema: + return alternative_name else: type_ = "object" warnings.warn(f"Unknown type for schema: {schema} ({name or alternative_name})") diff --git a/.generator/src/generator/templates/model_oneof.j2 b/.generator/src/generator/templates/model_oneof.j2 index dcf92d792..c4e59c7a8 100644 --- a/.generator/src/generator/templates/model_oneof.j2 +++ b/.generator/src/generator/templates/model_oneof.j2 @@ -7,6 +7,10 @@ pub enum {{name}} { {%- for oneOf in model.oneOf %} {%- set dataType = get_type(oneOf, render_nullable=False, render_option=False, version=version) %} {%- set attributeName = (get_name(oneOf) or dataType)|upperfirst %} + {%- if oneOf | is_primitive or oneOf.type == "array" %} + {{attributeName}}({{dataType}}), + {%- else %} {{attributeName}}(Box<{{dataType}}>), + {%- endif %} {%- endfor%} } diff --git a/src/datadogV1/model/model_distribution_point_item.rs b/src/datadogV1/model/model_distribution_point_item.rs index 964b3be3d..acc859614 100644 --- a/src/datadogV1/model/model_distribution_point_item.rs +++ b/src/datadogV1/model/model_distribution_point_item.rs @@ -7,6 +7,6 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(untagged)] pub enum DistributionPointItem { - DistributionPointTimestamp(Box), - DistributionPointData(Box>), + DistributionPointTimestamp(f64), + DistributionPointData(Vec), } diff --git a/src/datadogV1/model/model_distribution_points_series.rs b/src/datadogV1/model/model_distribution_points_series.rs index 75b3b8b2a..4aced3d91 100644 --- a/src/datadogV1/model/model_distribution_points_series.rs +++ b/src/datadogV1/model/model_distribution_points_series.rs @@ -16,7 +16,7 @@ pub struct DistributionPointsSeries { pub metric: String, /// Points relating to the distribution point metric. All points must be tuples with timestamp and a list of values (cannot be a string). Timestamps should be in POSIX time in seconds. #[serde(rename = "points")] - pub points: Vec>, + pub points: Vec>, /// A list of tags associated with the distribution point metric. #[serde(rename = "tags")] pub tags: Option>, @@ -26,7 +26,10 @@ pub struct DistributionPointsSeries { } impl DistributionPointsSeries { - pub fn new(metric: String, points: Vec>) -> DistributionPointsSeries { + pub fn new( + metric: String, + points: Vec>, + ) -> DistributionPointsSeries { DistributionPointsSeries { host: None, metric, diff --git a/src/datadogV1/model/model_shared_dashboard_invites_data.rs b/src/datadogV1/model/model_shared_dashboard_invites_data.rs index fe9f44993..3ee00d5e8 100644 --- a/src/datadogV1/model/model_shared_dashboard_invites_data.rs +++ b/src/datadogV1/model/model_shared_dashboard_invites_data.rs @@ -10,7 +10,5 @@ pub enum SharedDashboardInvitesData { SharedDashboardInvitesDataObject( Box, ), - SharedDashboardInvitesDataList( - Box>, - ), + SharedDashboardInvitesDataList(Vec), } diff --git a/src/datadogV2/model/model_ci_app_aggregate_bucket_value.rs b/src/datadogV2/model/model_ci_app_aggregate_bucket_value.rs index 3d1377aa4..081e31a98 100644 --- a/src/datadogV2/model/model_ci_app_aggregate_bucket_value.rs +++ b/src/datadogV2/model/model_ci_app_aggregate_bucket_value.rs @@ -7,9 +7,9 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(untagged)] pub enum CIAppAggregateBucketValue { - CIAppAggregateBucketValueSingleString(Box), - CIAppAggregateBucketValueSingleNumber(Box), + CIAppAggregateBucketValueSingleString(String), + CIAppAggregateBucketValueSingleNumber(f64), CIAppAggregateBucketValueTimeseries( - Box, + crate::datadogV2::model::CIAppAggregateBucketValueTimeseries, ), } diff --git a/src/datadogV2/model/model_ci_app_group_by_missing.rs b/src/datadogV2/model/model_ci_app_group_by_missing.rs index 7f77ae13d..15ffd54b1 100644 --- a/src/datadogV2/model/model_ci_app_group_by_missing.rs +++ b/src/datadogV2/model/model_ci_app_group_by_missing.rs @@ -7,6 +7,6 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(untagged)] pub enum CIAppGroupByMissing { - CIAppGroupByMissingString(Box), - CIAppGroupByMissingNumber(Box), + CIAppGroupByMissingString(String), + CIAppGroupByMissingNumber(f64), } diff --git a/src/datadogV2/model/model_ci_app_group_by_total.rs b/src/datadogV2/model/model_ci_app_group_by_total.rs index 449d8196e..ca101fb9d 100644 --- a/src/datadogV2/model/model_ci_app_group_by_total.rs +++ b/src/datadogV2/model/model_ci_app_group_by_total.rs @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(untagged)] pub enum CIAppGroupByTotal { - CIAppGroupByTotalBoolean(Box), - CIAppGroupByTotalString(Box), - CIAppGroupByTotalNumber(Box), + CIAppGroupByTotalBoolean(bool), + CIAppGroupByTotalString(String), + CIAppGroupByTotalNumber(f64), } diff --git a/src/datadogV2/model/model_incident_todo_assignee.rs b/src/datadogV2/model/model_incident_todo_assignee.rs index dab06b362..d0056cef2 100644 --- a/src/datadogV2/model/model_incident_todo_assignee.rs +++ b/src/datadogV2/model/model_incident_todo_assignee.rs @@ -7,6 +7,6 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(untagged)] pub enum IncidentTodoAssignee { - IncidentTodoAssigneeHandle(Box), + IncidentTodoAssigneeHandle(String), IncidentTodoAnonymousAssignee(Box), } diff --git a/src/datadogV2/model/model_logs_aggregate_bucket_value.rs b/src/datadogV2/model/model_logs_aggregate_bucket_value.rs index 0210b56e3..5ccdb7a61 100644 --- a/src/datadogV2/model/model_logs_aggregate_bucket_value.rs +++ b/src/datadogV2/model/model_logs_aggregate_bucket_value.rs @@ -7,9 +7,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(untagged)] pub enum LogsAggregateBucketValue { - LogsAggregateBucketValueSingleString(Box), - LogsAggregateBucketValueSingleNumber(Box), - LogsAggregateBucketValueTimeseries( - Box, - ), + LogsAggregateBucketValueSingleString(String), + LogsAggregateBucketValueSingleNumber(f64), + LogsAggregateBucketValueTimeseries(crate::datadogV2::model::LogsAggregateBucketValueTimeseries), } diff --git a/src/datadogV2/model/model_logs_group_by_missing.rs b/src/datadogV2/model/model_logs_group_by_missing.rs index f812c84c9..b198eadc3 100644 --- a/src/datadogV2/model/model_logs_group_by_missing.rs +++ b/src/datadogV2/model/model_logs_group_by_missing.rs @@ -7,6 +7,6 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(untagged)] pub enum LogsGroupByMissing { - LogsGroupByMissingString(Box), - LogsGroupByMissingNumber(Box), + LogsGroupByMissingString(String), + LogsGroupByMissingNumber(f64), } diff --git a/src/datadogV2/model/model_logs_group_by_total.rs b/src/datadogV2/model/model_logs_group_by_total.rs index 17f963e26..c7b9ea26d 100644 --- a/src/datadogV2/model/model_logs_group_by_total.rs +++ b/src/datadogV2/model/model_logs_group_by_total.rs @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(untagged)] pub enum LogsGroupByTotal { - LogsGroupByTotalBoolean(Box), - LogsGroupByTotalString(Box), - LogsGroupByTotalNumber(Box), + LogsGroupByTotalBoolean(bool), + LogsGroupByTotalString(String), + LogsGroupByTotalNumber(f64), } diff --git a/src/datadogV2/model/model_rum_aggregate_bucket_value.rs b/src/datadogV2/model/model_rum_aggregate_bucket_value.rs index bc6ac235c..0835daaed 100644 --- a/src/datadogV2/model/model_rum_aggregate_bucket_value.rs +++ b/src/datadogV2/model/model_rum_aggregate_bucket_value.rs @@ -7,9 +7,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(untagged)] pub enum RUMAggregateBucketValue { - RUMAggregateBucketValueSingleString(Box), - RUMAggregateBucketValueSingleNumber(Box), - RUMAggregateBucketValueTimeseries( - Box, - ), + RUMAggregateBucketValueSingleString(String), + RUMAggregateBucketValueSingleNumber(f64), + RUMAggregateBucketValueTimeseries(crate::datadogV2::model::RUMAggregateBucketValueTimeseries), } diff --git a/src/datadogV2/model/model_rum_group_by_missing.rs b/src/datadogV2/model/model_rum_group_by_missing.rs index 7644bf2b7..8582e547a 100644 --- a/src/datadogV2/model/model_rum_group_by_missing.rs +++ b/src/datadogV2/model/model_rum_group_by_missing.rs @@ -7,6 +7,6 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(untagged)] pub enum RUMGroupByMissing { - RUMGroupByMissingString(Box), - RUMGroupByMissingNumber(Box), + RUMGroupByMissingString(String), + RUMGroupByMissingNumber(f64), } diff --git a/src/datadogV2/model/model_rum_group_by_total.rs b/src/datadogV2/model/model_rum_group_by_total.rs index 16f704b95..ac7efa1bf 100644 --- a/src/datadogV2/model/model_rum_group_by_total.rs +++ b/src/datadogV2/model/model_rum_group_by_total.rs @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(untagged)] pub enum RUMGroupByTotal { - RUMGroupByTotalBoolean(Box), - RUMGroupByTotalString(Box), - RUMGroupByTotalNumber(Box), + RUMGroupByTotalBoolean(bool), + RUMGroupByTotalString(String), + RUMGroupByTotalNumber(f64), } diff --git a/src/datadogV2/model/model_service_definitions_create_request.rs b/src/datadogV2/model/model_service_definitions_create_request.rs index 9d2072ecd..58135a292 100644 --- a/src/datadogV2/model/model_service_definitions_create_request.rs +++ b/src/datadogV2/model/model_service_definitions_create_request.rs @@ -10,5 +10,5 @@ pub enum ServiceDefinitionsCreateRequest { ServiceDefinitionV2Dot2(Box), ServiceDefinitionV2Dot1(Box), ServiceDefinitionV2(Box), - ServiceDefinitionRaw(Box), + ServiceDefinitionRaw(String), } diff --git a/src/datadogV2/model/model_spans_aggregate_bucket_value.rs b/src/datadogV2/model/model_spans_aggregate_bucket_value.rs index 048815570..0efbaedad 100644 --- a/src/datadogV2/model/model_spans_aggregate_bucket_value.rs +++ b/src/datadogV2/model/model_spans_aggregate_bucket_value.rs @@ -7,9 +7,9 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(untagged)] pub enum SpansAggregateBucketValue { - SpansAggregateBucketValueSingleString(Box), - SpansAggregateBucketValueSingleNumber(Box), + SpansAggregateBucketValueSingleString(String), + SpansAggregateBucketValueSingleNumber(f64), SpansAggregateBucketValueTimeseries( - Box, + crate::datadogV2::model::SpansAggregateBucketValueTimeseries, ), } diff --git a/src/datadogV2/model/model_spans_group_by_missing.rs b/src/datadogV2/model/model_spans_group_by_missing.rs index 45ff9894d..f14ebcf79 100644 --- a/src/datadogV2/model/model_spans_group_by_missing.rs +++ b/src/datadogV2/model/model_spans_group_by_missing.rs @@ -7,6 +7,6 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(untagged)] pub enum SpansGroupByMissing { - SpansGroupByMissingString(Box), - SpansGroupByMissingNumber(Box), + SpansGroupByMissingString(String), + SpansGroupByMissingNumber(f64), } diff --git a/src/datadogV2/model/model_spans_group_by_total.rs b/src/datadogV2/model/model_spans_group_by_total.rs index 0f8446a63..87209034c 100644 --- a/src/datadogV2/model/model_spans_group_by_total.rs +++ b/src/datadogV2/model/model_spans_group_by_total.rs @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(untagged)] pub enum SpansGroupByTotal { - SpansGroupByTotalBoolean(Box), - SpansGroupByTotalString(Box), - SpansGroupByTotalNumber(Box), + SpansGroupByTotalBoolean(bool), + SpansGroupByTotalString(String), + SpansGroupByTotalNumber(f64), } diff --git a/tests/main.rs b/tests/main.rs index b6a9cf12d..fb6ae691f 100644 --- a/tests/main.rs +++ b/tests/main.rs @@ -3,7 +3,9 @@ mod scenarios; use cucumber::{cli, parser, runner, writer, World}; use lazy_static::lazy_static; use regex::Regex; -use scenarios::fixtures::{after_scenario, before_scenario, given_resource_in_system, DatadogWorld}; +use scenarios::fixtures::{ + after_scenario, before_scenario, given_resource_in_system, DatadogWorld, +}; use serde_json::Value; use std::{env, fs::File, io::BufReader}; @@ -78,7 +80,10 @@ async fn main() { }); for value in GIVEN_MAP.as_array().unwrap() { - cucumber = cucumber.given(Regex::new(value.get("step").unwrap().as_str().unwrap()).unwrap(), given_resource_in_system); + cucumber = cucumber.given( + Regex::new(value.get("step").unwrap().as_str().unwrap()).unwrap(), + given_resource_in_system, + ); } cucumber