Skip to content

Commit

Permalink
fix nullables being propagated incorrectly, api tag capitalization, a…
Browse files Browse the repository at this point in the history
…rbitrary json fields getting mixed up with additionalproperties, undo operation json strings being left unserialized
  • Loading branch information
nkzou committed Jan 8, 2024
1 parent 87bc94e commit c595600
Show file tree
Hide file tree
Showing 38 changed files with 3,281 additions and 654 deletions.
9 changes: 3 additions & 6 deletions .generator/src/generator/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,15 @@ def type_to_rust(schema, alternative_name=None, render_nullable=False, render_op
else:
type_ = "object"
warnings.warn(f"Unknown type for schema: {schema} ({name or alternative_name})")
return option_wrapper(f"serde_json::Value", render_option, render_nullable)

if type_ == "array":
if name and schema.get("x-generate-alias-as-model", False):
return name
if name or alternative_name:
alternative_name = (name or alternative_name) + "Item"
name = type_to_rust(schema["items"], alternative_name=alternative_name, render_nullable=render_nullable, render_option=False, version=version)
# handle nullable arrays
if formatter.simple_type(schema["items"]) and schema["items"].get("nullable"):
name = f"Option<{name}>"
if schema.get("nullable") and formatter.is_primitive(schema["items"]):
name = formatter.simple_type(schema["items"], render_nullable=render_nullable, render_option=False)
nullable_item = schema["items"].get("nullable")
name = type_to_rust(schema["items"], alternative_name=alternative_name, render_nullable=nullable_item, render_option=False, version=version)
return option_wrapper(f"Vec<{name}>", render_option, render_nullable)
elif type_ == "object":
name = "serde_json::Value"
Expand Down
2 changes: 1 addition & 1 deletion .generator/src/generator/templates/api.j2
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub enum {{operation.operationId}}Error {
}
{% endfor %}

{%- set structName = name|camel_case +"API" %}
{%- set structName = name.replace(" ", "")+"API" %}
#[derive(Debug, Clone)]
pub struct {{ structName }} {
config: configuration::Configuration,
Expand Down
13 changes: 9 additions & 4 deletions .generator/src/generator/templates/function_mappings.j2
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct ApiInstances {
{%- for version, apis in all_apis.items() %}
{%- for name, operations in apis.items() %}
{%- set fieldName = "api_"+name %}
{%- set structName = name|camel_case +"API" %}
{%- set structName = name.replace(" ", "")+"API" %}
pub {{version}}_{{fieldName | snake_case}}: Option<datadog{{ version.upper() }}::api::{{fieldName | snake_case}}::{{structName}}>,
{%- endfor %}
{%- endfor %}
Expand All @@ -23,8 +23,8 @@ pub fn initialize_api_instance(world: &mut DatadogWorld, api: String) {
match api.as_str() {
{%- for name, versions in get_apis_and_versions(all_apis) %}
{%- set fieldName = "api_"+name|snake_case %}
{%- set structName = name|camel_case +"API" %}
"{{name|camel_case}}" => {
{%- set structName = name.replace(" ", "")+"API" %}
"{{name.replace(" ", "")}}" => {
{%- for version in versions %}
if world.api_instances.{{version}}_{{fieldName}}.is_none() {
world.api_instances.{{version}}_{{fieldName}} = Some(datadog{{ version.upper() }}::api::{{fieldName}}::{{structName}}::with_config(world.config.clone()));
Expand Down Expand Up @@ -86,7 +86,12 @@ fn test_{{version}}_{{ operation['operationId'] | snake_case }}(world: &mut Data
Ok(response) => response,
Err(error) => {
return match error {
Error::ResponseError(e) => world.response.code = e.status.as_u16(),
Error::ResponseError(e) => {
world.response.code = e.status.as_u16();
if let Some(entity) = e.entity {
world.response.object = serde_json::to_value(entity).unwrap();
}
},
_ => panic!("error parsing response: {}", error),
};
}
Expand Down
6 changes: 3 additions & 3 deletions src/datadogV1/api/api_aws_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,19 +214,19 @@ pub enum UpdateAWSAccountError {
}

#[derive(Debug, Clone)]
pub struct AwsIntegrationAPI {
pub struct AWSIntegrationAPI {
config: configuration::Configuration,
}

impl Default for AwsIntegrationAPI {
impl Default for AWSIntegrationAPI {
fn default() -> Self {
Self {
config: configuration::Configuration::new(),
}
}
}

impl AwsIntegrationAPI {
impl AWSIntegrationAPI {
pub fn new() -> Self {
Self::default()
}
Expand Down
6 changes: 3 additions & 3 deletions src/datadogV1/api/api_aws_logs_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,19 @@ pub enum ListAWSLogsServicesError {
}

#[derive(Debug, Clone)]
pub struct AwsLogsIntegrationAPI {
pub struct AWSLogsIntegrationAPI {
config: configuration::Configuration,
}

impl Default for AwsLogsIntegrationAPI {
impl Default for AWSLogsIntegrationAPI {
fn default() -> Self {
Self {
config: configuration::Configuration::new(),
}
}
}

impl AwsLogsIntegrationAPI {
impl AWSLogsIntegrationAPI {
pub fn new() -> Self {
Self::default()
}
Expand Down
6 changes: 3 additions & 3 deletions src/datadogV1/api/api_gcp_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,19 @@ pub enum UpdateGCPIntegrationError {
}

#[derive(Debug, Clone)]
pub struct GcpIntegrationAPI {
pub struct GCPIntegrationAPI {
config: configuration::Configuration,
}

impl Default for GcpIntegrationAPI {
impl Default for GCPIntegrationAPI {
fn default() -> Self {
Self {
config: configuration::Configuration::new(),
}
}
}

impl GcpIntegrationAPI {
impl GCPIntegrationAPI {
pub fn new() -> Self {
Self::default()
}
Expand Down
6 changes: 3 additions & 3 deletions src/datadogV1/api/api_ip_ranges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ pub enum GetIPRangesError {
}

#[derive(Debug, Clone)]
pub struct IpRangesAPI {
pub struct IPRangesAPI {
config: configuration::Configuration,
}

impl Default for IpRangesAPI {
impl Default for IPRangesAPI {
fn default() -> Self {
Self {
config: configuration::Configuration::new(),
}
}
}

impl IpRangesAPI {
impl IPRangesAPI {
pub fn new() -> Self {
Self::default()
}
Expand Down
5 changes: 2 additions & 3 deletions src/datadogV1/model/model_dashboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,14 @@ pub struct Dashboard {
with = "::serde_with::rust::double_option"
)]
pub template_variable_presets:
Option<Option<Vec<Option<crate::datadogV1::model::DashboardTemplateVariablePreset>>>>,
Option<Option<Vec<crate::datadogV1::model::DashboardTemplateVariablePreset>>>,
/// List of template variables for this dashboard.
#[serde(
rename = "template_variables",
default,
with = "::serde_with::rust::double_option"
)]
pub template_variables:
Option<Option<Vec<Option<crate::datadogV1::model::DashboardTemplateVariable>>>>,
pub template_variables: Option<Option<Vec<crate::datadogV1::model::DashboardTemplateVariable>>>,
/// Title of the dashboard.
#[serde(rename = "title")]
pub title: String,
Expand Down
7 changes: 2 additions & 5 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<std::collections::HashMap<String, serde_json::Value>>>,
pub points: Vec<Vec<serde_json::Value>>,
/// A list of tags associated with the distribution point metric.
#[serde(rename = "tags")]
pub tags: Option<Vec<String>>,
Expand All @@ -26,10 +26,7 @@ pub struct DistributionPointsSeries {
}

impl DistributionPointsSeries {
pub fn new(
metric: String,
points: Vec<Vec<std::collections::HashMap<String, serde_json::Value>>>,
) -> DistributionPointsSeries {
pub fn new(metric: String, points: Vec<Vec<serde_json::Value>>) -> DistributionPointsSeries {
DistributionPointsSeries {
host: None,
metric,
Expand Down
10 changes: 5 additions & 5 deletions src/datadogV1/model/model_host_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use serde_with::skip_serializing_none;
pub struct HostMeta {
/// A list of Agent checks running on the host.
#[serde(rename = "agent_checks")]
pub agent_checks: Option<Vec<Vec<std::collections::HashMap<String, serde_json::Value>>>>,
pub agent_checks: Option<Vec<Vec<serde_json::Value>>>,
/// The Datadog Agent version.
#[serde(rename = "agent_version")]
pub agent_version: Option<String>,
Expand All @@ -19,7 +19,7 @@ pub struct HostMeta {
pub cpu_cores: Option<i64>,
/// An array of Mac versions.
#[serde(rename = "fbsdV")]
pub fbsd_v: Option<Vec<std::collections::HashMap<String, serde_json::Value>>>,
pub fbsd_v: Option<Vec<serde_json::Value>>,
/// JSON string containing system information.
#[serde(rename = "gohai")]
pub gohai: Option<String>,
Expand All @@ -28,13 +28,13 @@ pub struct HostMeta {
pub install_method: Option<Box<crate::datadogV1::model::HostMetaInstallMethod>>,
/// An array of Mac versions.
#[serde(rename = "macV")]
pub mac_v: Option<Vec<std::collections::HashMap<String, serde_json::Value>>>,
pub mac_v: Option<Vec<serde_json::Value>>,
/// The machine architecture.
#[serde(rename = "machine")]
pub machine: Option<String>,
/// Array of Unix versions.
#[serde(rename = "nixV")]
pub nix_v: Option<Vec<std::collections::HashMap<String, serde_json::Value>>>,
pub nix_v: Option<Vec<serde_json::Value>>,
/// The OS platform.
#[serde(rename = "platform")]
pub platform: Option<String>,
Expand All @@ -52,7 +52,7 @@ pub struct HostMeta {
pub socket_hostname: Option<String>,
/// An array of Windows versions.
#[serde(rename = "winV")]
pub win_v: Option<Vec<std::collections::HashMap<String, serde_json::Value>>>,
pub win_v: Option<Vec<serde_json::Value>>,
}

impl HostMeta {
Expand Down
2 changes: 1 addition & 1 deletion src/datadogV1/model/model_metrics_query_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub struct MetricsQueryMetadata {
/// The second element describes the "per unit" (for example, `second` in `bytes per second`).
/// If the second element is not present, the API returns null.
#[serde(rename = "unit")]
pub unit: Option<Vec<crate::datadogV1::model::MetricsQueryUnit>>,
pub unit: Option<Vec<Option<crate::datadogV1::model::MetricsQueryUnit>>>,
}

impl MetricsQueryMetadata {
Expand Down
3 changes: 1 addition & 2 deletions src/datadogV1/model/model_monitor_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ pub struct MonitorOptions {
default,
with = "::serde_with::rust::double_option"
)]
pub renotify_statuses:
Option<Option<Vec<Option<crate::datadogV1::model::MonitorRenotifyStatusType>>>>,
pub renotify_statuses: Option<Option<Vec<crate::datadogV1::model::MonitorRenotifyStatusType>>>,
/// A Boolean indicating whether this monitor needs a full window of data before it’s evaluated.
/// We highly recommend you set this to `false` for sparse metrics,
/// otherwise some evaluations are skipped. Default is false.
Expand Down
2 changes: 1 addition & 1 deletion src/datadogV1/model/model_monitor_search_count_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct MonitorSearchCountItem {
pub count: Option<i64>,
/// The facet value.
#[serde(rename = "name")]
pub name: Option<std::collections::HashMap<String, serde_json::Value>>,
pub name: Option<serde_json::Value>,
}

impl MonitorSearchCountItem {
Expand Down
2 changes: 1 addition & 1 deletion src/datadogV1/model/model_shared_dashboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub struct SharedDashboard {
with = "::serde_with::rust::double_option"
)]
pub selectable_template_vars:
Option<Option<Vec<Option<crate::datadogV1::model::SelectableTemplateVariableItems>>>>,
Option<Option<Vec<crate::datadogV1::model::SelectableTemplateVariableItems>>>,
/// List of email addresses that can receive an invitation to access to the shared dashboard.
#[serde(
rename = "share_list",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct SharedDashboardUpdateRequest {
with = "::serde_with::rust::double_option"
)]
pub selectable_template_vars:
Option<Option<Vec<Option<crate::datadogV1::model::SelectableTemplateVariableItems>>>>,
Option<Option<Vec<crate::datadogV1::model::SelectableTemplateVariableItems>>>,
/// List of email addresses that can be given access to the shared dashboard.
#[serde(
rename = "share_list",
Expand Down
2 changes: 1 addition & 1 deletion src/datadogV1/model/model_slo_history_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct SLOHistoryResponse {
pub data: Option<Box<crate::datadogV1::model::SLOHistoryResponseData>>,
/// A list of errors while querying the history data for the service level objective.
#[serde(rename = "errors", default, with = "::serde_with::rust::double_option")]
pub errors: Option<Option<Vec<Option<crate::datadogV1::model::SLOHistoryResponseError>>>>,
pub errors: Option<Option<Vec<crate::datadogV1::model::SLOHistoryResponseError>>>,
}

impl SLOHistoryResponse {
Expand Down
4 changes: 1 addition & 3 deletions src/datadogV1/model/model_synthetics_api_test_result_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ pub struct SyntheticsAPITestResultData {
pub response_body: Option<String>,
/// Response headers returned for the API test.
#[serde(rename = "responseHeaders")]
pub response_headers: Option<
std::collections::HashMap<String, std::collections::HashMap<String, serde_json::Value>>,
>,
pub response_headers: Option<std::collections::HashMap<String, serde_json::Value>>,
/// Global size in byte of the API test response.
#[serde(rename = "responseSize")]
pub response_size: Option<i64>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct SyntheticsAssertionJSONPathTargetTarget {
pub operator: Option<String>,
/// The path target value to compare to.
#[serde(rename = "targetValue")]
pub target_value: Option<std::collections::HashMap<String, serde_json::Value>>,
pub target_value: Option<serde_json::Value>,
}

impl SyntheticsAssertionJSONPathTargetTarget {
Expand Down
4 changes: 2 additions & 2 deletions src/datadogV1/model/model_synthetics_assertion_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct SyntheticsAssertionTarget {
pub property: Option<String>,
/// Value used by the operator.
#[serde(rename = "target")]
pub target: std::collections::HashMap<String, serde_json::Value>,
pub target: serde_json::Value,
/// Timings scope for response time assertions.
#[serde(rename = "timingsScope")]
pub timings_scope: Option<crate::datadogV1::model::SyntheticsAssertionTimingsScope>,
Expand All @@ -28,7 +28,7 @@ pub struct SyntheticsAssertionTarget {
impl SyntheticsAssertionTarget {
pub fn new(
operator: crate::datadogV1::model::SyntheticsAssertionOperator,
target: std::collections::HashMap<String, serde_json::Value>,
target: serde_json::Value,
type_: crate::datadogV1::model::SyntheticsAssertionType,
) -> SyntheticsAssertionTarget {
SyntheticsAssertionTarget {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct SyntheticsAssertionXPathTargetTarget {
pub operator: Option<String>,
/// The path target value to compare to.
#[serde(rename = "targetValue")]
pub target_value: Option<std::collections::HashMap<String, serde_json::Value>>,
pub target_value: Option<serde_json::Value>,
/// The X path to assert.
#[serde(rename = "xPath")]
pub x_path: Option<String>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct SyntheticsPatchTestOperation {
pub path: Option<String>,
/// A value to use in a [JSON Patch](https://jsonpatch.com) operation
#[serde(rename = "value")]
pub value: Option<std::collections::HashMap<String, serde_json::Value>>,
pub value: Option<serde_json::Value>,
}

impl SyntheticsPatchTestOperation {
Expand Down
2 changes: 1 addition & 1 deletion src/datadogV1/model/model_synthetics_step_detail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub struct SyntheticsStepDetail {
pub url: Option<String>,
/// Value for the step.
#[serde(rename = "value")]
pub value: Option<std::collections::HashMap<String, serde_json::Value>>,
pub value: Option<serde_json::Value>,
/// Array of Core Web Vitals metrics for the step.
#[serde(rename = "vitalsMetrics")]
pub vitals_metrics: Option<Vec<crate::datadogV1::model::SyntheticsCoreWebVitals>>,
Expand Down
6 changes: 3 additions & 3 deletions src/datadogV2/api/api_apm_retention_filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,19 @@ pub enum UpdateApmRetentionFilterError {
}

#[derive(Debug, Clone)]
pub struct ApmRetentionFiltersAPI {
pub struct APMRetentionFiltersAPI {
config: configuration::Configuration,
}

impl Default for ApmRetentionFiltersAPI {
impl Default for APMRetentionFiltersAPI {
fn default() -> Self {
Self {
config: configuration::Configuration::new(),
}
}
}

impl ApmRetentionFiltersAPI {
impl APMRetentionFiltersAPI {
pub fn new() -> Self {
Self::default()
}
Expand Down
Loading

0 comments on commit c595600

Please sign in to comment.