Skip to content

Commit

Permalink
Merge branch 'master' into kevinzou/integration_test_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nkzou authored Feb 20, 2024
2 parents b33a677 + d126e3c commit 8a3d02b
Show file tree
Hide file tree
Showing 2,201 changed files with 4,866 additions and 3,600 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 @@ -19,6 +19,7 @@ use log::warn;
{%- 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
39 changes: 21 additions & 18 deletions .generator/src/generator/templates/configuration.j2
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct Configuration {
{%- endfor %}
{%- endfor %}
{%- endif %}

unstable_operations: HashMap<String, bool>,
}

impl Configuration {
Expand All @@ -29,33 +29,35 @@ impl Configuration {
}

pub fn set_unstable_operation_enabled(&mut self, operation: &str, enabled: bool) -> bool {
if let Some(unstable_operations) = &mut self.unstable_operations {
if unstable_operations.contains_key(operation) {
unstable_operations.insert(operation.to_string(), enabled);
return true;
}
if self.unstable_operations.contains_key(operation) {
self.unstable_operations.insert(operation.to_string(), enabled);
return true;
}

warn!("Operation {} is not an unstable operation, can't enable/disable", operation);
warn!(
"Operation {} is not an unstable operation, can't enable/disable",
operation
);

false
}

pub fn is_unstable_operation_enabled(&self, operation: &str) -> bool {
if let Some(unstable_operations) = &self.unstable_operations {
if unstable_operations.contains_key(operation) {
return unstable_operations.get(operation).unwrap().clone();
}
if self.unstable_operations.contains_key(operation) {
return self.unstable_operations.get(operation).unwrap().clone();
}

warn!("Operation {} is not an unstable operation, is always enabled", operation);
warn!(
"Operation {} is not an unstable operation, is always enabled",
operation
);

false
}

pub fn is_unstable_operation(&self, operation: &str) -> bool {
if let Some(unstable_operations) = &self.unstable_operations {
if unstable_operations.contains_key(operation) {
return true;
}
if self.unstable_operations.contains_key(operation) {
return true;
}

false
Expand All @@ -65,7 +67,7 @@ impl Configuration {
impl Default for Configuration {
fn default() -> Self {
let http_client = reqwest_middleware::ClientBuilder::new(reqwest::Client::new());
let unstable_operations = Some(HashMap::from([
let unstable_operations = HashMap::from([
{%- for version, api in apis.items() %}
{%- for operations in api.values() %}
{%- for _, _, operation in operations|sort(attribute="2.operationId") %}
Expand All @@ -75,7 +77,7 @@ impl Default for Configuration {
{%- endfor %}
{%- endfor %}
{%- endfor %}
]));
]);

Configuration {
base_path: "https://api.datadoghq.com".to_owned(),
Expand All @@ -99,6 +101,7 @@ impl Default for Configuration {
{%- endfor %}
{%- endfor %}
{%- endif %}
unstable_operations,
}
}
}
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 @@ -38,7 +38,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 @@ -61,25 +61,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
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
/target/
**/*.rs.bk
Cargo.lock
__pycache__
__pycache__

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
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
Loading

0 comments on commit 8a3d02b

Please sign in to comment.