Skip to content

Commit

Permalink
[rust][reqwest] support binary type for upload and download
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Ville committed Nov 6, 2024
1 parent 00dbe59 commit 69fb82c
Show file tree
Hide file tree
Showing 45 changed files with 346 additions and 192 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}}({{#isEnum}}{{{enumName}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}),
Status{{code}}({{#isResponseFile}}{{#supportAsync}}reqwest::Response{{/supportAsync}}{{^supportAsync}}reqwest::blocking::Response{{/supportAsync}}{{/isResponseFile}}{{^isResponseFile}}{{#isEnum}}{{{enumName}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{/isResponseFile}}),
{{/is2xx}}
{{#is3xx}}
Status{{code}}({{#isEnum}}{{{enumName}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}),
Status{{code}}({{#isResponseFile}}{{#supportAsync}}reqwest::Response{{/supportAsync}}{{^supportAsync}}reqwest::blocking::Response{{/supportAsync}}{{/isResponseFile}}{{^isResponseFile}}{{#isEnum}}{{{enumName}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{/isResponseFile}}),
{{/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}}{{{returnType}}}{{/supportMultipleResponses}}, Error<{{{operationIdCamelCase}}}Error>> {
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>> {
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<{{#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>> {
let local_var_configuration = configuration;
{{/vendorExtensions.x-group-parameters}}

Expand Down Expand Up @@ -346,31 +346,49 @@ 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}}
{{^returnType}}
Ok(())
{{/returnType}}
{{#returnType}}
{{#isResponseFile}}
Ok(local_var_resp)
{{/isResponseFile}}
{{^isResponseFile}}
let local_var_content = local_var_resp.text(){{#supportAsync}}.await{{/supportAsync}}?;
serde_json::from_str(&local_var_content).map_err(Error::from)
{{/isResponseFile}}
{{/returnType}}
{{/supportMultipleResponses}}
{{#supportMultipleResponses}}
{{#isResponseFile}}
let local_var_content = String::new();
let local_var_entity = {{{operationIdCamelCase}}}Success::Status200(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)
{{/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

0 comments on commit 69fb82c

Please sign in to comment.