Skip to content

Commit

Permalink
[rust][reqwest] support binary download in supportMultipleResponses c…
Browse files Browse the repository at this point in the history
…ontexts
  • Loading branch information
Thomas Ville committed Nov 7, 2024
1 parent 69fb82c commit 82250cc
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ pub struct {{{operationIdCamelCase}}}Params {
pub enum {{{operationIdCamelCase}}}Success {
{{#responses}}
{{#is2xx}}
Status{{code}}({{#isResponseFile}}{{#supportAsync}}reqwest::Response{{/supportAsync}}{{^supportAsync}}reqwest::blocking::Response{{/supportAsync}}{{/isResponseFile}}{{^isResponseFile}}{{#isEnum}}{{{enumName}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{/isResponseFile}}),
Status{{code}}({{#isEnum}}{{{enumName}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}),
{{/is2xx}}
{{#is3xx}}
Status{{code}}({{#isResponseFile}}{{#supportAsync}}reqwest::Response{{/supportAsync}}{{^supportAsync}}reqwest::blocking::Response{{/supportAsync}}{{/isResponseFile}}{{^isResponseFile}}{{#isEnum}}{{{enumName}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{/isResponseFile}}),
Status{{code}}({{#isEnum}}{{{enumName}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}),
{{/is3xx}}
{{/responses}}
UnknownValue(serde_json::Value),
Expand Down Expand Up @@ -80,7 +80,7 @@ pub enum {{{operationIdCamelCase}}}Error {
/// {{{.}}}
{{/notes}}
{{#vendorExtensions.x-group-parameters}}
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}}{{#isResponseFile}}{{#supportAsync}}reqwest::Response{{/supportAsync}}{{^supportAsync}}reqwest::blocking::Response{{/supportAsync}}{{/isResponseFile}}{{^isResponseFile}}{{{returnType}}}{{/isResponseFile}}{{/supportMultipleResponses}}, Error<{{{operationIdCamelCase}}}Error>> {
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>> {
let local_var_configuration = configuration;
// unbox the parameters
Expand All @@ -90,7 +90,7 @@ pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration:

{{/vendorExtensions.x-group-parameters}}
{{^vendorExtensions.x-group-parameters}}
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}}{{#isResponseFile}}{{#supportAsync}}reqwest::Response{{/supportAsync}}{{^supportAsync}}reqwest::blocking::Response{{/supportAsync}}{{/isResponseFile}}{{^isResponseFile}}{{{returnType}}}{{/isResponseFile}}{{/supportMultipleResponses}}, Error<{{{operationIdCamelCase}}}Error>> {
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>> {
let local_var_configuration = configuration;
{{/vendorExtensions.x-group-parameters}}

Expand Down Expand Up @@ -377,15 +377,14 @@ pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration:
{{/supportMultipleResponses}}
{{#supportMultipleResponses}}
{{#isResponseFile}}
let local_var_content = String::new();
let local_var_entity = {{{operationIdCamelCase}}}Success::Status200(local_var_resp);
Ok(local_var_resp)
{{/isResponseFile}}
{{^isResponseFile}}
let local_var_content = local_var_resp.text(){{#supportAsync}}.await{{/supportAsync}}?;
let local_var_entity: Option<{{{operationIdCamelCase}}}Success> = serde_json::from_str(&local_var_content).ok();
{{/isResponseFile}}
let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Ok(local_var_result)
{{/isResponseFile}}
{{/supportMultipleResponses}}
} else {
let local_var_content = local_var_resp.text(){{#supportAsync}}.await{{/supportAsync}}?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use super::{Error, configuration};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum TestsFileResponseGetSuccess {
Status200(reqwest::Response),
Status200(std::path::PathBuf),
UnknownValue(serde_json::Value),
}

Expand All @@ -46,7 +46,7 @@ pub enum TestsTypeTestingGetError {
}


pub async fn tests_file_response_get(configuration: &configuration::Configuration) -> Result<ResponseContent<TestsFileResponseGetSuccess>, Error<TestsFileResponseGetError>> {
pub async fn tests_file_response_get(configuration: &configuration::Configuration) -> Result<reqwest::Response, Error<TestsFileResponseGetError>> {
let local_var_configuration = configuration;

// unbox the parameters
Expand All @@ -67,10 +67,7 @@ pub async fn tests_file_response_get(configuration: &configuration::Configuratio
let local_var_status = local_var_resp.status();

if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
let local_var_content = String::new();
let local_var_entity = TestsFileResponseGetSuccess::Status200(local_var_resp);
let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Ok(local_var_result)
Ok(local_var_resp)
} else {
let local_var_content = local_var_resp.text().await?;
let local_var_entity: Option<TestsFileResponseGetError> = serde_json::from_str(&local_var_content).ok();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use super::{Error, configuration};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum TestsFileResponseGetSuccess {
Status200(reqwest::Response),
Status200(std::path::PathBuf),
UnknownValue(serde_json::Value),
}

Expand All @@ -46,7 +46,7 @@ pub enum TestsTypeTestingGetError {
}


pub async fn tests_file_response_get(configuration: &configuration::Configuration) -> Result<ResponseContent<TestsFileResponseGetSuccess>, Error<TestsFileResponseGetError>> {
pub async fn tests_file_response_get(configuration: &configuration::Configuration) -> Result<reqwest::Response, Error<TestsFileResponseGetError>> {
let local_var_configuration = configuration;

// unbox the parameters
Expand All @@ -67,10 +67,7 @@ pub async fn tests_file_response_get(configuration: &configuration::Configuratio
let local_var_status = local_var_resp.status();

if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
let local_var_content = String::new();
let local_var_entity = TestsFileResponseGetSuccess::Status200(local_var_resp);
let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Ok(local_var_result)
Ok(local_var_resp)
} else {
let local_var_content = local_var_resp.text().await?;
let local_var_entity: Option<TestsFileResponseGetError> = serde_json::from_str(&local_var_content).ok();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use super::{Error, configuration};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum TestsFileResponseGetSuccess {
Status200(reqwest::Response),
Status200(std::path::PathBuf),
UnknownValue(serde_json::Value),
}

Expand All @@ -46,7 +46,7 @@ pub enum TestsTypeTestingGetError {
}


pub async fn tests_file_response_get(configuration: &configuration::Configuration) -> Result<ResponseContent<TestsFileResponseGetSuccess>, Error<TestsFileResponseGetError>> {
pub async fn tests_file_response_get(configuration: &configuration::Configuration) -> Result<reqwest::Response, Error<TestsFileResponseGetError>> {
let local_var_configuration = configuration;

// unbox the parameters
Expand All @@ -67,10 +67,7 @@ pub async fn tests_file_response_get(configuration: &configuration::Configuratio
let local_var_status = local_var_resp.status();

if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
let local_var_content = String::new();
let local_var_entity = TestsFileResponseGetSuccess::Status200(local_var_resp);
let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Ok(local_var_result)
Ok(local_var_resp)
} else {
let local_var_content = local_var_resp.text().await?;
let local_var_entity: Option<TestsFileResponseGetError> = serde_json::from_str(&local_var_content).ok();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use super::{Error, configuration};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum TestsFileResponseGetSuccess {
Status200(reqwest::Response),
Status200(std::path::PathBuf),
UnknownValue(serde_json::Value),
}

Expand All @@ -46,7 +46,7 @@ pub enum TestsTypeTestingGetError {
}


pub async fn tests_file_response_get(configuration: &configuration::Configuration) -> Result<ResponseContent<TestsFileResponseGetSuccess>, Error<TestsFileResponseGetError>> {
pub async fn tests_file_response_get(configuration: &configuration::Configuration) -> Result<reqwest::Response, Error<TestsFileResponseGetError>> {
let local_var_configuration = configuration;

// unbox the parameters
Expand All @@ -67,10 +67,7 @@ pub async fn tests_file_response_get(configuration: &configuration::Configuratio
let local_var_status = local_var_resp.status();

if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
let local_var_content = String::new();
let local_var_entity = TestsFileResponseGetSuccess::Status200(local_var_resp);
let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Ok(local_var_result)
Ok(local_var_resp)
} else {
let local_var_content = local_var_resp.text().await?;
let local_var_entity: Option<TestsFileResponseGetError> = serde_json::from_str(&local_var_content).ok();
Expand Down

0 comments on commit 82250cc

Please sign in to comment.