@@ -3,18 +3,48 @@ use futures::executor::block_on;
3
3
use serde_json::Value;
4
4
use std::collections::HashMap;
5
5
6
- use datadog_api_client::datadog::*;{#
6
+ use datadog_api_client::datadog::*;
7
+ {#
7
8
{% for name, operations in apis["v1"].items() %}
8
9
{%- set classname = "api_"+name%}
9
10
use datadog_api_client::datadogV1::{{classname | snake_case}}::*;
10
11
{%- endfor %}
11
- #} {% - for version , apis in all_apis .items () %}
12
+ #}
13
+ {% - for version , apis in all_apis .items () %}
12
14
{% - for name , operations in apis .items () %}
13
15
{% - set classname = "api_" +name %}
14
16
use datadog_api_client::datadog{{ version.upper() }}::api::{{classname | snake_case}}::*;
15
17
{% - endfor %}
16
18
{% - endfor %}
17
19
20
+ #[derive(Debug, Default)]
21
+ pub struct ApiInstances {
22
+ {% - for version , apis in all_apis .items () %}
23
+ {% - for name , operations in apis .items () %}
24
+ {% - set fieldName = "api_" +name %}
25
+ {% - set structName = name |camel_case +"API" %}
26
+ pub {{fieldName | snake_case}}: Option<{{structName}}>,
27
+ {% - endfor %}
28
+ {% - endfor %}
29
+ }
30
+
31
+ pub fn initialize_api_instance(world: &mut DatadogWorld, api: String) {
32
+ match api.as_str() {
33
+ {% - for version , apis in all_apis .items () %}
34
+ {% - for name , operations in apis .items () %}
35
+ {% - set fieldName = "api_" +name %}
36
+ {% - set structName = name |camel_case +"API" %}
37
+ "{{name|camel_case}}" => {
38
+ if world.api_instances.api_fastly_integration.is_none() {
39
+ world.api_instances.{{fieldName | snake_case}} = Some({{structName}}::with_config(world.config.clone()));
40
+ }
41
+ },
42
+ {% - endfor %}
43
+ {% - endfor %}
44
+ _ => panic!("{api} API instance not found"),
45
+ }
46
+ }
47
+
18
48
pub fn collect_function_calls(world: &mut DatadogWorld) {
19
49
{% - for _ , apis in all_apis .items () %}
20
50
{% - for _ , operations in apis .items () %}
@@ -26,26 +56,28 @@ pub fn collect_function_calls(world: &mut DatadogWorld) {
26
56
}
27
57
28
58
{% - for _ , apis in all_apis .items () %}
29
- {% - for _ , operations in apis .items () %}
59
+ {% - for name , operations in apis .items () %}
60
+ {% - set apiName = "api_" +name | snake_case %}
30
61
{% for _ , _ , operation in operations %}
31
62
{% - set operationParams = operation |parameters |list %}
32
63
fn test_{{ operation['operationId'] | snake_case }}(world: &mut DatadogWorld, _parameters: &HashMap<String , Value >) {
64
+ let api = world.api_instances.{{ apiName }}.as_ref().expect("api instance not found");
33
65
{% - if operationParams |length > 0 -%}
34
66
let params = {{ operation['operationId'] }}Params {
35
67
{% - for param in operationParams %}
36
68
{{ param[0] }}: serde_json::from_value(_parameters.get("{{ param[0] }}").unwrap().clone()).unwrap(),
37
69
{% - endfor %}
38
70
};
39
- let response = match block_on({{ operation['operationId'] | snake_case}}(&world.config, params)) {
71
+ let response = match block_on(api. {{ operation['operationId'] | snake_case}}_with_http_info( params)) {
40
72
{% - else %}
41
- let response = match block_on({{ operation['operationId'] | snake_case}}(&world.config )) {
73
+ let response = match block_on(api. {{ operation['operationId'] | snake_case}}_with_http_info( )) {
42
74
{% - endif %}
43
75
Ok(response) => response,
44
76
Err(error) => {
45
77
return match error {
46
- Error::Reqwest(e) => panic!("reqwest error: {}", e.to_string() ),
47
- Error::Serde(e) => panic!("serde error: {}", e.to_string() ),
48
- Error::Io(e) => panic!("io error: {}", e.to_string() ),
78
+ Error::Reqwest(e) => panic!("reqwest error: {}", e),
79
+ Error::Serde(e) => panic!("serde error: {}", e),
80
+ Error::Io(e) => panic!("io error: {}", e),
49
81
Error::ResponseError(e) => world.response.code = e.status.as_u16(),
50
82
};
51
83
}
0 commit comments