Skip to content

Commit 34bd021

Browse files
authored
[rust][reqwest] support binary type for download (#20031)
* [rust][reqwest] support binary type for upload and download * [rust][reqwest] support binary download in supportMultipleResponses contexts * [rust][reqwest] support binary responses that don't have any return type
1 parent 326f100 commit 34bd021

File tree

45 files changed

+339
-198
lines changed

Some content is hidden

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

45 files changed

+339
-198
lines changed

modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache

+20-3
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub enum {{{operationIdCamelCase}}}Error {
8080
/// {{{.}}}
8181
{{/notes}}
8282
{{#vendorExtensions.x-group-parameters}}
83-
pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration: &configuration::Configuration{{#allParams}}{{#-first}}, params: {{{operationIdCamelCase}}}Params{{/-first}}{{/allParams}}) -> Result<{{#supportMultipleResponses}}ResponseContent<{{{operationIdCamelCase}}}Success>{{/supportMultipleResponses}}{{^supportMultipleResponses}}{{^returnType}}(){{/returnType}}{{{returnType}}}{{/supportMultipleResponses}}, Error<{{{operationIdCamelCase}}}Error>> {
83+
pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration: &configuration::Configuration{{#allParams}}{{#-first}}, params: {{{operationIdCamelCase}}}Params{{/-first}}{{/allParams}}) -> Result<{{#isResponseFile}}{{#supportAsync}}reqwest::Response{{/supportAsync}}{{^supportAsync}}reqwest::blocking::Response{{/supportAsync}}{{/isResponseFile}}{{^isResponseFile}}{{#supportMultipleResponses}}ResponseContent<{{{operationIdCamelCase}}}Success>{{/supportMultipleResponses}}{{^supportMultipleResponses}}{{^returnType}}(){{/returnType}}{{{returnType}}}{{/supportMultipleResponses}}{{/isResponseFile}}, Error<{{{operationIdCamelCase}}}Error>> {
8484
let local_var_configuration = configuration;
8585
8686
// unbox the parameters
@@ -90,7 +90,7 @@ pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration:
9090

9191
{{/vendorExtensions.x-group-parameters}}
9292
{{^vendorExtensions.x-group-parameters}}
93-
pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration: &configuration::Configuration, {{#allParams}}{{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isString}}{{#isArray}}Vec<{{/isArray}}{{^isUuid}}&str{{/isUuid}}{{#isArray}}>{{/isArray}}{{/isString}}{{#isUuid}}{{#isArray}}Vec<{{/isArray}}&str{{#isArray}}>{{/isArray}}{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}) -> Result<{{#supportMultipleResponses}}ResponseContent<{{{operationIdCamelCase}}}Success>{{/supportMultipleResponses}}{{^supportMultipleResponses}}{{^returnType}}(){{/returnType}}{{{returnType}}}{{/supportMultipleResponses}}, Error<{{{operationIdCamelCase}}}Error>> {
93+
pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration: &configuration::Configuration, {{#allParams}}{{{paramName}}}: {{^required}}Option<{{/required}}{{#required}}{{#isNullable}}Option<{{/isNullable}}{{/required}}{{#isString}}{{#isArray}}Vec<{{/isArray}}{{^isUuid}}&str{{/isUuid}}{{#isArray}}>{{/isArray}}{{/isString}}{{#isUuid}}{{#isArray}}Vec<{{/isArray}}&str{{#isArray}}>{{/isArray}}{{/isUuid}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}models::{{/isContainer}}{{/isPrimitiveType}}{{{dataType}}}{{/isUuid}}{{/isString}}{{^required}}>{{/required}}{{#required}}{{#isNullable}}>{{/isNullable}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}) -> Result<{{#isResponseFile}}{{#supportAsync}}reqwest::Response{{/supportAsync}}{{^supportAsync}}reqwest::blocking::Response{{/supportAsync}}{{/isResponseFile}}{{^isResponseFile}}{{#supportMultipleResponses}}ResponseContent<{{{operationIdCamelCase}}}Success>{{/supportMultipleResponses}}{{^supportMultipleResponses}}{{^returnType}}(){{/returnType}}{{{returnType}}}{{/supportMultipleResponses}}{{/isResponseFile}}, Error<{{{operationIdCamelCase}}}Error>> {
9494
let local_var_configuration = configuration;
9595
{{/vendorExtensions.x-group-parameters}}
9696

@@ -346,31 +346,48 @@ pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration:
346346
{{/isMultipart}}
347347
{{#hasBodyParam}}
348348
{{#bodyParams}}
349+
{{#isFile}}
350+
local_var_req_builder = local_var_req_builder.body({{{paramName}}});
351+
{{/isFile}}
352+
{{^isFile}}
349353
local_var_req_builder = local_var_req_builder.json(&{{{paramName}}});
354+
{{/isFile}}
350355
{{/bodyParams}}
351356
{{/hasBodyParam}}
352357

353358
let local_var_req = local_var_req_builder.build()?;
354359
let local_var_resp = local_var_client.execute(local_var_req){{#supportAsync}}.await{{/supportAsync}}?;
355360

356361
let local_var_status = local_var_resp.status();
357-
let local_var_content = local_var_resp.text(){{#supportAsync}}.await{{/supportAsync}}?;
358362

359363
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
360364
{{^supportMultipleResponses}}
365+
{{#isResponseFile}}
366+
Ok(local_var_resp)
367+
{{/isResponseFile}}
368+
{{^isResponseFile}}
361369
{{^returnType}}
362370
Ok(())
363371
{{/returnType}}
364372
{{#returnType}}
373+
let local_var_content = local_var_resp.text(){{#supportAsync}}.await{{/supportAsync}}?;
365374
serde_json::from_str(&local_var_content).map_err(Error::from)
366375
{{/returnType}}
376+
{{/isResponseFile}}
367377
{{/supportMultipleResponses}}
368378
{{#supportMultipleResponses}}
379+
{{#isResponseFile}}
380+
Ok(local_var_resp)
381+
{{/isResponseFile}}
382+
{{^isResponseFile}}
383+
let local_var_content = local_var_resp.text(){{#supportAsync}}.await{{/supportAsync}}?;
369384
let local_var_entity: Option<{{{operationIdCamelCase}}}Success> = serde_json::from_str(&local_var_content).ok();
370385
let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
371386
Ok(local_var_result)
387+
{{/isResponseFile}}
372388
{{/supportMultipleResponses}}
373389
} else {
390+
let local_var_content = local_var_resp.text(){{#supportAsync}}.await{{/supportAsync}}?;
374391
let local_var_entity: Option<{{{operationIdCamelCase}}}Error> = serde_json::from_str(&local_var_content).ok();
375392
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
376393
Err(Error::ResponseError(local_var_error))

samples/client/others/rust/reqwest-regression-16119/src/apis/default_api.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ pub fn repro(configuration: &configuration::Configuration, ) -> Result<models::P
3939
let local_var_resp = local_var_client.execute(local_var_req)?;
4040

4141
let local_var_status = local_var_resp.status();
42-
let local_var_content = local_var_resp.text()?;
4342

4443
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
44+
let local_var_content = local_var_resp.text()?;
4545
serde_json::from_str(&local_var_content).map_err(Error::from)
4646
} else {
47+
let local_var_content = local_var_resp.text()?;
4748
let local_var_entity: Option<ReproError> = serde_json::from_str(&local_var_content).ok();
4849
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
4950
Err(Error::ResponseError(local_var_error))

samples/client/others/rust/reqwest/api-with-ref-param/src/apis/default_api.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ pub async fn demo_color_get(configuration: &configuration::Configuration, color:
3939
let local_var_resp = local_var_client.execute(local_var_req).await?;
4040

4141
let local_var_status = local_var_resp.status();
42-
let local_var_content = local_var_resp.text().await?;
4342

4443
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
4544
Ok(())
4645
} else {
46+
let local_var_content = local_var_resp.text().await?;
4747
let local_var_entity: Option<DemoColorGetError> = serde_json::from_str(&local_var_content).ok();
4848
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
4949
Err(Error::ResponseError(local_var_error))

samples/client/others/rust/reqwest/composed-oneof/src/apis/default_api.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ pub fn create_state(configuration: &configuration::Configuration, create_state_r
4747
let local_var_resp = local_var_client.execute(local_var_req)?;
4848

4949
let local_var_status = local_var_resp.status();
50-
let local_var_content = local_var_resp.text()?;
5150

5251
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
5352
Ok(())
5453
} else {
54+
let local_var_content = local_var_resp.text()?;
5555
let local_var_entity: Option<CreateStateError> = serde_json::from_str(&local_var_content).ok();
5656
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
5757
Err(Error::ResponseError(local_var_error))
@@ -74,11 +74,12 @@ pub fn get_state(configuration: &configuration::Configuration, ) -> Result<model
7474
let local_var_resp = local_var_client.execute(local_var_req)?;
7575

7676
let local_var_status = local_var_resp.status();
77-
let local_var_content = local_var_resp.text()?;
7877

7978
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
79+
let local_var_content = local_var_resp.text()?;
8080
serde_json::from_str(&local_var_content).map_err(Error::from)
8181
} else {
82+
let local_var_content = local_var_resp.text()?;
8283
let local_var_entity: Option<GetStateError> = serde_json::from_str(&local_var_content).ok();
8384
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
8485
Err(Error::ResponseError(local_var_error))

samples/client/others/rust/reqwest/emptyObject/src/apis/default_api.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ pub fn endpoint_get(configuration: &configuration::Configuration, ) -> Result<mo
3939
let local_var_resp = local_var_client.execute(local_var_req)?;
4040

4141
let local_var_status = local_var_resp.status();
42-
let local_var_content = local_var_resp.text()?;
4342

4443
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
44+
let local_var_content = local_var_resp.text()?;
4545
serde_json::from_str(&local_var_content).map_err(Error::from)
4646
} else {
47+
let local_var_content = local_var_resp.text()?;
4748
let local_var_entity: Option<EndpointGetError> = serde_json::from_str(&local_var_content).ok();
4849
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
4950
Err(Error::ResponseError(local_var_error))

samples/client/others/rust/reqwest/oneOf-array-map/src/apis/default_api.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@ pub fn root_get(configuration: &configuration::Configuration, ) -> Result<models
4646
let local_var_resp = local_var_client.execute(local_var_req)?;
4747

4848
let local_var_status = local_var_resp.status();
49-
let local_var_content = local_var_resp.text()?;
5049

5150
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
51+
let local_var_content = local_var_resp.text()?;
5252
serde_json::from_str(&local_var_content).map_err(Error::from)
5353
} else {
54+
let local_var_content = local_var_resp.text()?;
5455
let local_var_entity: Option<RootGetError> = serde_json::from_str(&local_var_content).ok();
5556
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
5657
Err(Error::ResponseError(local_var_error))
@@ -74,11 +75,11 @@ pub fn test(configuration: &configuration::Configuration, body: Option<serde_jso
7475
let local_var_resp = local_var_client.execute(local_var_req)?;
7576

7677
let local_var_status = local_var_resp.status();
77-
let local_var_content = local_var_resp.text()?;
7878

7979
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
8080
Ok(())
8181
} else {
82+
let local_var_content = local_var_resp.text()?;
8283
let local_var_entity: Option<TestError> = serde_json::from_str(&local_var_content).ok();
8384
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
8485
Err(Error::ResponseError(local_var_error))

samples/client/others/rust/reqwest/oneOf-reuseRef/src/apis/default_api.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ pub fn get_fruit(configuration: &configuration::Configuration, ) -> Result<model
3939
let local_var_resp = local_var_client.execute(local_var_req)?;
4040

4141
let local_var_status = local_var_resp.status();
42-
let local_var_content = local_var_resp.text()?;
4342

4443
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
44+
let local_var_content = local_var_resp.text()?;
4545
serde_json::from_str(&local_var_content).map_err(Error::from)
4646
} else {
47+
let local_var_content = local_var_resp.text()?;
4748
let local_var_entity: Option<GetFruitError> = serde_json::from_str(&local_var_content).ok();
4849
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
4950
Err(Error::ResponseError(local_var_error))

samples/client/others/rust/reqwest/oneOf/src/apis/bar_api.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,12 @@ pub fn create_bar(configuration: &configuration::Configuration, bar_create: mode
4040
let local_var_resp = local_var_client.execute(local_var_req)?;
4141

4242
let local_var_status = local_var_resp.status();
43-
let local_var_content = local_var_resp.text()?;
4443

4544
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
45+
let local_var_content = local_var_resp.text()?;
4646
serde_json::from_str(&local_var_content).map_err(Error::from)
4747
} else {
48+
let local_var_content = local_var_resp.text()?;
4849
let local_var_entity: Option<CreateBarError> = serde_json::from_str(&local_var_content).ok();
4950
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
5051
Err(Error::ResponseError(local_var_error))

samples/client/others/rust/reqwest/oneOf/src/apis/foo_api.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@ pub fn create_foo(configuration: &configuration::Configuration, foo: Option<mode
4747
let local_var_resp = local_var_client.execute(local_var_req)?;
4848

4949
let local_var_status = local_var_resp.status();
50-
let local_var_content = local_var_resp.text()?;
5150

5251
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
52+
let local_var_content = local_var_resp.text()?;
5353
serde_json::from_str(&local_var_content).map_err(Error::from)
5454
} else {
55+
let local_var_content = local_var_resp.text()?;
5556
let local_var_entity: Option<CreateFooError> = serde_json::from_str(&local_var_content).ok();
5657
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
5758
Err(Error::ResponseError(local_var_error))
@@ -74,11 +75,12 @@ pub fn get_all_foos(configuration: &configuration::Configuration, ) -> Result<Ve
7475
let local_var_resp = local_var_client.execute(local_var_req)?;
7576

7677
let local_var_status = local_var_resp.status();
77-
let local_var_content = local_var_resp.text()?;
7878

7979
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
80+
let local_var_content = local_var_resp.text()?;
8081
serde_json::from_str(&local_var_content).map_err(Error::from)
8182
} else {
83+
let local_var_content = local_var_resp.text()?;
8284
let local_var_entity: Option<GetAllFoosError> = serde_json::from_str(&local_var_content).ok();
8385
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
8486
Err(Error::ResponseError(local_var_error))

samples/client/petstore/rust/reqwest/name-mapping/src/apis/fake_api.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ pub fn get_parameter_name_mapping(configuration: &configuration::Configuration,
4444
let local_var_resp = local_var_client.execute(local_var_req)?;
4545

4646
let local_var_status = local_var_resp.status();
47-
let local_var_content = local_var_resp.text()?;
4847

4948
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
5049
Ok(())
5150
} else {
51+
let local_var_content = local_var_resp.text()?;
5252
let local_var_entity: Option<GetParameterNameMappingError> = serde_json::from_str(&local_var_content).ok();
5353
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
5454
Err(Error::ResponseError(local_var_error))

samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/fake_api.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,14 @@ pub async fn test_nullable_required_param(configuration: &configuration::Configu
7474
let local_var_resp = local_var_client.execute(local_var_req).await?;
7575

7676
let local_var_status = local_var_resp.status();
77-
let local_var_content = local_var_resp.text().await?;
7877

7978
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
79+
let local_var_content = local_var_resp.text().await?;
8080
let local_var_entity: Option<TestNullableRequiredParamSuccess> = serde_json::from_str(&local_var_content).ok();
8181
let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
8282
Ok(local_var_result)
8383
} else {
84+
let local_var_content = local_var_resp.text().await?;
8485
let local_var_entity: Option<TestNullableRequiredParamError> = serde_json::from_str(&local_var_content).ok();
8586
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
8687
Err(Error::ResponseError(local_var_error))

0 commit comments

Comments
 (0)