Skip to content

Commit

Permalink
End user usability refactors (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
nkzou authored Feb 14, 2024
1 parent b683eab commit 0df0a96
Show file tree
Hide file tree
Showing 2,198 changed files with 4,815 additions and 3,556 deletions.
1 change: 1 addition & 0 deletions .generator/src/generator/templates/api.j2
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::datadog::*;
{%- for name, parameter in optionalParams %}
{%- if loop.first %}
/// {{operation.operationId}}OptionalParams is a struct for passing parameters to the method [`{{ structName }}::{{operation.operationId | snake_case}}`]
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct {{operation.operationId}}OptionalParams {
{%- endif %}
Expand Down
14 changes: 6 additions & 8 deletions .generator/src/generator/templates/function_mappings.j2
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn collect_function_calls(world: &mut DatadogWorld) {
{%- for version, apis in all_apis.items() %}
{%- for _, operations in apis.items() %}
{%- for _, _, operation in operations %}
world.function_mappings.insert("{{version}}.{{ operation['operationId'] }}".to_string(), test_{{version}}_{{ operation['operationId'] | snake_case }});
world.function_mappings.insert("{{version}}.{{ operation['operationId'] }}".into(), test_{{version}}_{{ operation['operationId'] | snake_case }});
{%- endfor %}
{%- endfor %}
{%- endfor %}
Expand All @@ -63,25 +63,23 @@ fn test_{{version}}_{{ operation['operationId'] | snake_case }}(world: &mut Data
let {{ parameter[0] | variable_name }} = serde_json::from_value(_parameters.get("{{ parameter[0] }}").unwrap().clone()).unwrap();
{%- endif -%}
{%- else %}
let {{ parameter[0] | variable_name }} = if let Some(param) = _parameters.get("{{ parameter[0] }}") {
let {{ parameter[0] | variable_name }} = _parameters.get("{{ parameter[0] }}").and_then(|param|
{%- if schema | is_primitive and schema.get("format") == "binary" -%}
Some(param.as_str().unwrap().as_bytes().to_vec())
{%- else -%}
Some(serde_json::from_value(param.clone()).unwrap())
{%- endif -%}
} else {
None
};
);
{%- endif %}
{%- endfor %}

{%- for parameter in optionalParams %}
{%- if loop.first %}
let params = datadog{{ version.upper() }}::api::{{ apiName }}::{{ operation['operationId'] }}OptionalParams {
let mut params = datadog{{ version.upper() }}::api::{{ apiName }}::{{ operation['operationId'] }}OptionalParams::default();
{%- endif %}
{{ parameter[0] | variable_name }},
params.{{ parameter[0] | variable_name }} = {{ parameter[0] | variable_name }};
{%- if loop.last %}
};
;
{%- endif %}
{%- endfor %}
let response = match block_on(api.{{ operation['operationId'] | snake_case}}_with_http_info({% for name, parameter in requiredParams %}{{name|variable_name}}{% if loop.last %}{% if operation|has_optional_parameter %}, {% endif %}{% else %}, {% endif %}{% endfor %}{% if operation|has_optional_parameter %}params{% endif %})) {
Expand Down
5 changes: 0 additions & 5 deletions .generator/src/generator/templates/lib.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]

extern crate serde;
extern crate serde_json;
extern crate url;
extern crate reqwest;

pub mod datadog;
pub mod datadogV1;
pub mod datadogV2;
118 changes: 0 additions & 118 deletions .generator/src/generator/templates/model.mustache

This file was deleted.

3 changes: 2 additions & 1 deletion .generator/src/generator/templates/model_enum.j2
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ use serde::{Serialize, Deserialize};
{{ description | block_comment }}
{%- endif %}

#[non_exhaustive]
{%- if model["type"] == "integer" %}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize_repr, Deserialize_repr)]
#[repr({{model | simple_type(False, False)}})]
#[repr({{model | simple_type(false, false)}})]
{%- else %}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
{%- endif %}
Expand Down
1 change: 1 addition & 0 deletions .generator/src/generator/templates/model_oneof.j2
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};

{{ model.description | block_comment }}
#[non_exhaustive]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum {{name}} {
Expand Down
17 changes: 9 additions & 8 deletions .generator/src/generator/templates/model_simple.j2
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ use serde::{Serialize, Deserialize};
use serde_with::skip_serializing_none;

{{ model.description | block_comment }}
#[non_exhaustive]
#[skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct {{ name }} {
{%- for attr, schema in model.get("properties", {}).items() %}
{%- set propertyName = attr|variable_name %}
{%- set required = attr in model.required %}
{%- set nullable = schema.get("nullable", False)%}
{%- set nullable = schema.get("nullable", false)%}
{%- set dataType = get_type(schema, alternative_name=name + propertyName, render_nullable=nullable, render_option=not required, render_box=false, version=version) %}
{%- if schema.description is defined %}
{{ schema.description | block_comment }}
Expand All @@ -19,37 +20,37 @@ pub struct {{ name }} {
#[serde(rename = "{{ attr }}"{% if not required and nullable%}, default, with = "::serde_with::rust::double_option"{% endif %})]
pub {{propertyName}}: {{dataType}},
{%- endfor %}
{%- if model.additionalProperties is defined and model.additionalProperties != False %}
{%- set dataType = get_type(model.additionalProperties, alternative_name=None, render_nullable=False, render_option=False, render_box=false, version=version) %}
{%- if model.additionalProperties is defined and model.additionalProperties != false %}
{%- set dataType = get_type(model.additionalProperties, alternative_name=None, render_nullable=false, render_option=false, render_box=false, version=version) %}
#[serde(flatten)]
pub additional_properties: std::collections::BTreeMap<String, {{ dataType }}>,
{%- endif %}
}

impl {{ name }} {
pub fn new({% for attr, schema in model.get("properties", {}).items() if attr in model.required %}{%- set nullable = schema.get("nullable", False)%}{%- set dataType = get_type(schema, alternative_name=name + attr|variable_name, render_nullable=nullable, render_option=False, render_box=false, version=version) %}{{attr|variable_name}}: {{ dataType }}{%- if not loop.last %}, {% endif %}{% endfor %}) -> {{ name }} {
pub fn new({% for attr, schema in model.get("properties", {}).items() if attr in model.required %}{%- set nullable = schema.get("nullable", false)%}{%- set dataType = get_type(schema, alternative_name=name + attr|variable_name, render_nullable=nullable, render_option=false, render_box=false, version=version) %}{{attr|variable_name}}: {{ dataType }}{%- if not loop.last %}, {% endif %}{% endfor %}) -> {{ name }} {
{%- if get_deprecated(model) %}
#[allow(deprecated)]
{%- endif %}
{{ name }} {
{%- for attr, schema in model.get("properties", {}).items() %}
{%- set required = attr in model.required %}
{%- set nullable = schema.get("nullable", False)%}
{%- set nullable = schema.get("nullable", false)%}
{%- set dataType = get_type(schema, alternative_name=name + attr|variable_name, render_nullable=nullable, render_option=not required, render_box=false, version=version) %}
{%- if attr in model.get("required", []) %}
{{ attr|variable_name }},
{%- else %}
{{ attr|variable_name }}: None,
{%- endif %}
{%- endfor %}
{%- if model.additionalProperties is defined and model.additionalProperties != False %}
{%- if model.additionalProperties is defined and model.additionalProperties != false %}
additional_properties: std::collections::BTreeMap::new(),
{%- endif %}
}
}
{% for attr, schema in model.get("properties", {}).items() if attr not in model.required %}
{%- set nullable = schema.get("nullable", False)%}
{%- set dataType = get_type(schema, alternative_name=name + attr|variable_name, render_nullable=nullable, render_option=False, render_box=false, version=version) %}
{%- set nullable = schema.get("nullable", false)%}
{%- set dataType = get_type(schema, alternative_name=name + attr|variable_name, render_nullable=nullable, render_option=false, render_box=false, version=version) %}
{%- if get_deprecated(model) %}
#[allow(deprecated)]
{%- endif %}
Expand Down
1 change: 1 addition & 0 deletions scripts/license-check.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cargo install --quiet dd-rust-license-tool
cargo fetch --target aarch64-apple-darwin
dd-rust-license-tool check
if [ $? -ne 0 ]; then
echo "Run 'dd-rust-license-tool write' to regenerate license csv file."
Expand Down
2 changes: 2 additions & 0 deletions src/datadogV1/api/api_aws_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use reqwest;
use serde::{Deserialize, Serialize};

/// ListAWSAccountsOptionalParams is a struct for passing parameters to the method [`AWSIntegrationAPI::list_aws_accounts`]
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct ListAWSAccountsOptionalParams {
/// Only return AWS accounts that matches this `account_id`.
Expand Down Expand Up @@ -35,6 +36,7 @@ impl ListAWSAccountsOptionalParams {
}

/// UpdateAWSAccountOptionalParams is a struct for passing parameters to the method [`AWSIntegrationAPI::update_aws_account`]
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct UpdateAWSAccountOptionalParams {
/// Only return AWS accounts that matches this `account_id`.
Expand Down
2 changes: 2 additions & 0 deletions src/datadogV1/api/api_dashboards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use reqwest;
use serde::{Deserialize, Serialize};

/// GetPublicDashboardInvitationsOptionalParams is a struct for passing parameters to the method [`DashboardsAPI::get_public_dashboard_invitations`]
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct GetPublicDashboardInvitationsOptionalParams {
/// The number of records to return in a single request.
Expand All @@ -28,6 +29,7 @@ impl GetPublicDashboardInvitationsOptionalParams {
}

/// ListDashboardsOptionalParams is a struct for passing parameters to the method [`DashboardsAPI::list_dashboards`]
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct ListDashboardsOptionalParams {
/// When `true`, this query only returns shared custom created
Expand Down
1 change: 1 addition & 0 deletions src/datadogV1/api/api_downtimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use reqwest;
use serde::{Deserialize, Serialize};

/// ListDowntimesOptionalParams is a struct for passing parameters to the method [`DowntimesAPI::list_downtimes`]
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct ListDowntimesOptionalParams {
/// Only return downtimes that are active when the request is made.
Expand Down
1 change: 1 addition & 0 deletions src/datadogV1/api/api_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use reqwest;
use serde::{Deserialize, Serialize};

/// ListEventsOptionalParams is a struct for passing parameters to the method [`EventsAPI::list_events`]
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct ListEventsOptionalParams {
/// Priority of your events, either `low` or `normal`.
Expand Down
2 changes: 2 additions & 0 deletions src/datadogV1/api/api_hosts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use reqwest;
use serde::{Deserialize, Serialize};

/// GetHostTotalsOptionalParams is a struct for passing parameters to the method [`HostsAPI::get_host_totals`]
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct GetHostTotalsOptionalParams {
/// Number of seconds from which you want to get total number of active hosts.
Expand All @@ -21,6 +22,7 @@ impl GetHostTotalsOptionalParams {
}

/// ListHostsOptionalParams is a struct for passing parameters to the method [`HostsAPI::list_hosts`]
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct ListHostsOptionalParams {
/// String to filter search results.
Expand Down
1 change: 1 addition & 0 deletions src/datadogV1/api/api_logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use reqwest;
use serde::{Deserialize, Serialize};

/// SubmitLogOptionalParams is a struct for passing parameters to the method [`LogsAPI::submit_log`]
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct SubmitLogOptionalParams {
/// HTTP header used to compress the media-type.
Expand Down
3 changes: 3 additions & 0 deletions src/datadogV1/api/api_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use reqwest;
use serde::{Deserialize, Serialize};

/// ListActiveMetricsOptionalParams is a struct for passing parameters to the method [`MetricsAPI::list_active_metrics`]
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct ListActiveMetricsOptionalParams {
/// Hostname for filtering the list of metrics returned.
Expand All @@ -32,6 +33,7 @@ impl ListActiveMetricsOptionalParams {
}

/// SubmitDistributionPointsOptionalParams is a struct for passing parameters to the method [`MetricsAPI::submit_distribution_points`]
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct SubmitDistributionPointsOptionalParams {
/// HTTP header used to compress the media-type.
Expand All @@ -50,6 +52,7 @@ impl SubmitDistributionPointsOptionalParams {
}

/// SubmitMetricsOptionalParams is a struct for passing parameters to the method [`MetricsAPI::submit_metrics`]
#[non_exhaustive]
#[derive(Clone, Default, Debug)]
pub struct SubmitMetricsOptionalParams {
/// HTTP header used to compress the media-type.
Expand Down
Loading

0 comments on commit 0df0a96

Please sign in to comment.