Skip to content

Commit 0df0a96

Browse files
authored
End user usability refactors (#11)
1 parent b683eab commit 0df0a96

File tree

2,198 files changed

+4815
-3556
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,198 files changed

+4815
-3556
lines changed

.generator/src/generator/templates/api.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::datadog::*;
1414
{%- for name, parameter in optionalParams %}
1515
{%- if loop.first %}
1616
/// {{operation.operationId}}OptionalParams is a struct for passing parameters to the method [`{{ structName }}::{{operation.operationId | snake_case}}`]
17+
#[non_exhaustive]
1718
#[derive(Clone, Default, Debug)]
1819
pub struct {{operation.operationId}}OptionalParams {
1920
{%- endif %}

.generator/src/generator/templates/function_mappings.j2

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub fn collect_function_calls(world: &mut DatadogWorld) {
4040
{%- for version, apis in all_apis.items() %}
4141
{%- for _, operations in apis.items() %}
4242
{%- for _, _, operation in operations %}
43-
world.function_mappings.insert("{{version}}.{{ operation['operationId'] }}".to_string(), test_{{version}}_{{ operation['operationId'] | snake_case }});
43+
world.function_mappings.insert("{{version}}.{{ operation['operationId'] }}".into(), test_{{version}}_{{ operation['operationId'] | snake_case }});
4444
{%- endfor %}
4545
{%- endfor %}
4646
{%- endfor %}
@@ -63,25 +63,23 @@ fn test_{{version}}_{{ operation['operationId'] | snake_case }}(world: &mut Data
6363
let {{ parameter[0] | variable_name }} = serde_json::from_value(_parameters.get("{{ parameter[0] }}").unwrap().clone()).unwrap();
6464
{%- endif -%}
6565
{%- else %}
66-
let {{ parameter[0] | variable_name }} = if let Some(param) = _parameters.get("{{ parameter[0] }}") {
66+
let {{ parameter[0] | variable_name }} = _parameters.get("{{ parameter[0] }}").and_then(|param|
6767
{%- if schema | is_primitive and schema.get("format") == "binary" -%}
6868
Some(param.as_str().unwrap().as_bytes().to_vec())
6969
{%- else -%}
7070
Some(serde_json::from_value(param.clone()).unwrap())
7171
{%- endif -%}
72-
} else {
73-
None
74-
};
72+
);
7573
{%- endif %}
7674
{%- endfor %}
7775

7876
{%- for parameter in optionalParams %}
7977
{%- if loop.first %}
80-
let params = datadog{{ version.upper() }}::api::{{ apiName }}::{{ operation['operationId'] }}OptionalParams {
78+
let mut params = datadog{{ version.upper() }}::api::{{ apiName }}::{{ operation['operationId'] }}OptionalParams::default();
8179
{%- endif %}
82-
{{ parameter[0] | variable_name }},
80+
params.{{ parameter[0] | variable_name }} = {{ parameter[0] | variable_name }};
8381
{%- if loop.last %}
84-
};
82+
;
8583
{%- endif %}
8684
{%- endfor %}
8785
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 %})) {

.generator/src/generator/templates/lib.j2

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
#![allow(non_camel_case_types)]
33
#![allow(non_snake_case)]
44

5-
extern crate serde;
6-
extern crate serde_json;
7-
extern crate url;
8-
extern crate reqwest;
9-
105
pub mod datadog;
116
pub mod datadogV1;
127
pub mod datadogV2;

.generator/src/generator/templates/model.mustache

Lines changed: 0 additions & 118 deletions
This file was deleted.

.generator/src/generator/templates/model_enum.j2

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ use serde::{Serialize, Deserialize};
77
{{ description | block_comment }}
88
{%- endif %}
99

10+
#[non_exhaustive]
1011
{%- if model["type"] == "integer" %}
1112
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize_repr, Deserialize_repr)]
12-
#[repr({{model | simple_type(False, False)}})]
13+
#[repr({{model | simple_type(false, false)}})]
1314
{%- else %}
1415
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
1516
{%- endif %}

.generator/src/generator/templates/model_oneof.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use serde::{Deserialize, Serialize};
22

