@@ -90,7 +90,7 @@ impl {{ structName }} {
90
90
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>> {
91
91
let local_configuration = &self.config;
92
92
93
- // unbox the parameters
93
+ // unbox and build parameters
94
94
{% - for name , parameter in operation |parameters %}
95
95
let {{name|variable_name}} = params.{{name|variable_name}};
96
96
{% - endfor %}
@@ -110,9 +110,6 @@ impl {{ structName }} {
110
110
let mut local_req_builder = local_client.request(reqwest::Method::{{ httpMethod }}, local_uri_str.as_str());
111
111
112
112
{% for name , parameter in operation |parameters %}
113
- {% - if loop .first %}
114
- // build parameters
115
- {% - endif %}
116
113
{% - set schema = parameter | parameter_schema %}
117
114
{% - if parameter .in == "query" %}
118
115
{% - if schema .type == "array" %}
@@ -142,80 +139,13 @@ impl {{ structName }} {
142
139
{% - endif %}
143
140
{% - endif %}
144
141
{% - 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(¶ms);
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(¶ms);
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
194
144
if let Some(ref local_user_agent) = local_configuration.user_agent {
195
145
local_req_builder = local_req_builder.header(reqwest::header::USER_AGENT, local_user_agent.clone());
196
146
}
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
219
149
{% - set authMethods = operation .security if "security" in operation else openapi .security %}
220
150
{% - if authMethods %}
221
151
{% - for authMethod in authMethods %}
@@ -231,6 +161,7 @@ impl {{ structName }} {
231
161
{% - endif %}
232
162
233
163
{% if formParameter %}
164
+ // build form parameters
234
165
{% - if formParameter .required %}
235
166
let mut local_form = reqwest::multipart::Form::new();
236
167
local_form = local_form.part("{{formParameter.name}}", reqwest::multipart::Part::bytes({{formParameter.name}}).file_name("{{formParameter.name}}"));
@@ -244,102 +175,9 @@ impl {{ structName }} {
244
175
{% - endif %}
245
176
{% - endif %}
246
177
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
- #}
340
178
{% - if operation .requestBody is defined and not formParameter %}
341
179
{% - set isBodyOptional = False if "required" in operation .requestBody and operation .requestBody .required else True %}
342
- // body params
180
+ // build body parameters
343
181
{% - if isBodyOptional %}
344
182
if {{operation.get("x-codegen-request-body-name", "body")|variable_name}}.is_some() {
345
183
local_req_builder = local_req_builder.json(& {{operation.get("x-codegen-request-body-name", "body")|variable_name}}.unwrap());
0 commit comments