Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rust][reqwest] support binary type for download #20031

Merged
merged 3 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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}}{{{returnType}}}{{/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}}{{{returnType}}}{{/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 @@ -346,31 +346,48 @@ pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration:
{{/isMultipart}}
{{#hasBodyParam}}
{{#bodyParams}}
{{#isFile}}
local_var_req_builder = local_var_req_builder.body({{{paramName}}});
{{/isFile}}
{{^isFile}}
local_var_req_builder = local_var_req_builder.json(&{{{paramName}}});
{{/isFile}}
{{/bodyParams}}
{{/hasBodyParam}}

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

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

if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
{{^supportMultipleResponses}}
{{#isResponseFile}}
Ok(local_var_resp)
{{/isResponseFile}}
{{^isResponseFile}}
{{^returnType}}
Ok(())
{{/returnType}}
{{#returnType}}
let local_var_content = local_var_resp.text(){{#supportAsync}}.await{{/supportAsync}}?;
serde_json::from_str(&local_var_content).map_err(Error::from)
{{/returnType}}
{{/isResponseFile}}
{{/supportMultipleResponses}}
{{#supportMultipleResponses}}
{{#isResponseFile}}
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();
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}}?;
let local_var_entity: Option<{{{operationIdCamelCase}}}Error> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ pub fn repro(configuration: &configuration::Configuration, ) -> Result<models::P
let local_var_resp = local_var_client.execute(local_var_req)?;

let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text()?;

if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
let local_var_content = local_var_resp.text()?;
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_content = local_var_resp.text()?;
let local_var_entity: Option<ReproError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ pub async fn demo_color_get(configuration: &configuration::Configuration, color:
let local_var_resp = local_var_client.execute(local_var_req).await?;

let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;

if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
Ok(())
} else {
let local_var_content = local_var_resp.text().await?;
let local_var_entity: Option<DemoColorGetError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ pub fn create_state(configuration: &configuration::Configuration, create_state_r
let local_var_resp = local_var_client.execute(local_var_req)?;

let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text()?;

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

let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text()?;

if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
let local_var_content = local_var_resp.text()?;
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_content = local_var_resp.text()?;
let local_var_entity: Option<GetStateError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ pub fn endpoint_get(configuration: &configuration::Configuration, ) -> Result<mo
let local_var_resp = local_var_client.execute(local_var_req)?;

let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text()?;

if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
let local_var_content = local_var_resp.text()?;
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_content = local_var_resp.text()?;
let local_var_entity: Option<EndpointGetError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ pub fn root_get(configuration: &configuration::Configuration, ) -> Result<models
let local_var_resp = local_var_client.execute(local_var_req)?;

let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text()?;

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

let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text()?;

if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
Ok(())
} else {
let local_var_content = local_var_resp.text()?;
let local_var_entity: Option<TestError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ pub fn get_fruit(configuration: &configuration::Configuration, ) -> Result<model
let local_var_resp = local_var_client.execute(local_var_req)?;

let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text()?;

if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
let local_var_content = local_var_resp.text()?;
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_content = local_var_resp.text()?;
let local_var_entity: Option<GetFruitError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
Expand Down
3 changes: 2 additions & 1 deletion samples/client/others/rust/reqwest/oneOf/src/apis/bar_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ pub fn create_bar(configuration: &configuration::Configuration, bar_create: mode
let local_var_resp = local_var_client.execute(local_var_req)?;

let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text()?;

if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
let local_var_content = local_var_resp.text()?;
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_content = local_var_resp.text()?;
let local_var_entity: Option<CreateBarError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
Expand Down
6 changes: 4 additions & 2 deletions samples/client/others/rust/reqwest/oneOf/src/apis/foo_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ pub fn create_foo(configuration: &configuration::Configuration, foo: Option<mode
let local_var_resp = local_var_client.execute(local_var_req)?;

let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text()?;

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

let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text()?;

if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
let local_var_content = local_var_resp.text()?;
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_content = local_var_resp.text()?;
let local_var_entity: Option<GetAllFoosError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ pub fn get_parameter_name_mapping(configuration: &configuration::Configuration,
let local_var_resp = local_var_client.execute(local_var_req)?;

let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text()?;

if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
Ok(())
} else {
let local_var_content = local_var_resp.text()?;
let local_var_entity: Option<GetParameterNameMappingError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,14 @@ pub async fn test_nullable_required_param(configuration: &configuration::Configu
let local_var_resp = local_var_client.execute(local_var_req).await?;

let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;

if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
let local_var_content = local_var_resp.text().await?;
let local_var_entity: Option<TestNullableRequiredParamSuccess> = serde_json::from_str(&local_var_content).ok();
let local_var_result = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Ok(local_var_result)
} else {
let local_var_content = local_var_resp.text().await?;
let local_var_entity: Option<TestNullableRequiredParamError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
Expand Down
Loading
Loading