33
{{ model.description | block_comment }}
4+
#[non_exhaustive]
45
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
56
#[serde(untagged)]
67
pub enum {{name}} {

.generator/src/generator/templates/model_simple.j2

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ use serde::{Serialize, Deserialize};
22
use serde_with::skip_serializing_none;
33

44
{{ model.description | block_comment }}
5+
#[non_exhaustive]
56
#[skip_serializing_none]
67
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
78
pub struct {{ name }} {
89
{%- for attr, schema in model.get("properties", {}).items() %}
910
{%- set propertyName = attr|variable_name %}
1011
{%- set required = attr in model.required %}
11-
{%- set nullable = schema.get("nullable", False)%}
12+
{%- set nullable = schema.get("nullable", false)%}
1213
{%- set dataType = get_type(schema, alternative_name=name + propertyName, render_nullable=nullable, render_option=not required, render_box=false, version=version) %}
1314
{%- if schema.description is defined %}
1415
{{ schema.description | block_comment }}
@@ -19,37 +20,37 @@ pub struct {{ name }} {
1920
#[serde(rename = "{{ attr }}"{% if not required and nullable%}, default, with = "::serde_with::rust::double_option"{% endif %})]
2021
pub {{propertyName}}: {{dataType}},
2122
{%- endfor %}
22-
{%- if model.additionalProperties is defined and model.additionalProperties != False %}
23-
{%- set dataType = get_type(model.additionalProperties, alternative_name=None, render_nullable=False, render_option=False, render_box=false, version=version) %}
23+
{%- if model.additionalProperties is defined and model.additionalProperties != false %}
24+
{%- set dataType = get_type(model.additionalProperties, alternative_name=None, render_nullable=false, render_option=false, render_box=false, version=version) %}
2425
#[serde(flatten)]
2526
pub additional_properties: std::collections::BTreeMap<String, {{ dataType }}>,
2627
{%- endif %}
2728
}
2829

2930
impl {{ name }} {
30-
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 }} {
31+
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 }} {
3132
{%- if get_deprecated(model) %}
3233
#[allow(deprecated)]
3334
{%- endif %}
3435
{{ name }} {
3536
{%- for attr, schema in model.get("properties", {}).items() %}
3637
{%- set required = attr in model.required %}
37-
{%- set nullable = schema.get("nullable", False)%}
38+
{%- set nullable = schema.get("nullable", false)%}
3839
{%- set dataType = get_type(schema, alternative_name=name + attr|variable_name, render_nullable=nullable, render_option=not required, render_box=false, version=version) %}
3940
{%- if attr in model.get("required", []) %}
4041
{{ attr|variable_name }},
4142
{%- else %}
4243
{{ attr|variable_name }}: None,
4344
{%- endif %}
4445
{%- endfor %}
45-
{%- if model.additionalProperties is defined and model.additionalProperties != False %}
46+
{%- if model.additionalProperties is defined and model.additionalProperties != false %}
4647
additional_properties: std::collections::BTreeMap::new(),
4748
{%- endif %}
4849
}
4950
}
5051
{% for attr, schema in model.get("properties", {}).items() if attr not in model.required %}
51-
{%- set nullable = schema.get("nullable", False)%}
52-
{%- set dataType = get_type(schema, alternative_name=name + attr|variable_name, render_nullable=nullable, render_option=False, render_box=false, version=version) %}
52+
{%- set nullable = schema.get("nullable", false)%}
53+
{%- set dataType = get_type(schema, alternative_name=name + attr|variable_name, render_nullable=nullable, render_option=false, render_box=false, version=version) %}
5354
{%- if get_deprecated(model) %}
5455
#[allow(deprecated)]
5556
{%- endif %}

scripts/license-check.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
cargo install --quiet dd-rust-license-tool
2+
cargo fetch --target aarch64-apple-darwin
23
dd-rust-license-tool check
34
if [ $? -ne 0 ]; then
45
echo "Run 'dd-rust-license-tool write' to regenerate license csv file."

src/datadogV1/api/api_aws_integration.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use reqwest;
66
use serde::{Deserialize, Serialize};
77

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

3738
/// UpdateAWSAccountOptionalParams is a struct for passing parameters to the method [`AWSIntegrationAPI::update_aws_account`]
39+
#[non_exhaustive]
3840
#[derive(Clone, Default, Debug)]
3941
pub struct UpdateAWSAccountOptionalParams {
4042
/// Only return AWS accounts that matches this `account_id`.

src/datadogV1/api/api_dashboards.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use reqwest;
66
use serde::{Deserialize, Serialize};
77

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

3031
/// ListDashboardsOptionalParams is a struct for passing parameters to the method [`DashboardsAPI::list_dashboards`]
32+
#[non_exhaustive]
3133
#[derive(Clone, Default, Debug)]
3234
pub struct ListDashboardsOptionalParams {
3335
/// When `true`, this query only returns shared custom created

0 commit comments

Comments
 (0)