Skip to content

Commit

Permalink
fix inline oneOfs and primitive oneOf types
Browse files Browse the repository at this point in the history
  • Loading branch information
nkzou committed Jan 17, 2024
1 parent ff2ef88 commit d146e1f
Show file tree
Hide file tree
Showing 20 changed files with 55 additions and 47 deletions.
2 changes: 2 additions & 0 deletions .generator/src/generator/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})")
Expand Down
4 changes: 4 additions & 0 deletions .generator/src/generator/templates/model_oneof.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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%}
}
4 changes: 2 additions & 2 deletions src/datadogV1/model/model_distribution_point_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DistributionPointItem {
DistributionPointTimestamp(Box<f64>),
DistributionPointData(Box<Vec<f64>>),
DistributionPointTimestamp(f64),
DistributionPointData(Vec<f64>),
}
7 changes: 5 additions & 2 deletions src/datadogV1/model/model_distribution_points_series.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<serde_json::Value>>,
pub points: Vec<Vec<crate::datadogV1::model::DistributionPointItem>>,
/// A list of tags associated with the distribution point metric.
#[serde(rename = "tags")]
pub tags: Option<Vec<String>>,
Expand All @@ -26,7 +26,10 @@ pub struct DistributionPointsSeries {
}

impl DistributionPointsSeries {
pub fn new(metric: String, points: Vec<Vec<serde_json::Value>>) -> DistributionPointsSeries {
pub fn new(
metric: String,
points: Vec<Vec<crate::datadogV1::model::DistributionPointItem>>,
) -> DistributionPointsSeries {
DistributionPointsSeries {
host: None,
metric,
Expand Down
4 changes: 1 addition & 3 deletions src/datadogV1/model/model_shared_dashboard_invites_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,5 @@ pub enum SharedDashboardInvitesData {
SharedDashboardInvitesDataObject(
Box<crate::datadogV1::model::SharedDashboardInvitesDataObject>,
),
SharedDashboardInvitesDataList(
Box<Vec<crate::datadogV1::model::SharedDashboardInvitesDataObject>>,
),
SharedDashboardInvitesDataList(Vec<crate::datadogV1::model::SharedDashboardInvitesDataObject>),
}
6 changes: 3 additions & 3 deletions src/datadogV2/model/model_ci_app_aggregate_bucket_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CIAppAggregateBucketValue {
CIAppAggregateBucketValueSingleString(Box<String>),
CIAppAggregateBucketValueSingleNumber(Box<f64>),
CIAppAggregateBucketValueSingleString(String),
CIAppAggregateBucketValueSingleNumber(f64),
CIAppAggregateBucketValueTimeseries(
Box<crate::datadogV2::model::CIAppAggregateBucketValueTimeseries>,
crate::datadogV2::model::CIAppAggregateBucketValueTimeseries,
),
}
4 changes: 2 additions & 2 deletions src/datadogV2/model/model_ci_app_group_by_missing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CIAppGroupByMissing {
CIAppGroupByMissingString(Box<String>),
CIAppGroupByMissingNumber(Box<f64>),
CIAppGroupByMissingString(String),
CIAppGroupByMissingNumber(f64),
}
6 changes: 3 additions & 3 deletions src/datadogV2/model/model_ci_app_group_by_total.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CIAppGroupByTotal {
CIAppGroupByTotalBoolean(Box<bool>),
CIAppGroupByTotalString(Box<String>),
CIAppGroupByTotalNumber(Box<f64>),
CIAppGroupByTotalBoolean(bool),
CIAppGroupByTotalString(String),
CIAppGroupByTotalNumber(f64),
}
2 changes: 1 addition & 1 deletion src/datadogV2/model/model_incident_todo_assignee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum IncidentTodoAssignee {
IncidentTodoAssigneeHandle(Box<String>),
IncidentTodoAssigneeHandle(String),
IncidentTodoAnonymousAssignee(Box<crate::datadogV2::model::IncidentTodoAnonymousAssignee>),
}
8 changes: 3 additions & 5 deletions src/datadogV2/model/model_logs_aggregate_bucket_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum LogsAggregateBucketValue {
LogsAggregateBucketValueSingleString(Box<String>),
LogsAggregateBucketValueSingleNumber(Box<f64>),
LogsAggregateBucketValueTimeseries(
Box<crate::datadogV2::model::LogsAggregateBucketValueTimeseries>,
),
LogsAggregateBucketValueSingleString(String),
LogsAggregateBucketValueSingleNumber(f64),
LogsAggregateBucketValueTimeseries(crate::datadogV2::model::LogsAggregateBucketValueTimeseries),
}
4 changes: 2 additions & 2 deletions src/datadogV2/model/model_logs_group_by_missing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum LogsGroupByMissing {
LogsGroupByMissingString(Box<String>),
LogsGroupByMissingNumber(Box<f64>),
LogsGroupByMissingString(String),
LogsGroupByMissingNumber(f64),
}
6 changes: 3 additions & 3 deletions src/datadogV2/model/model_logs_group_by_total.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum LogsGroupByTotal {
LogsGroupByTotalBoolean(Box<bool>),
LogsGroupByTotalString(Box<String>),
LogsGroupByTotalNumber(Box<f64>),
LogsGroupByTotalBoolean(bool),
LogsGroupByTotalString(String),
LogsGroupByTotalNumber(f64),
}
8 changes: 3 additions & 5 deletions src/datadogV2/model/model_rum_aggregate_bucket_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RUMAggregateBucketValue {
RUMAggregateBucketValueSingleString(Box<String>),
RUMAggregateBucketValueSingleNumber(Box<f64>),
RUMAggregateBucketValueTimeseries(
Box<crate::datadogV2::model::RUMAggregateBucketValueTimeseries>,
),
RUMAggregateBucketValueSingleString(String),
RUMAggregateBucketValueSingleNumber(f64),
RUMAggregateBucketValueTimeseries(crate::datadogV2::model::RUMAggregateBucketValueTimeseries),
}
4 changes: 2 additions & 2 deletions src/datadogV2/model/model_rum_group_by_missing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RUMGroupByMissing {
RUMGroupByMissingString(Box<String>),
RUMGroupByMissingNumber(Box<f64>),
RUMGroupByMissingString(String),
RUMGroupByMissingNumber(f64),
}
6 changes: 3 additions & 3 deletions src/datadogV2/model/model_rum_group_by_total.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RUMGroupByTotal {
RUMGroupByTotalBoolean(Box<bool>),
RUMGroupByTotalString(Box<String>),
RUMGroupByTotalNumber(Box<f64>),
RUMGroupByTotalBoolean(bool),
RUMGroupByTotalString(String),
RUMGroupByTotalNumber(f64),
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ pub enum ServiceDefinitionsCreateRequest {
ServiceDefinitionV2Dot2(Box<crate::datadogV2::model::ServiceDefinitionV2Dot2>),
ServiceDefinitionV2Dot1(Box<crate::datadogV2::model::ServiceDefinitionV2Dot1>),
ServiceDefinitionV2(Box<crate::datadogV2::model::ServiceDefinitionV2>),
ServiceDefinitionRaw(Box<String>),
ServiceDefinitionRaw(String),
}
6 changes: 3 additions & 3 deletions src/datadogV2/model/model_spans_aggregate_bucket_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SpansAggregateBucketValue {
SpansAggregateBucketValueSingleString(Box<String>),
SpansAggregateBucketValueSingleNumber(Box<f64>),
SpansAggregateBucketValueSingleString(String),
SpansAggregateBucketValueSingleNumber(f64),
SpansAggregateBucketValueTimeseries(
Box<crate::datadogV2::model::SpansAggregateBucketValueTimeseries>,
crate::datadogV2::model::SpansAggregateBucketValueTimeseries,
),
}
4 changes: 2 additions & 2 deletions src/datadogV2/model/model_spans_group_by_missing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SpansGroupByMissing {
SpansGroupByMissingString(Box<String>),
SpansGroupByMissingNumber(Box<f64>),
SpansGroupByMissingString(String),
SpansGroupByMissingNumber(f64),
}
6 changes: 3 additions & 3 deletions src/datadogV2/model/model_spans_group_by_total.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SpansGroupByTotal {
SpansGroupByTotalBoolean(Box<bool>),
SpansGroupByTotalString(Box<String>),
SpansGroupByTotalNumber(Box<f64>),
SpansGroupByTotalBoolean(bool),
SpansGroupByTotalString(String),
SpansGroupByTotalNumber(f64),
}
9 changes: 7 additions & 2 deletions tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d146e1f

Please sign in to comment.