Skip to content

Commit 4987536

Browse files
committed
Add request-making logic to rust template
1 parent a7c612f commit 4987536

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed

templates/svix_lib_resource.rs.jinja

+30-20
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
#![allow(unused_imports)]
2-
31
{% set api_mod_name %}{{ resource.name | to_snake_case }}_api{% endset -%}
42
{% set resource_type_name = resource.name | to_upper_camel_case -%}
53

64
{% if resource.has_post_operation -%}
75
use super::PostOptions;
86
{% endif -%}
97
use crate::{
10-
apis::{{ api_mod_name }},
118
error::Result,
129
models::*,
1310
Configuration,
@@ -105,23 +102,36 @@ impl<'a> {{ resource_type_name }}<'a> {
105102
let PostOptions { idempotency_key } = options.unwrap_or_default();
106103
{% endif -%}
107104

108-
{% set weird_rust_generator_op_id = op.id | replace(".", "-period-") %}
109-
{% set fn_name = weird_rust_generator_op_id | to_snake_case %}
110-
{% set params_struct_name -%}
111-
{{ weird_rust_generator_op_id | to_upper_camel_case }}Params
112-
{%- endset -%}
113-
{{ api_mod_name }}::{{ fn_name }}(
114-
self.cfg,
115-
{{ api_mod_name }}::{{ params_struct_name }} {
116-
{% for p in op.path_params -%}{{ p }},{% endfor %}
117-
{% if op.request_body_schema_name is defined -%}
118-
{{ op.request_body_schema_name | to_snake_case -}},
119-
{% endif -%}
120-
{% for p in op.query_params %}{{ p.name }},{% endfor -%}
121-
{% if has_header_params %}idempotency_key,{% endif %}
122-
}
123-
)
124-
.await
105+
{# make the request #}
106+
crate::request::Request::new(http1::Method::{{ op.method | upper }}, "{{ op.path }}")
107+
108+
{% for p in op.path_params -%}
109+
.with_path_param("{{ p }}", {{ p }})
110+
{% endfor -%}
111+
112+
{% for p in op.query_params -%}
113+
{% if p.required -%}
114+
.with_query_param
115+
{%- else -%}
116+
.with_optional_query_param
117+
{%- endif -%}
118+
("{{ p.name }}", {{ p.name }})
119+
{% endfor -%}
120+
121+
{% if op.request_body_schema_name is defined -%}
122+
.with_body_param({{ op.request_body_schema_name | to_snake_case }})
123+
{% endif -%}
124+
125+
{% if has_header_params -%}
126+
.with_optional_header_param("idempotency-key", idempotency_key)
127+
{% endif -%}
128+
129+
{% if op.response_body_schema_name is undefined -%}
130+
.returns_nothing()
131+
{% endif -%}
132+
133+
.execute(self.cfg)
134+
.await
125135
}
126136
{% endfor %}
127137
}

0 commit comments

Comments
 (0)