Skip to content

Commit 2c12a0a

Browse files
authored
Bugfixes based on BDD testing (#7)
1 parent 1689f47 commit 2c12a0a

File tree

1,025 files changed

+8465
-992
lines changed

Some content is hidden

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

1,025 files changed

+8465
-992
lines changed

Diff for: .generator/src/generator/openapi.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -59,27 +59,26 @@ def type_to_rust(schema, alternative_name=None, render_nullable=False, render_op
5959
type_ = "array"
6060
elif "properties" in schema:
6161
type_ = "object"
62+
elif "oneOf" in schema:
63+
return alternative_name
6264
else:
6365
type_ = "object"
6466
warnings.warn(f"Unknown type for schema: {schema} ({name or alternative_name})")
67+
return option_wrapper(f"serde_json::Value", render_option, render_nullable)
6568

6669
if type_ == "array":
6770
if name and schema.get("x-generate-alias-as-model", False):
6871
return name
6972
if name or alternative_name:
7073
alternative_name = (name or alternative_name) + "Item"
71-
name = type_to_rust(schema["items"], alternative_name=alternative_name, render_nullable=render_nullable, render_option=False, version=version)
72-
# handle nullable arrays
73-
if formatter.simple_type(schema["items"]) and schema["items"].get("nullable"):
74-
name = f"Option<{name}>"
75-
if schema.get("nullable") and formatter.is_primitive(schema["items"]):
76-
name = formatter.simple_type(schema["items"], render_nullable=render_nullable, render_option=False)
74+
nullable_item = schema["items"].get("nullable")
75+
name = type_to_rust(schema["items"], alternative_name=alternative_name, render_nullable=nullable_item, render_option=False, version=version)
7776
return option_wrapper(f"Vec<{name}>", render_option, render_nullable)
7877
elif type_ == "object":
7978
name = "serde_json::Value"
8079
if "additionalProperties" in schema:
8180
name = type_to_rust(schema["additionalProperties"], render_nullable=render_nullable, render_option=False, version=version)
82-
return option_wrapper(f"std::collections::HashMap<String, {name}>", render_option, render_nullable)
81+
return option_wrapper(f"std::collections::BTreeMap<String, {name}>", render_option, render_nullable)
8382

8483
raise ValueError(f"Unknown type {type_}")
8584

Diff for: .generator/src/generator/templates/api.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub enum {{operation.operationId}}Error {
4848
}
4949
{% endfor %}
5050

51-
{%- set structName = name|camel_case +"API" %}
51+
{%- set structName = name.replace(" ", "")+"API" %}
5252
#[derive(Debug, Clone)]
5353
pub struct {{ structName }} {
5454
config: configuration::Configuration,

Diff for: .generator/src/generator/templates/configuration.j2

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{% include "partial_header.j2" %}
2-
use rustc_version::{version, Version};
32
use std::env;
43

54
#[derive(Debug, Clone)]
@@ -34,8 +33,8 @@ impl Default for Configuration {
3433
base_path: "https://api.datadoghq.com".to_owned(),
3534
user_agent: Some(format!(
3635
"datadog-api-client-rust/{} (rust {}; os {}; arch {})",
37-
env::var("CARGO_PKG_VERSION").unwrap_or("?".to_owned()),
38-
version().unwrap_or(Version::new(0, 0, 0)),
36+
option_env!("CARGO_PKG_VERSION").unwrap_or("?"),
37+
option_env!("DD_RUSTC_VERSION").unwrap_or("?"),
3938
env::consts::OS,
4039
env::consts::ARCH,
4140
)),

Diff for: .generator/src/generator/templates/function_mappings.j2

+9-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub struct ApiInstances {
1313
{%- for version, apis in all_apis.items() %}
1414
{%- for name, operations in apis.items() %}
1515
{%- set fieldName = "api_"+name %}
16-
{%- set structName = name|camel_case +"API" %}
16+
{%- set structName = name.replace(" ", "")+"API" %}
1717
pub {{version}}_{{fieldName | snake_case}}: Option<datadog{{ version.upper() }}::api::{{fieldName | snake_case}}::{{structName}}>,
1818
{%- endfor %}
1919
{%- endfor %}
@@ -23,8 +23,8 @@ pub fn initialize_api_instance(world: &mut DatadogWorld, api: String) {
2323
match api.as_str() {
2424
{%- for name, versions in get_apis_and_versions(all_apis) %}
2525
{%- set fieldName = "api_"+name|snake_case %}
26-
{%- set structName = name|camel_case +"API" %}
27-
"{{name|camel_case}}" => {
26+
{%- set structName = name.replace(" ", "")+"API" %}
27+
"{{name.replace(" ", "")}}" => {
2828
{%- for version in versions %}
2929
if world.api_instances.{{version}}_{{fieldName}}.is_none() {
3030
world.api_instances.{{version}}_{{fieldName}} = Some(datadog{{ version.upper() }}::api::{{fieldName}}::{{structName}}::with_config(world.config.clone()));
@@ -86,7 +86,12 @@ fn test_{{version}}_{{ operation['operationId'] | snake_case }}(world: &mut Data
8686
Ok(response) => response,
8787
Err(error) => {
8888
return match error {
89-
Error::ResponseError(e) => world.response.code = e.status.as_u16(),
89+
Error::ResponseError(e) => {
90+
world.response.code = e.status.as_u16();
91+
if let Some(entity) = e.entity {
92+
world.response.object = serde_json::to_value(entity).unwrap();
93+
}
94+
},
9095
_ => panic!("error parsing response: {}", error),
9196
};
9297
}

Diff for: .generator/src/generator/templates/model_oneof.j2

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ pub enum {{name}} {
77
{%- for oneOf in model.oneOf %}
88
{%- set dataType = get_type(oneOf, render_nullable=False, render_option=False, version=version) %}
99
{%- set attributeName = (get_name(oneOf) or dataType)|upperfirst %}
10+
{%- if oneOf | is_primitive or oneOf.type == "array" %}
11+
{{attributeName}}({{dataType}}),
12+
{%- else %}
1013
{{attributeName}}(Box<{{dataType}}>),
14+
{%- endif %}
1115
{%- endfor%}
1216
}

Diff for: .generator/src/generator/templates/model_simple.j2

+10-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub struct {{ name }} {
2020
{%- if model.additionalProperties is defined and model.additionalProperties != False %}
2121
{%- set dataType = get_type(model.additionalProperties, alternative_name=None, render_nullable=False, render_option=False, render_box=True, version=version) %}
2222
#[serde(flatten)]
23-
pub additional_properties: std::collections::HashMap<String, {{ dataType }}>,
23+
pub additional_properties: std::collections::BTreeMap<String, {{ dataType }}>,
2424
{%- endif %}
2525
}
2626

@@ -42,8 +42,16 @@ impl {{ name }} {
4242
{%- endif %}
4343
{%- endfor %}
4444
{%- if model.additionalProperties is defined and model.additionalProperties != False %}
45-
additional_properties: std::collections::HashMap::new(),
45+
additional_properties: std::collections::BTreeMap::new(),
4646
{%- endif %}
4747
}
4848
}
4949
}
50+
51+
{%- if not model.required %}
52+
impl Default for {{ name }} {
53+
fn default() -> Self {
54+
Self::new()
55+
}
56+
}
57+
{%- endif %}

Diff for: Cargo.toml

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,28 @@ edition = "2021"
1010
log = "0.4.20"
1111
reqwest = { version = "^0.11", features = ["multipart"] }
1212
reqwest-middleware = "0.1.6"
13-
rustc_version = "0.4.0"
1413
serde = "^1.0"
1514
serde_derive = "^1.0"
1615
serde_json = "^1.0"
1716
serde_repr = "0.1.17"
1817
serde_with = "^2.0"
1918
url = "^2.2"
2019

20+
[build-dependencies]
21+
rustc_version = "0.4.0"
22+
2123
[dev-dependencies]
2224
chrono = "0.4.31"
2325
cucumber = "0.20.2"
2426
env_logger = "0.10.0"
2527
futures = "0.3.28"
26-
handlebars = "4.4.0"
2728
regex = "1.9.5"
2829
rvcr = { git = "https://github.com/nkzou/rvcr.git", rev = "b8f84bc0dfacd539fdc6f7446637c6276dcbb57c" }
2930
vcr-cassette = "^2.0"
3031
sha256 = "1.4.0"
3132
tokio = { version = "1.10", features = ["macros", "rt-multi-thread", "time"] }
3233
lazy_static = "1.4.0"
34+
minijinja = "1.0.10"
3335

3436
[[test]]
3537
harness = false # allows Cucumber to print output instead of libtest

Diff for: build.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use rustc_version::version;
2+
3+
fn main() {
4+
println!(
5+
"cargo:rustc-env=DD_RUSTC_VERSION={}",
6+
match version() {
7+
Ok(ver) => ver.to_string(),
8+
Err(_) => "0.0.0".to_owned(),
9+
}
10+
);
11+
println!("cargo:rerun-if-changed=src/");
12+
}

Diff for: src/datadog/configuration.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
22
// This product includes software developed at Datadog (https://www.datadoghq.com/).
33
// Copyright 2019-Present Datadog, Inc.
4-
use rustc_version::{version, Version};
54
use std::env;
65

76
#[derive(Debug, Clone)]
@@ -26,8 +25,8 @@ impl Default for Configuration {
2625
base_path: "https://api.datadoghq.com".to_owned(),
2726
user_agent: Some(format!(
2827
"datadog-api-client-rust/{} (rust {}; os {}; arch {})",
29-
env::var("CARGO_PKG_VERSION").unwrap_or("?".to_owned()),
30-
version().unwrap_or(Version::new(0, 0, 0)),
28+
option_env!("CARGO_PKG_VERSION").unwrap_or("?"),
29+
option_env!("DD_RUSTC_VERSION").unwrap_or("?"),
3130
env::consts::OS,
3231
env::consts::ARCH,
3332
)),

Diff for: src/datadogV1/api/api_aws_integration.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -214,19 +214,19 @@ pub enum UpdateAWSAccountError {
214214
}
215215

216216
#[derive(Debug, Clone)]
217-
pub struct AwsIntegrationAPI {
217+
pub struct AWSIntegrationAPI {
218218
config: configuration::Configuration,
219219
}
220220

221-
impl Default for AwsIntegrationAPI {
221+
impl Default for AWSIntegrationAPI {
222222
fn default() -> Self {
223223
Self {
224224
config: configuration::Configuration::new(),
225225
}
226226
}
227227
}
228228

229-
impl AwsIntegrationAPI {
229+
impl AWSIntegrationAPI {
230230
pub fn new() -> Self {
231231
Self::default()
232232
}
@@ -411,7 +411,7 @@ impl AwsIntegrationAPI {
411411
&self,
412412
params: CreateAWSTagFilterParams,
413413
) -> Result<
414-
Option<std::collections::HashMap<String, serde_json::Value>>,
414+
Option<std::collections::BTreeMap<String, serde_json::Value>>,
415415
Error<CreateAWSTagFilterError>,
416416
> {
417417
match self.create_aws_tag_filter_with_http_info(params).await {
@@ -425,7 +425,7 @@ impl AwsIntegrationAPI {
425425
&self,
426426
params: CreateAWSTagFilterParams,
427427
) -> Result<
428-
ResponseContent<std::collections::HashMap<String, serde_json::Value>>,
428+
ResponseContent<std::collections::BTreeMap<String, serde_json::Value>>,
429429
Error<CreateAWSTagFilterError>,
430430
> {
431431
let local_configuration = &self.config;
@@ -470,7 +470,7 @@ impl AwsIntegrationAPI {
470470
let local_content = local_resp.text().await?;
471471

472472
if !local_status.is_client_error() && !local_status.is_server_error() {
473-
let local_entity: Option<std::collections::HashMap<String, serde_json::Value>> =
473+
let local_entity: Option<std::collections::BTreeMap<String, serde_json::Value>> =
474474
serde_json::from_str(&local_content).ok();
475475
Ok(ResponseContent {
476476
status: local_status,
@@ -577,7 +577,7 @@ impl AwsIntegrationAPI {
577577
&self,
578578
params: DeleteAWSAccountParams,
579579
) -> Result<
580-
Option<std::collections::HashMap<String, serde_json::Value>>,
580+
Option<std::collections::BTreeMap<String, serde_json::Value>>,
581581
Error<DeleteAWSAccountError>,
582582
> {
583583
match self.delete_aws_account_with_http_info(params).await {
@@ -591,7 +591,7 @@ impl AwsIntegrationAPI {
591591
&self,
592592
params: DeleteAWSAccountParams,
593593
) -> Result<
594-
ResponseContent<std::collections::HashMap<String, serde_json::Value>>,
594+
ResponseContent<std::collections::BTreeMap<String, serde_json::Value>>,
595595
Error<DeleteAWSAccountError>,
596596
> {
597597
let local_configuration = &self.config;
@@ -633,7 +633,7 @@ impl AwsIntegrationAPI {
633633
let local_content = local_resp.text().await?;
634634

635635
if !local_status.is_client_error() && !local_status.is_server_error() {
636-
let local_entity: Option<std::collections::HashMap<String, serde_json::Value>> =
636+
let local_entity: Option<std::collections::BTreeMap<String, serde_json::Value>> =
637637
serde_json::from_str(&local_content).ok();
638638
Ok(ResponseContent {
639639
status: local_status,
@@ -743,7 +743,7 @@ impl AwsIntegrationAPI {
743743
&self,
744744
params: DeleteAWSTagFilterParams,
745745
) -> Result<
746-
Option<std::collections::HashMap<String, serde_json::Value>>,
746+
Option<std::collections::BTreeMap<String, serde_json::Value>>,
747747
Error<DeleteAWSTagFilterError>,
748748
> {
749749
match self.delete_aws_tag_filter_with_http_info(params).await {
@@ -757,7 +757,7 @@ impl AwsIntegrationAPI {
757757
&self,
758758
params: DeleteAWSTagFilterParams,
759759
) -> Result<
760-
ResponseContent<std::collections::HashMap<String, serde_json::Value>>,
760+
ResponseContent<std::collections::BTreeMap<String, serde_json::Value>>,
761761
Error<DeleteAWSTagFilterError>,
762762
> {
763763
let local_configuration = &self.config;
@@ -802,7 +802,7 @@ impl AwsIntegrationAPI {
802802
let local_content = local_resp.text().await?;
803803

804804
if !local_status.is_client_error() && !local_status.is_server_error() {
805-
let local_entity: Option<std::collections::HashMap<String, serde_json::Value>> =
805+
let local_entity: Option<std::collections::BTreeMap<String, serde_json::Value>> =
806806
serde_json::from_str(&local_content).ok();
807807
Ok(ResponseContent {
808808
status: local_status,
@@ -1127,7 +1127,7 @@ impl AwsIntegrationAPI {
11271127
&self,
11281128
params: UpdateAWSAccountParams,
11291129
) -> Result<
1130-
Option<std::collections::HashMap<String, serde_json::Value>>,
1130+
Option<std::collections::BTreeMap<String, serde_json::Value>>,
11311131
Error<UpdateAWSAccountError>,
11321132
> {
11331133
match self.update_aws_account_with_http_info(params).await {
@@ -1141,7 +1141,7 @@ impl AwsIntegrationAPI {
11411141
&self,
11421142
params: UpdateAWSAccountParams,
11431143
) -> Result<
1144-
ResponseContent<std::collections::HashMap<String, serde_json::Value>>,
1144+
ResponseContent<std::collections::BTreeMap<String, serde_json::Value>>,
11451145
Error<UpdateAWSAccountError>,
11461146
> {
11471147
let local_configuration = &self.config;
@@ -1197,7 +1197,7 @@ impl AwsIntegrationAPI {
11971197
let local_content = local_resp.text().await?;
11981198

11991199
if !local_status.is_client_error() && !local_status.is_server_error() {
1200-
let local_entity: Option<std::collections::HashMap<String, serde_json::Value>> =
1200+
let local_entity: Option<std::collections::BTreeMap<String, serde_json::Value>> =
12011201
serde_json::from_str(&local_content).ok();
12021202
Ok(ResponseContent {
12031203
status: local_status,

0 commit comments

Comments
 (0)