Skip to content

Commit 49d755a

Browse files
committed
template cleanup and comments
1 parent b01eb17 commit 49d755a

Some content is hidden

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

49 files changed

+862
-888
lines changed

.generator/src/generator/templates/api.j2

Lines changed: 7 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl {{ structName }} {
9090
pub async fn {{operation.operationId | snake_case}}_with_http_info(&self{% for name, parameter in operation|parameters %}{% if loop.first %}, params: {{operation.operationId}}Params{% endif %}{% endfor %}) -> Result<ResponseContent<{% if returnType %}{{returnType}}{% else %}(){% endif %}>, Error<{{operation.operationId}}Error>> {
9191
let local_configuration = &self.config;
9292

93-
// unbox the parameters
93+
// unbox and build parameters
9494
{%- for name, parameter in operation|parameters %}
9595
let {{name|variable_name}} = params.{{name|variable_name}};
9696
{%- endfor %}
@@ -110,9 +110,6 @@ impl {{ structName }} {
110110
let mut local_req_builder = local_client.request(reqwest::Method::{{ httpMethod }}, local_uri_str.as_str());
111111

112112
{% for name, parameter in operation|parameters %}
113-
{%- if loop.first %}
114-
// build parameters
115-
{%- endif %}
116113
{%- set schema = parameter | parameter_schema %}
117114
{%- if parameter.in == "query" %}
118115
{%- if schema.type == "array" %}
@@ -142,80 +139,13 @@ impl {{ structName }} {
142139
{%- endif %}
143140
{%- endif %}
144141
{%- endfor %}
145-
{#
146-
{{#queryParams}}
147-
{{#required}}
148-
{{#isArray}}
149-
local_req_builder = match "{{collectionFormat}}" {
150-
"multi" => local_req_builder.query(&{{{paramName}}}.into_iter().map(|p| ("{{{baseName}}}".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
151-
_ => local_req_builder.query(&[("{{{baseName}}}", &{{{paramName}}}.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
152-
};
153-
{{/isArray}}
154-
{{^isArray}}
155-
{{^isNullable}}
156-
local_req_builder = local_req_builder.query(&[("{{{baseName}}}", &{{{paramName}}}.to_string())]);
157-
{{/isNullable}}
158-
{{#isNullable}}
159-
{{#isDeepObject}}
160-
if let Some(ref local_str) = {{{paramName}}} {
161-
let params = crate::apis::parse_deep_object("{{{baseName}}}", local_str);
162-
local_req_builder = local_req_builder.query(&params);
163-
};
164-
{{/isDeepObject}}
165-
{{^isDeepObject}}
166-
if let Some(ref local_str) = {{{paramName}}} {
167-
local_req_builder = local_req_builder.query(&[("{{{baseName}}}", &local_str.to_string())]);
168-
};
169-
{{/isDeepObject}}
170-
{{/isNullable}}
171-
{{/isArray}}
172-
{{/required}}
173-
{{^required}}
174-
if let Some(ref local_str) = {{{paramName}}} {
175-
{{#isArray}}
176-
local_req_builder = match "{{collectionFormat}}" {
177-
"multi" => local_req_builder.query(&local_str.into_iter().map(|p| ("{{{baseName}}}".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
178-
_ => local_req_builder.query(&[("{{{baseName}}}", &local_str.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string())]),
179-
};
180-
{{/isArray}}
181-
{{^isArray}}
182-
{{#isDeepObject}}
183-
let params = crate::apis::parse_deep_object("{{{baseName}}}", local_str);
184-
local_req_builder = local_req_builder.query(&params);
185-
{{/isDeepObject}}
186-
{{^isDeepObject}}
187-
local_req_builder = local_req_builder.query(&[("{{{baseName}}}", &local_str.to_string())]);
188-
{{/isDeepObject}}
189-
{{/isArray}}
190-
}
191-
{{/required}}
192-
{{/queryParams}}
193-
#}
142+
143+
// build user agent
194144
if let Some(ref local_user_agent) = local_configuration.user_agent {
195145
local_req_builder = local_req_builder.header(reqwest::header::USER_AGENT, local_user_agent.clone());
196146
}
197-
{#
198-
{{#hasHeaderParams}}
199-
{{#headerParams}}
200-
{{#required}}
201-
{{^isNullable}}
202-
local_req_builder = local_req_builder.header("{{{baseName}}}", {{{paramName}}}{{#isArray}}.join(","){{/isArray}}.to_string());
203-
{{/isNullable}}
204-
{{#isNullable}}
205-
match {{{paramName}}} {
206-
Some(local_param_value) => { local_req_builder = local_req_builder.header("{{{baseName}}}", local_param_value{{#isArray}}.join(","){{/isArray}}.to_string()); },
207-
None => { local_req_builder = local_req_builder.header("{{{baseName}}}", ""); },
208-
}
209-
{{/isNullable}}
210-
{{/required}}
211-
{{^required}}
212-
if let Some(local_param_value) = {{{paramName}}} {
213-
local_req_builder = local_req_builder.header("{{{baseName}}}", local_param_value{{#isArray}}.join(","){{/isArray}}.to_string());
214-
}
215-
{{/required}}
216-
{{/headerParams}}
217-
{{/hasHeaderParams}}
218-
#}
147+
148+
// build auth
219149
{%- set authMethods = operation.security if "security" in operation else openapi.security %}
220150
{%- if authMethods %}
221151
{%- for authMethod in authMethods %}
@@ -231,6 +161,7 @@ impl {{ structName }} {
231161
{%- endif %}
232162

233163
{% if formParameter %}
164+
// build form parameters
234165
{%- if formParameter.required %}
235166
let mut local_form = reqwest::multipart::Form::new();
236167
local_form = local_form.part("{{formParameter.name}}", reqwest::multipart::Part::bytes({{formParameter.name}}).file_name("{{formParameter.name}}"));
@@ -244,102 +175,9 @@ impl {{ structName }} {
244175
{%- endif %}
245176
{%- endif %}
246177

247-
{#
248-
{{#isMultipart}}
249-
{{#hasFormParams}}
250-
let mut local_form = reqwest::multipart::Form::new();
251-
{{#formParams}}
252-
{{#isFile}}
253-
{{^supportAsync}}
254-
{{#required}}
255-
{{^isNullable}}
256-
local_form = local_form.file("{{{baseName}}}", {{{paramName}}})?;
257-
{{/isNullable}}
258-
{{#isNullable}}
259-
match {{{paramName}}} {
260-
Some(local_param_value) => { local_form = local_form.file("{{{baseName}}}", local_param_value)?; },
261-
None => { unimplemented!("Required nullable form file param not supported"); },
262-
}
263-
{{/isNullable}}
264-
{{/required}}
265-
{{^required}}
266-
if let Some(local_param_value) = {{{paramName}}} {
267-
local_form = local_form.file("{{{baseName}}}", local_param_value)?;
268-
}
269-
{{/required}}
270-
// TODO: support file upload for '{{{baseName}}}' parameter
271-
272-
{{/isFile}}
273-
{{^isFile}}
274-
{{#required}}
275-
{{^isNullable}}
276-
local_form = local_form.text("{{{baseName}}}", {{{paramName}}}{{#isArray}}.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(","){{/isArray}}.to_string());
277-
{{/isNullable}}
278-
{{#isNullable}}
279-
match {{{paramName}}} {
280-
Some(local_param_value) => { local_form = local_form.text("{{{baseName}}}", local_param_value{{#isArray}}.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(","){{/isArray}}.to_string()); },
281-
None => { local_form = local_form.text("{{{baseName}}}", ""); },
282-
}
283-
{{/isNullable}}
284-
{{/required}}
285-
{{^required}}
286-
if let Some(local_param_value) = {{{paramName}}} {
287-
local_form = local_form.text("{{{baseName}}}", local_param_value{{#isArray}}.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(","){{/isArray}}.to_string());
288-
}
289-
{{/required}}
290-
{{/isFile}}
291-
{{/formParams}}
292-
local_req_builder = local_req_builder.multipart(local_form);
293-
{{/hasFormParams}}
294-
{{/isMultipart}}
295-
{{^isMultipart}}
296-
{{#hasFormParams}}
297-
let mut local_form_params = std::collections::HashMap::new();
298-
{{#formParams}}
299-
{{#isFile}}
300-
{{#required}}
301-
{{^isNullable}}
302-
local_form_params.insert("{{{baseName}}}", unimplemented!("File form param not supported with x-www-form-urlencoded content"));
303-
{{/isNullable}}
304-
{{#isNullable}}
305-
match {{{paramName}}} {
306-
Some(local_param_value) => { local_form_params.insert("{{{baseName}}}", unimplemented!("File form param not supported with x-www-form-urlencoded content")); },
307-
None => { unimplemented!("Required nullable file form param not supported with x-www-form-urlencoded content"); },
308-
}
309-
{{/isNullable}}
310-
{{/required}}
311-
{{^required}}
312-
if let Some(local_param_value) = {{{paramName}}} {
313-
local_form_params.insert("{{{baseName}}}", unimplemented!("File form param not supported with x-www-form-urlencoded content"));
314-
}
315-
{{/required}}
316-
{{/isFile}}
317-
{{^isFile}}
318-
{{#required}}
319-
{{^isNullable}}
320-
local_form_params.insert("{{{baseName}}}", {{{paramName}}}{{#isArray}}.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(","){{/isArray}}.to_string());
321-
{{/isNullable}}
322-
{{#isNullable}}
323-
match {{{paramName}}} {
324-
Some(local_param_value) => { local_form_params.insert("{{{baseName}}}", local_param_value{{#isArray}}.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(","){{/isArray}}.to_string()); },
325-
None => { local_form_params.insert("{{{baseName}}}", ""); },
326-
}
327-
{{/isNullable}}
328-
{{/required}}
329-
{{^required}}
330-
if let Some(local_param_value) = {{{paramName}}} {
331-
local_form_params.insert("{{{baseName}}}", local_param_value{{#isArray}}.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(","){{/isArray}}.to_string());
332-
}
333-
{{/required}}
334-
{{/isFile}}
335-
{{/formParams}}
336-
local_req_builder = local_req_builder.form(&local_form_params);
337-
{{/hasFormParams}}
338-
{{/isMultipart}}
339-
#}
340178
{%- if operation.requestBody is defined and not formParameter %}
341179
{%- set isBodyOptional = False if "required" in operation.requestBody and operation.requestBody.required else True %}
342-
// body params
180+
// build body parameters
343181
{%- if isBodyOptional %}
344182
if {{operation.get("x-codegen-request-body-name", "body")|variable_name}}.is_some() {
345183
local_req_builder = local_req_builder.json(&{{operation.get("x-codegen-request-body-name", "body")|variable_name}}.unwrap());

src/datadogV1/api/api_authentication.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,21 @@ impl AuthenticationAPI {
5858
> {
5959
let local_configuration = &self.config;
6060

61-
// unbox the parameters
61+
// unbox and build parameters
6262

6363
let local_client = &local_configuration.client;
6464

6565
let local_uri_str = format!("{}/api/v1/validate", local_configuration.base_path);
6666
let mut local_req_builder =
6767
local_client.request(reqwest::Method::GET, local_uri_str.as_str());
6868

69+
// build user agent
6970
if let Some(ref local_user_agent) = local_configuration.user_agent {
7071
local_req_builder =
7172
local_req_builder.header(reqwest::header::USER_AGENT, local_user_agent.clone());
7273
}
7374

75+
// build auth
7476
if let Some(ref local_apikey) = local_configuration.api_key_auth {
7577
local_req_builder = local_req_builder.header("DD-API-KEY", local_apikey);
7678
};

0 commit comments

Comments
 (0)