@@ -3,18 +3,48 @@ use futures::executor::block_on;
33use serde_json::Value;
44use std::collections::HashMap;
55
6- use datadog_api_client::datadog::*;{#
6+ use datadog_api_client::datadog::*;
7+ {#
78{% for name, operations in apis["v1"].items() %}
89{%- set classname = "api_"+name%}
910use datadog_api_client::datadogV1::{{classname | snake_case}}::*;
1011{%- endfor %}
11- #} {% - for version , apis in all_apis .items () %}
12+ #}
13+ {% - for version , apis in all_apis .items () %}
1214{% - for name , operations in apis .items () %}
1315{% - set classname = "api_" +name %}
1416use datadog_api_client::datadog{{ version.upper() }}::api::{{classname | snake_case}}::*;
1517{% - endfor %}
1618{% - endfor %}
1719
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+
1848pub fn collect_function_calls(world: &mut DatadogWorld) {
1949{% - for _ , apis in all_apis .items () %}
2050{% - for _ , operations in apis .items () %}
@@ -26,26 +56,28 @@ pub fn collect_function_calls(world: &mut DatadogWorld) {
2656}
2757
2858{% - 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 %}
3061{% for _ , _ , operation in operations %}
3162{% - set operationParams = operation |parameters |list %}
3263fn 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");
3365 {% - if operationParams |length > 0 -%}
3466 let params = {{ operation['operationId'] }}Params {
3567 {% - for param in operationParams %}
3668 {{ param[0] }}: serde_json::from_value(_parameters.get("{{ param[0] }}").unwrap().clone()).unwrap(),
3769 {% - endfor %}
3870 };
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)) {
4072 {% - 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( )) {
4274 {% - endif %}
4375 Ok(response) => response,
4476 Err(error) => {
4577 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),
4981 Error::ResponseError(e) => world.response.code = e.status.as_u16(),
5082 };
5183 }
0 commit comments