diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractRustCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractRustCodegen.java index 55bd4290126fe..7da93b288de13 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractRustCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractRustCodegen.java @@ -21,6 +21,8 @@ public abstract class AbstractRustCodegen extends DefaultCodegen implements Code private final Logger LOGGER = LoggerFactory.getLogger(AbstractRustCodegen.class); + protected static final String VENDOR_EXTENSION_PARAM_IDENTIFIER = "x-rust-param-identifier"; + protected List charactersToAllow = Collections.singletonList("_"); protected Set keywordsThatDoNotSupportRawIdentifiers = new HashSet<>( Arrays.asList("super", "self", "Self", "extern", "crate")); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java index d8d58cd588b8b..3f8ba7bb3b5b5 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustClientCodegen.java @@ -39,8 +39,10 @@ import org.openapitools.codegen.CodegenModel; import org.openapitools.codegen.CodegenOperation; import org.openapitools.codegen.CodegenProperty; +import org.openapitools.codegen.CodegenParameter; import org.openapitools.codegen.CodegenType; import org.openapitools.codegen.SupportingFile; +import org.openapitools.codegen.VendorExtension; import org.openapitools.codegen.meta.features.ClientModificationFeature; import org.openapitools.codegen.meta.features.DocumentationFeature; import org.openapitools.codegen.meta.features.GlobalFeature; @@ -602,6 +604,25 @@ public void postProcessModelProperty(CodegenModel model, CodegenProperty propert } } + @Override + public void postProcessParameter(CodegenParameter parameter) { + super.postProcessParameter(parameter); + // in order to avoid name conflicts, we map parameters inside the functions + String inFunctionIdentifier = ""; + if (this.useSingleRequestParameter) { + inFunctionIdentifier = "params." + parameter.paramName; + } else { + if (parameter.paramName.startsWith("r#")) { + inFunctionIdentifier = "p_" + parameter.paramName.substring(2); + } else { + inFunctionIdentifier = "p_" + parameter.paramName; + } + } + if (!parameter.vendorExtensions.containsKey(this.VENDOR_EXTENSION_PARAM_IDENTIFIER)) { // allow to overwrite this value + parameter.vendorExtensions.put(this.VENDOR_EXTENSION_PARAM_IDENTIFIER, inFunctionIdentifier); + } + } + @Override public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List allModels) { OperationMap objectMap = objs.getOperations(); @@ -699,7 +720,7 @@ public String toDefaultValue(Schema p) { @Override protected ImmutableMap.Builder addMustacheLambdas() { return super.addMustacheLambdas() - // Convert variable names to lifetime names. + // Convert variable names to lifetime names. // Generally they are the same, but `#` is not valid in lifetime names. // Rust uses `r#` prefix for variables that are also keywords. .put("lifetimeName", new ReplaceAllLambda("^r#", "r_")); diff --git a/modules/openapi-generator/src/main/resources/dart/libraries/dio/pubspec.mustache b/modules/openapi-generator/src/main/resources/dart/libraries/dio/pubspec.mustache index 5a93026402d26..6e27e3309329b 100644 --- a/modules/openapi-generator/src/main/resources/dart/libraries/dio/pubspec.mustache +++ b/modules/openapi-generator/src/main/resources/dart/libraries/dio/pubspec.mustache @@ -9,11 +9,12 @@ repository: {{.}} publish_to: {{.}} {{/pubPublishTo}} + environment: - sdk: '>={{#useJsonSerializable}}2.17.0{{/useJsonSerializable}}{{^useJsonSerializable}}2.15.0{{/useJsonSerializable}} <4.0.0' + sdk: '>={{^useJsonSerializable}}2.18.0{{/useJsonSerializable}}{{#useJsonSerializable}}3.5.0{{/useJsonSerializable}} <4.0.0' dependencies: - dio: '^5.2.0' + dio: '^5.7.0' {{#useBuiltValue}} one_of: '>=1.5.0 <2.0.0' one_of_serializer: '>=1.5.0 <2.0.0' @@ -21,13 +22,13 @@ dependencies: built_collection: '>=5.1.1 <6.0.0' {{/useBuiltValue}} {{#useEquatable}} - equatable: '^2.0.5' + equatable: '^2.0.7' {{/useEquatable}} {{#useJsonSerializable}} - json_annotation: '^4.4.0' + json_annotation: '^4.9.0' {{/useJsonSerializable}} {{#useDateLibTimeMachine}} - time_machine: ^0.9.16 + time_machine: ^0.9.17 {{/useDateLibTimeMachine}} dev_dependencies: @@ -37,6 +38,6 @@ dev_dependencies: {{/useBuiltValue}} {{#useJsonSerializable}} build_runner: any - json_serializable: '^6.1.5' + json_serializable: '^6.9.3' {{/useJsonSerializable}} - test: ^1.16.0 + test: '^1.16.0' diff --git a/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache b/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache index b96063531e616..ffe0f199a9806 100644 --- a/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache +++ b/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache @@ -81,66 +81,62 @@ 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<{{#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 - {{#allParams}} - let {{paramName}} = params.{{paramName}}; - {{/allParams}} - {{/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<{{#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; + {{#allParams.0}} + // add a prefix to parameters to efficiently prevent name collisions + {{/allParams.0}} + {{#allParams}} + let {{{vendorExtensions.x-rust-param-identifier}}} = {{{paramName}}}; + {{/allParams}} {{/vendorExtensions.x-group-parameters}} - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}{{{path}}}", local_var_configuration.base_path{{#pathParams}}, {{{baseName}}}={{#isString}}crate::apis::urlencode({{/isString}}{{{paramName}}}{{^required}}.unwrap(){{/required}}{{#required}}{{#isNullable}}.unwrap(){{/isNullable}}{{/required}}{{#isArray}}.join(",").as_ref(){{/isArray}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}.to_string(){{/isContainer}}{{/isPrimitiveType}}{{/isUuid}}{{/isString}}{{#isString}}){{/isString}}{{/pathParams}}); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::{{{httpMethod}}}, local_var_uri_str.as_str()); + let uri_str = format!("{}{{{path}}}", configuration.base_path{{#pathParams}}, {{{baseName}}}={{#isString}}crate::apis::urlencode({{/isString}}{{{vendorExtensions.x-rust-param-identifier}}}{{^required}}.unwrap(){{/required}}{{#required}}{{#isNullable}}.unwrap(){{/isNullable}}{{/required}}{{#isArray}}.join(",").as_ref(){{/isArray}}{{^isString}}{{^isUuid}}{{^isPrimitiveType}}{{^isContainer}}.to_string(){{/isContainer}}{{/isPrimitiveType}}{{/isUuid}}{{/isString}}{{#isString}}){{/isString}}{{/pathParams}}); + let mut req_builder = configuration.client.request(reqwest::Method::{{{httpMethod}}}, &uri_str); {{#queryParams}} {{#required}} {{#isArray}} - local_var_req_builder = match "{{collectionFormat}}" { - "multi" => local_var_req_builder.query(&{{{paramName}}}.into_iter().map(|p| ("{{{baseName}}}".to_owned(), p.to_string())).collect::>()), - _ => local_var_req_builder.query(&[("{{{baseName}}}", &{{{paramName}}}.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), + req_builder = match "{{collectionFormat}}" { + "multi" => req_builder.query(&{{{vendorExtensions.x-rust-param-identifier}}}.into_iter().map(|p| ("{{{baseName}}}".to_owned(), p.to_string())).collect::>()), + _ => req_builder.query(&[("{{{baseName}}}", &{{{vendorExtensions.x-rust-param-identifier}}}.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), }; {{/isArray}} {{^isArray}} {{^isNullable}} - local_var_req_builder = local_var_req_builder.query(&[("{{{baseName}}}", &{{{paramName}}}.to_string())]); + req_builder = req_builder.query(&[("{{{baseName}}}", &{{{vendorExtensions.x-rust-param-identifier}}}.to_string())]); {{/isNullable}} {{#isNullable}} {{#isDeepObject}} - if let Some(ref local_var_str) = {{{paramName}}} { - let params = crate::apis::parse_deep_object("{{{baseName}}}", local_var_str); - local_var_req_builder = local_var_req_builder.query(¶ms); + if let Some(ref param_value) = {{{vendorExtensions.x-rust-param-identifier}}} { + let params = crate::apis::parse_deep_object("{{{baseName}}}", param_value); + req_builder = req_builder.query(¶ms); }; {{/isDeepObject}} {{^isDeepObject}} - if let Some(ref local_var_str) = {{{paramName}}} { - local_var_req_builder = local_var_req_builder.query(&[("{{{baseName}}}", &local_var_str.to_string())]); + if let Some(ref param_value) = {{{vendorExtensions.x-rust-param-identifier}}} { + req_builder = req_builder.query(&[("{{{baseName}}}", ¶m_value.to_string())]); }; {{/isDeepObject}} {{/isNullable}} {{/isArray}} {{/required}} {{^required}} - if let Some(ref local_var_str) = {{{paramName}}} { + if let Some(ref param_value) = {{{vendorExtensions.x-rust-param-identifier}}} { {{#isArray}} - local_var_req_builder = match "{{collectionFormat}}" { - "multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("{{{baseName}}}".to_owned(), p.to_string())).collect::>()), - _ => local_var_req_builder.query(&[("{{{baseName}}}", &local_var_str.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), + req_builder = match "{{collectionFormat}}" { + "multi" => req_builder.query(¶m_value.into_iter().map(|p| ("{{{baseName}}}".to_owned(), p.to_string())).collect::>()), + _ => req_builder.query(&[("{{{baseName}}}", ¶m_value.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), }; {{/isArray}} {{^isArray}} {{#isDeepObject}} - let params = crate::apis::parse_deep_object("{{{baseName}}}", local_var_str); - local_var_req_builder = local_var_req_builder.query(¶ms); + let params = crate::apis::parse_deep_object("{{{baseName}}}", param_value); + req_builder = req_builder.query(¶ms); {{/isDeepObject}} {{^isDeepObject}} - local_var_req_builder = local_var_req_builder.query(&[("{{{baseName}}}", &local_var_str.to_string())]); + req_builder = req_builder.query(&[("{{{baseName}}}", ¶m_value.to_string())]); {{/isDeepObject}} {{/isArray}} } @@ -150,13 +146,13 @@ pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration: {{#authMethods}} {{#isApiKey}} {{#isKeyInQuery}} - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.query(&[("{{{keyParamName}}}", local_var_value)]); + req_builder = req_builder.query(&[("{{{keyParamName}}}", value)]); } {{/isKeyInQuery}} {{/isApiKey}} @@ -164,13 +160,13 @@ pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration: {{/hasAuthMethods}} {{#hasAuthMethods}} {{#withAWSV4Signature}} - if let Some(ref local_var_aws_v4_key) = local_var_configuration.aws_v4_key { - let local_var_new_headers = match local_var_aws_v4_key.sign( - &local_var_uri_str, + if let Some(ref aws_v4_key) = configuration.aws_v4_key { + let new_headers = match aws_v4_key.sign( + &uri_str, "{{{httpMethod}}}", {{#hasBodyParam}} {{#bodyParams}} - &serde_json::to_string(&{{{paramName}}}).expect("param should serialize to string"), + &serde_json::to_string(&{{{vendorExtensions.x-rust-param-identifier}}}).expect("param should serialize to string"), {{/bodyParams}} {{/hasBodyParam}} {{^hasBodyParam}} @@ -180,31 +176,31 @@ pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration: Ok(new_headers) => new_headers, Err(err) => return Err(Error::AWSV4SignatureError(err)), }; - for (local_var_name, local_var_value) in local_var_new_headers.iter() { - local_var_req_builder = local_var_req_builder.header(local_var_name.as_str(), local_var_value.as_str()); + for (name, value) in new_headers.iter() { + req_builder = req_builder.header(name.as_str(), value.as_str()); } } {{/withAWSV4Signature}} {{/hasAuthMethods}} - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } {{#hasHeaderParams}} {{#headerParams}} {{#required}} {{^isNullable}} - local_var_req_builder = local_var_req_builder.header("{{{baseName}}}", {{{paramName}}}{{#isArray}}.join(","){{/isArray}}.to_string()); + req_builder = req_builder.header("{{{baseName}}}", {{{vendorExtensions.x-rust-param-identifier}}}{{#isArray}}.join(","){{/isArray}}.to_string()); {{/isNullable}} {{#isNullable}} - match {{{paramName}}} { - Some(local_var_param_value) => { local_var_req_builder = local_var_req_builder.header("{{{baseName}}}", local_var_param_value{{#isArray}}.join(","){{/isArray}}.to_string()); }, - None => { local_var_req_builder = local_var_req_builder.header("{{{baseName}}}", ""); }, + match {{{vendorExtensions.x-rust-param-identifier}}} { + Some(param_value) => { req_builder = req_builder.header("{{{baseName}}}", param_value{{#isArray}}.join(","){{/isArray}}.to_string()); }, + None => { req_builder = req_builder.header("{{{baseName}}}", ""); }, } {{/isNullable}} {{/required}} {{^required}} - if let Some(local_var_param_value) = {{{paramName}}} { - local_var_req_builder = local_var_req_builder.header("{{{baseName}}}", local_var_param_value{{#isArray}}.join(","){{/isArray}}.to_string()); + if let Some(param_value) = {{{vendorExtensions.x-rust-param-identifier}}} { + req_builder = req_builder.header("{{{baseName}}}", param_value{{#isArray}}.join(","){{/isArray}}.to_string()); } {{/required}} {{/headerParams}} @@ -214,38 +210,38 @@ pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration: {{#supportTokenSource}} // Obtain a token from source provider. // Tokens can be Id or access tokens depending on the provider type and configuration. - let token = local_var_configuration.token_source.token().await.map_err(Error::TokenSource)?; + let token = configuration.token_source.token().await.map_err(Error::TokenSource)?; // The token format is the responsibility of the provider, thus we just set the authorization header with whatever is given. - local_var_req_builder = local_var_req_builder.header(reqwest::header::AUTHORIZATION, token); + req_builder = req_builder.header(reqwest::header::AUTHORIZATION, token); {{/supportTokenSource}} {{^supportTokenSource}} {{#isApiKey}} {{#isKeyInHeader}} - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("{{{keyParamName}}}", local_var_value); + req_builder = req_builder.header("{{{keyParamName}}}", value); }; {{/isKeyInHeader}} {{/isApiKey}} {{#isBasic}} {{#isBasicBasic}} - if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth { - local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned()); + if let Some(ref auth_conf) = configuration.basic_auth { + req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned()); }; {{/isBasicBasic}} {{#isBasicBearer}} - if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.bearer_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; {{/isBasicBearer}} {{/isBasic}} {{#isOAuth}} - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; {{/isOAuth}} {{/supportTokenSource}} @@ -253,24 +249,24 @@ pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration: {{/hasAuthMethods}} {{#isMultipart}} {{#hasFormParams}} - let mut local_var_form = reqwest{{^supportAsync}}::blocking{{/supportAsync}}::multipart::Form::new(); + let mut multipart_form = reqwest{{^supportAsync}}::blocking{{/supportAsync}}::multipart::Form::new(); {{#formParams}} {{#isFile}} {{^supportAsync}} {{#required}} {{^isNullable}} - local_var_form = local_var_form.file("{{{baseName}}}", {{{paramName}}})?; + multipart_form = multipart_form.file("{{{baseName}}}", {{{vendorExtensions.x-rust-param-identifier}}})?; {{/isNullable}} {{#isNullable}} - match {{{paramName}}} { - Some(local_var_param_value) => { local_var_form = local_var_form.file("{{{baseName}}}", local_var_param_value)?; }, + match {{{vendorExtensions.x-rust-param-identifier}}} { + Some(param_value) => { multipart_form = multipart_form.file("{{{baseName}}}", param_value)?; }, None => { unimplemented!("Required nullable form file param not supported"); }, } {{/isNullable}} {{/required}} {{^required}} - if let Some(local_var_param_value) = {{{paramName}}} { - local_var_form = local_var_form.file("{{{baseName}}}", local_var_param_value)?; + if let Some(param_value) = {{{vendorExtensions.x-rust-param-identifier}}} { + multipart_form = multipart_form.file("{{{baseName}}}", param_value)?; } {{/required}} {{/supportAsync}} @@ -281,116 +277,114 @@ pub {{#supportAsync}}async {{/supportAsync}}fn {{{operationId}}}(configuration: {{^isFile}} {{#required}} {{^isNullable}} - local_var_form = local_var_form.text("{{{baseName}}}", {{{paramName}}}{{#isArray}}.into_iter().map(|p| p.to_string()).collect::>().join(","){{/isArray}}.to_string()); + multipart_form = multipart_form.text("{{{baseName}}}", {{{vendorExtensions.x-rust-param-identifier}}}{{#isArray}}.into_iter().map(|p| p.to_string()).collect::>().join(","){{/isArray}}.to_string()); {{/isNullable}} {{#isNullable}} - match {{{paramName}}} { - Some(local_var_param_value) => { local_var_form = local_var_form.text("{{{baseName}}}", local_var_param_value{{#isArray}}.into_iter().map(|p| p.to_string()).collect::>().join(","){{/isArray}}.to_string()); }, - None => { local_var_form = local_var_form.text("{{{baseName}}}", ""); }, + match {{{vendorExtensions.x-rust-param-identifier}}} { + Some(param_value) => { multipart_form = multipart_form.text("{{{baseName}}}", param_value{{#isArray}}.into_iter().map(|p| p.to_string()).collect::>().join(","){{/isArray}}.to_string()); }, + None => { multipart_form = multipart_form.text("{{{baseName}}}", ""); }, } {{/isNullable}} {{/required}} {{^required}} - if let Some(local_var_param_value) = {{{paramName}}} { - local_var_form = local_var_form.text("{{{baseName}}}", local_var_param_value{{#isArray}}.into_iter().map(|p| p.to_string()).collect::>().join(","){{/isArray}}.to_string()); + if let Some(param_value) = {{{vendorExtensions.x-rust-param-identifier}}} { + multipart_form = multipart_form.text("{{{baseName}}}", param_value{{#isArray}}.into_iter().map(|p| p.to_string()).collect::>().join(","){{/isArray}}.to_string()); } {{/required}} {{/isFile}} {{/formParams}} - local_var_req_builder = local_var_req_builder.multipart(local_var_form); + req_builder = req_builder.multipart(multipart_form); {{/hasFormParams}} {{/isMultipart}} {{^isMultipart}} {{#hasFormParams}} - let mut local_var_form_params = std::collections::HashMap::new(); + let mut multipart_form_params = std::collections::HashMap::new(); {{#formParams}} {{#isFile}} {{#required}} {{^isNullable}} - local_var_form_params.insert("{{{baseName}}}", unimplemented!("File form param not supported with x-www-form-urlencoded content")); + multipart_form_params.insert("{{{baseName}}}", unimplemented!("File form param not supported with x-www-form-urlencoded content")); {{/isNullable}} {{#isNullable}} - match {{{paramName}}} { - Some(local_var_param_value) => { local_var_form_params.insert("{{{baseName}}}", unimplemented!("File form param not supported with x-www-form-urlencoded content")); }, + match {{{vendorExtensions.x-rust-param-identifier}}} { + Some(param_value) => { multipart_form_params.insert("{{{baseName}}}", unimplemented!("File form param not supported with x-www-form-urlencoded content")); }, None => { unimplemented!("Required nullable file form param not supported with x-www-form-urlencoded content"); }, } {{/isNullable}} {{/required}} {{^required}} - if let Some(local_var_param_value) = {{{paramName}}} { - local_var_form_params.insert("{{{baseName}}}", unimplemented!("File form param not supported with x-www-form-urlencoded content")); + if let Some(param_value) = {{{vendorExtensions.x-rust-param-identifier}}} { + multipart_form_params.insert("{{{baseName}}}", unimplemented!("File form param not supported with x-www-form-urlencoded content")); } {{/required}} {{/isFile}} {{^isFile}} {{#required}} {{^isNullable}} - local_var_form_params.insert("{{{baseName}}}", {{{paramName}}}{{#isArray}}.into_iter().map(|p| p.to_string()).collect::>().join(","){{/isArray}}.to_string()); + multipart_form_params.insert("{{{baseName}}}", {{{vendorExtensions.x-rust-param-identifier}}}{{#isArray}}.into_iter().map(|p| p.to_string()).collect::>().join(","){{/isArray}}.to_string()); {{/isNullable}} {{#isNullable}} - match {{{paramName}}} { - Some(local_var_param_value) => { local_var_form_params.insert("{{{baseName}}}", local_var_param_value{{#isArray}}.into_iter().map(|p| p.to_string()).collect::>().join(","){{/isArray}}.to_string()); }, - None => { local_var_form_params.insert("{{{baseName}}}", ""); }, + match {{{vendorExtensions.x-rust-param-identifier}}} { + Some(param_value) => { multipart_form_params.insert("{{{baseName}}}", param_value{{#isArray}}.into_iter().map(|p| p.to_string()).collect::>().join(","){{/isArray}}.to_string()); }, + None => { multipart_form_params.insert("{{{baseName}}}", ""); }, } {{/isNullable}} {{/required}} {{^required}} - if let Some(local_var_param_value) = {{{paramName}}} { - local_var_form_params.insert("{{{baseName}}}", local_var_param_value{{#isArray}}.into_iter().map(|p| p.to_string()).collect::>().join(","){{/isArray}}.to_string()); + if let Some(param_value) = {{{vendorExtensions.x-rust-param-identifier}}} { + multipart_form_params.insert("{{{baseName}}}", param_value{{#isArray}}.into_iter().map(|p| p.to_string()).collect::>().join(","){{/isArray}}.to_string()); } {{/required}} {{/isFile}} {{/formParams}} - local_var_req_builder = local_var_req_builder.form(&local_var_form_params); + req_builder = req_builder.form(&multipart_form_params); {{/hasFormParams}} {{/isMultipart}} {{#hasBodyParam}} {{#bodyParams}} {{#isFile}} - local_var_req_builder = local_var_req_builder.body({{{paramName}}}); + req_builder = req_builder.body({{{vendorExtensions.x-rust-param-identifier}}}); {{/isFile}} {{^isFile}} - local_var_req_builder = local_var_req_builder.json(&{{{paramName}}}); + req_builder = req_builder.json(&{{{vendorExtensions.x-rust-param-identifier}}}); {{/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 req = req_builder.build()?; + let resp = configuration.client.execute(req){{#supportAsync}}.await{{/supportAsync}}?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + if !status.is_client_error() && !status.is_server_error() { {{^supportMultipleResponses}} {{#isResponseFile}} - Ok(local_var_resp) + Ok(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) + let content = resp.text(){{#supportAsync}}.await{{/supportAsync}}?; + serde_json::from_str(&content).map_err(Error::from) {{/returnType}} {{/isResponseFile}} {{/supportMultipleResponses}} {{#supportMultipleResponses}} {{#isResponseFile}} - Ok(local_var_resp) + Ok(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) + let content = resp.text(){{#supportAsync}}.await{{/supportAsync}}?; + let entity: Option<{{{operationIdCamelCase}}}Success> = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) {{/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)) + let content = resp.text(){{#supportAsync}}.await{{/supportAsync}}?; + let entity: Option<{{{operationIdCamelCase}}}Error> = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/modules/openapi-generator/src/test/resources/3_0/rust/petstore.yaml b/modules/openapi-generator/src/test/resources/3_0/rust/petstore.yaml index e193a3bc59029..211f9986dca1d 100644 --- a/modules/openapi-generator/src/test/resources/3_0/rust/petstore.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/rust/petstore.yaml @@ -608,6 +608,11 @@ paths: description: To test parameter names in upper case schema: type: string + - name: content + in: query + description: To test escaping of parameters in rust code works + schema: + type: string responses: '200': description: successful operation diff --git a/samples/client/others/rust/reqwest-regression-16119/src/apis/default_api.rs b/samples/client/others/rust/reqwest-regression-16119/src/apis/default_api.rs index bea5f638a6e79..382dc5a2ce0d5 100644 --- a/samples/client/others/rust/reqwest-regression-16119/src/apis/default_api.rs +++ b/samples/client/others/rust/reqwest-regression-16119/src/apis/default_api.rs @@ -24,30 +24,26 @@ pub enum ReproError { pub fn repro(configuration: &configuration::Configuration, ) -> Result> { - let local_var_configuration = configuration; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/repro", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - let local_var_uri_str = format!("{}/repro", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/others/rust/reqwest/api-with-ref-param/src/apis/default_api.rs b/samples/client/others/rust/reqwest/api-with-ref-param/src/apis/default_api.rs index 179f9ea5c141f..562421a76248c 100644 --- a/samples/client/others/rust/reqwest/api-with-ref-param/src/apis/default_api.rs +++ b/samples/client/others/rust/reqwest/api-with-ref-param/src/apis/default_api.rs @@ -24,29 +24,27 @@ pub enum DemoColorGetError { pub async fn demo_color_get(configuration: &configuration::Configuration, color: models::Color) -> Result<(), Error> { - let local_var_configuration = configuration; + // add a prefix to parameters to efficiently prevent name collisions + let p_color = color; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/demo/{color}", configuration.base_path, color=p_color.to_string()); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - let local_var_uri_str = format!("{}/demo/{color}", local_var_configuration.base_path, color=color.to_string()); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + if !status.is_client_error() && !status.is_server_error() { Ok(()) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/others/rust/reqwest/composed-oneof/src/apis/default_api.rs b/samples/client/others/rust/reqwest/composed-oneof/src/apis/default_api.rs index c0def694ddee6..593abfd482164 100644 --- a/samples/client/others/rust/reqwest/composed-oneof/src/apis/default_api.rs +++ b/samples/client/others/rust/reqwest/composed-oneof/src/apis/default_api.rs @@ -31,58 +31,52 @@ pub enum GetStateError { pub fn create_state(configuration: &configuration::Configuration, create_state_request: models::CreateStateRequest) -> Result<(), Error> { - let local_var_configuration = configuration; + // add a prefix to parameters to efficiently prevent name collisions + let p_create_state_request = create_state_request; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/state", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - let local_var_uri_str = format!("{}/state", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - local_var_req_builder = local_var_req_builder.json(&create_state_request); + req_builder = req_builder.json(&p_create_state_request); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + if !status.is_client_error() && !status.is_server_error() { Ok(()) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } pub fn get_state(configuration: &configuration::Configuration, ) -> Result> { - let local_var_configuration = configuration; - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/state", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + let uri_str = format!("{}/state", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/others/rust/reqwest/emptyObject/src/apis/default_api.rs b/samples/client/others/rust/reqwest/emptyObject/src/apis/default_api.rs index 54b21d9c0766f..6b5803fd24232 100644 --- a/samples/client/others/rust/reqwest/emptyObject/src/apis/default_api.rs +++ b/samples/client/others/rust/reqwest/emptyObject/src/apis/default_api.rs @@ -24,30 +24,26 @@ pub enum EndpointGetError { pub fn endpoint_get(configuration: &configuration::Configuration, ) -> Result> { - let local_var_configuration = configuration; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/endpoint", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - let local_var_uri_str = format!("{}/endpoint", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/others/rust/reqwest/oneOf-array-map/src/apis/default_api.rs b/samples/client/others/rust/reqwest/oneOf-array-map/src/apis/default_api.rs index 9fc93a60045b4..d7fbf92af0ad3 100644 --- a/samples/client/others/rust/reqwest/oneOf-array-map/src/apis/default_api.rs +++ b/samples/client/others/rust/reqwest/oneOf-array-map/src/apis/default_api.rs @@ -31,58 +31,52 @@ pub enum TestError { pub fn root_get(configuration: &configuration::Configuration, ) -> Result> { - let local_var_configuration = configuration; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - let local_var_uri_str = format!("{}/", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } pub fn test(configuration: &configuration::Configuration, body: Option) -> Result<(), Error> { - let local_var_configuration = configuration; - - let local_var_client = &local_var_configuration.client; + // add a prefix to parameters to efficiently prevent name collisions + let p_body = body; - let local_var_uri_str = format!("{}/", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str()); + let uri_str = format!("{}/", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - local_var_req_builder = local_var_req_builder.json(&body); + req_builder = req_builder.json(&p_body); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + if !status.is_client_error() && !status.is_server_error() { Ok(()) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/others/rust/reqwest/oneOf-reuseRef/src/apis/default_api.rs b/samples/client/others/rust/reqwest/oneOf-reuseRef/src/apis/default_api.rs index 3287c9177b3e8..3dceb3f7d0400 100644 --- a/samples/client/others/rust/reqwest/oneOf-reuseRef/src/apis/default_api.rs +++ b/samples/client/others/rust/reqwest/oneOf-reuseRef/src/apis/default_api.rs @@ -24,30 +24,26 @@ pub enum GetFruitError { pub fn get_fruit(configuration: &configuration::Configuration, ) -> Result> { - let local_var_configuration = configuration; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/example", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - let local_var_uri_str = format!("{}/example", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/others/rust/reqwest/oneOf/src/apis/bar_api.rs b/samples/client/others/rust/reqwest/oneOf/src/apis/bar_api.rs index fc6b75d5ebcd1..6af94c62e4428 100644 --- a/samples/client/others/rust/reqwest/oneOf/src/apis/bar_api.rs +++ b/samples/client/others/rust/reqwest/oneOf/src/apis/bar_api.rs @@ -24,31 +24,29 @@ pub enum CreateBarError { pub fn create_bar(configuration: &configuration::Configuration, bar_create: models::BarCreate) -> Result> { - let local_var_configuration = configuration; + // add a prefix to parameters to efficiently prevent name collisions + let p_bar_create = bar_create; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/bar", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - let local_var_uri_str = format!("{}/bar", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - local_var_req_builder = local_var_req_builder.json(&bar_create); + req_builder = req_builder.json(&p_bar_create); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/others/rust/reqwest/oneOf/src/apis/foo_api.rs b/samples/client/others/rust/reqwest/oneOf/src/apis/foo_api.rs index cdcd1feaf2a50..8fefb3f459043 100644 --- a/samples/client/others/rust/reqwest/oneOf/src/apis/foo_api.rs +++ b/samples/client/others/rust/reqwest/oneOf/src/apis/foo_api.rs @@ -31,59 +31,53 @@ pub enum GetAllFoosError { pub fn create_foo(configuration: &configuration::Configuration, foo: Option) -> Result> { - let local_var_configuration = configuration; + // add a prefix to parameters to efficiently prevent name collisions + let p_foo = foo; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/foo", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - let local_var_uri_str = format!("{}/foo", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - local_var_req_builder = local_var_req_builder.json(&foo); + req_builder = req_builder.json(&p_foo); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } pub fn get_all_foos(configuration: &configuration::Configuration, ) -> Result, Error> { - let local_var_configuration = configuration; - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/foo", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + let uri_str = format!("{}/foo", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/petstore/rust/hyper/petstore/docs/FakeApi.md b/samples/client/petstore/rust/hyper/petstore/docs/FakeApi.md index 09041c0cbe07e..7f8beb91115bd 100644 --- a/samples/client/petstore/rust/hyper/petstore/docs/FakeApi.md +++ b/samples/client/petstore/rust/hyper/petstore/docs/FakeApi.md @@ -10,7 +10,7 @@ Method | HTTP request | Description ## test_nullable_required_param -> test_nullable_required_param(user_name, dummy_required_nullable_param, uppercase) +> test_nullable_required_param(user_name, dummy_required_nullable_param, uppercase, content) To test nullable required parameters @@ -23,6 +23,7 @@ Name | Type | Description | Required | Notes **user_name** | **String** | The name that needs to be fetched. Use user1 for testing. | [required] | **dummy_required_nullable_param** | Option<**String**> | To test nullable required parameters | [required] | **uppercase** | Option<**String**> | To test parameter names in upper case | | +**content** | Option<**String**> | To test escaping of parameters in rust code works | | ### Return type diff --git a/samples/client/petstore/rust/hyper/petstore/src/apis/fake_api.rs b/samples/client/petstore/rust/hyper/petstore/src/apis/fake_api.rs index 7dfa43037fd87..b1e78f2c5f5ad 100644 --- a/samples/client/petstore/rust/hyper/petstore/src/apis/fake_api.rs +++ b/samples/client/petstore/rust/hyper/petstore/src/apis/fake_api.rs @@ -37,15 +37,19 @@ impl FakeApiClient } pub trait FakeApi: Send + Sync { - fn test_nullable_required_param(&self, user_name: &str, dummy_required_nullable_param: Option<&str>, uppercase: Option<&str>) -> Pin> + Send>>; + fn test_nullable_required_param(&self, user_name: &str, dummy_required_nullable_param: Option<&str>, uppercase: Option<&str>, content: Option<&str>) -> Pin> + Send>>; } implFakeApi for FakeApiClient where C: Clone + std::marker::Send + Sync { #[allow(unused_mut)] - fn test_nullable_required_param(&self, user_name: &str, dummy_required_nullable_param: Option<&str>, uppercase: Option<&str>) -> Pin> + Send>> { + fn test_nullable_required_param(&self, user_name: &str, dummy_required_nullable_param: Option<&str>, uppercase: Option<&str>, content: Option<&str>) -> Pin> + Send>> { let mut req = __internal_request::Request::new(hyper::Method::GET, "/fake/user/{user_name}".to_string()) ; + if let Some(ref s) = content { + let query_value = s.to_string(); + req = req.with_query_param("content".to_string(), query_value); + } req = req.with_path_param("user_name".to_string(), user_name.to_string()); match dummy_required_nullable_param { Some(param_value) => { req = req.with_header_param("dummy_required_nullable_param".to_string(), param_value.to_string()); }, diff --git a/samples/client/petstore/rust/hyper/petstore/tests/thread_test.rs b/samples/client/petstore/rust/hyper/petstore/tests/thread_test.rs index c61cc37b1a04b..8329988a18bf6 100644 --- a/samples/client/petstore/rust/hyper/petstore/tests/thread_test.rs +++ b/samples/client/petstore/rust/hyper/petstore/tests/thread_test.rs @@ -9,7 +9,9 @@ mod tests { let client = APIClient::new(Configuration::new()); let handle = thread::spawn(move || { - let _ = client.fake_api().test_nullable_required_param("username", None, None); + let _ = client + .fake_api() + .test_nullable_required_param("username", None, None, None); }); handle.join().expect("Thread panicked!"); diff --git a/samples/client/petstore/rust/hyper0x/petstore/docs/FakeApi.md b/samples/client/petstore/rust/hyper0x/petstore/docs/FakeApi.md index 7fd650381887e..c41f7d7b0e2fe 100644 --- a/samples/client/petstore/rust/hyper0x/petstore/docs/FakeApi.md +++ b/samples/client/petstore/rust/hyper0x/petstore/docs/FakeApi.md @@ -10,7 +10,7 @@ Method | HTTP request | Description ## test_nullable_required_param -> test_nullable_required_param(user_name, dummy_required_nullable_param, uppercase) +> test_nullable_required_param(user_name, dummy_required_nullable_param, uppercase, content) To test nullable required parameters @@ -23,6 +23,7 @@ Name | Type | Description | Required | Notes **user_name** | **String** | The name that needs to be fetched. Use user1 for testing. | [required] | **dummy_required_nullable_param** | Option<**String**> | To test nullable required parameters | [required] | **uppercase** | Option<**String**> | To test parameter names in upper case | | +**content** | Option<**String**> | To test escaping of parameters in rust code works | | ### Return type diff --git a/samples/client/petstore/rust/hyper0x/petstore/src/apis/fake_api.rs b/samples/client/petstore/rust/hyper0x/petstore/src/apis/fake_api.rs index 51fb1df2665c2..12a59925332f2 100644 --- a/samples/client/petstore/rust/hyper0x/petstore/src/apis/fake_api.rs +++ b/samples/client/petstore/rust/hyper0x/petstore/src/apis/fake_api.rs @@ -36,15 +36,19 @@ impl FakeApiClient } pub trait FakeApi { - fn test_nullable_required_param(&self, user_name: &str, dummy_required_nullable_param: Option<&str>, uppercase: Option<&str>) -> Pin>>>; + fn test_nullable_required_param(&self, user_name: &str, dummy_required_nullable_param: Option<&str>, uppercase: Option<&str>, content: Option<&str>) -> Pin>>>; } implFakeApi for FakeApiClient where C: Clone + std::marker::Send + Sync { #[allow(unused_mut)] - fn test_nullable_required_param(&self, user_name: &str, dummy_required_nullable_param: Option<&str>, uppercase: Option<&str>) -> Pin>>> { + fn test_nullable_required_param(&self, user_name: &str, dummy_required_nullable_param: Option<&str>, uppercase: Option<&str>, content: Option<&str>) -> Pin>>> { let mut req = __internal_request::Request::new(hyper::Method::GET, "/fake/user/{user_name}".to_string()) ; + if let Some(ref s) = content { + let query_value = s.to_string(); + req = req.with_query_param("content".to_string(), query_value); + } req = req.with_path_param("user_name".to_string(), user_name.to_string()); match dummy_required_nullable_param { Some(param_value) => { req = req.with_header_param("dummy_required_nullable_param".to_string(), param_value.to_string()); }, diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/docs/FakeApi.md b/samples/client/petstore/rust/reqwest-trait/petstore/docs/FakeApi.md index 7fd650381887e..c41f7d7b0e2fe 100644 --- a/samples/client/petstore/rust/reqwest-trait/petstore/docs/FakeApi.md +++ b/samples/client/petstore/rust/reqwest-trait/petstore/docs/FakeApi.md @@ -10,7 +10,7 @@ Method | HTTP request | Description ## test_nullable_required_param -> test_nullable_required_param(user_name, dummy_required_nullable_param, uppercase) +> test_nullable_required_param(user_name, dummy_required_nullable_param, uppercase, content) To test nullable required parameters @@ -23,6 +23,7 @@ Name | Type | Description | Required | Notes **user_name** | **String** | The name that needs to be fetched. Use user1 for testing. | [required] | **dummy_required_nullable_param** | Option<**String**> | To test nullable required parameters | [required] | **uppercase** | Option<**String**> | To test parameter names in upper case | | +**content** | Option<**String**> | To test escaping of parameters in rust code works | | ### Return type diff --git a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/fake_api.rs b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/fake_api.rs index 0dbbec22aeca0..84ba5cf66b41b 100644 --- a/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/fake_api.rs +++ b/samples/client/petstore/rust/reqwest-trait/petstore/src/apis/fake_api.rs @@ -21,7 +21,7 @@ use super::{Error, configuration}; #[cfg_attr(feature = "mockall", automock)] #[async_trait] pub trait FakeApi: Send + Sync { - async fn test_nullable_required_param<'user_name, 'dummy_required_nullable_param, 'uppercase>(&self, user_name: &'user_name str, dummy_required_nullable_param: Option<&'dummy_required_nullable_param str>, uppercase: Option<&'uppercase str>) -> Result<(), Error>; + async fn test_nullable_required_param<'user_name, 'dummy_required_nullable_param, 'uppercase, 'content>(&self, user_name: &'user_name str, dummy_required_nullable_param: Option<&'dummy_required_nullable_param str>, uppercase: Option<&'uppercase str>, content: Option<&'content str>) -> Result<(), Error>; } pub struct FakeApiClient { @@ -39,7 +39,7 @@ impl FakeApiClient { #[async_trait] impl FakeApi for FakeApiClient { /// - async fn test_nullable_required_param<'user_name, 'dummy_required_nullable_param, 'uppercase>(&self, user_name: &'user_name str, dummy_required_nullable_param: Option<&'dummy_required_nullable_param str>, uppercase: Option<&'uppercase str>) -> Result<(), Error> { + async fn test_nullable_required_param<'user_name, 'dummy_required_nullable_param, 'uppercase, 'content>(&self, user_name: &'user_name str, dummy_required_nullable_param: Option<&'dummy_required_nullable_param str>, uppercase: Option<&'uppercase str>, content: Option<&'content str>) -> Result<(), Error> { let local_var_configuration = &self.configuration; let local_var_client = &local_var_configuration.client; @@ -47,6 +47,9 @@ impl FakeApi for FakeApiClient { let local_var_uri_str = format!("{}/fake/user/{user_name}", local_var_configuration.base_path, user_name=crate::apis::urlencode(user_name)); let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + if let Some(ref local_var_str) = content { + local_var_req_builder = local_var_req_builder.query(&[("content", &local_var_str.to_string())]); + } if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); } diff --git a/samples/client/petstore/rust/reqwest/name-mapping/src/apis/fake_api.rs b/samples/client/petstore/rust/reqwest/name-mapping/src/apis/fake_api.rs index 1dd40a13d980b..7e45b087616cc 100644 --- a/samples/client/petstore/rust/reqwest/name-mapping/src/apis/fake_api.rs +++ b/samples/client/petstore/rust/reqwest/name-mapping/src/apis/fake_api.rs @@ -24,34 +24,36 @@ pub enum GetParameterNameMappingError { pub fn get_parameter_name_mapping(configuration: &configuration::Configuration, underscore_type: i64, r#type: &str, type_with_underscore: &str, dash_type: &str, http_debug_option: &str) -> Result<(), Error> { - let local_var_configuration = configuration; - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/fake/parameter-name-mapping", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - local_var_req_builder = local_var_req_builder.query(&[("type", &r#type.to_string())]); - local_var_req_builder = local_var_req_builder.query(&[("http_debug_option", &http_debug_option.to_string())]); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + // add a prefix to parameters to efficiently prevent name collisions + let p_underscore_type = underscore_type; + let p_type = r#type; + let p_type_with_underscore = type_with_underscore; + let p_dash_type = dash_type; + let p_http_debug_option = http_debug_option; + + let uri_str = format!("{}/fake/parameter-name-mapping", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); + + req_builder = req_builder.query(&[("type", &p_type.to_string())]); + req_builder = req_builder.query(&[("http_debug_option", &p_http_debug_option.to_string())]); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - local_var_req_builder = local_var_req_builder.header("_type", underscore_type.to_string()); - local_var_req_builder = local_var_req_builder.header("type_", type_with_underscore.to_string()); - local_var_req_builder = local_var_req_builder.header("-type", dash_type.to_string()); + req_builder = req_builder.header("_type", p_underscore_type.to_string()); + req_builder = req_builder.header("type_", p_type_with_underscore.to_string()); + req_builder = req_builder.header("-type", p_dash_type.to_string()); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + if !status.is_client_error() && !status.is_server_error() { Ok(()) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/petstore/rust/reqwest/petstore-async-middleware/docs/FakeApi.md b/samples/client/petstore/rust/reqwest/petstore-async-middleware/docs/FakeApi.md index 7fd650381887e..c41f7d7b0e2fe 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-middleware/docs/FakeApi.md +++ b/samples/client/petstore/rust/reqwest/petstore-async-middleware/docs/FakeApi.md @@ -10,7 +10,7 @@ Method | HTTP request | Description ## test_nullable_required_param -> test_nullable_required_param(user_name, dummy_required_nullable_param, uppercase) +> test_nullable_required_param(user_name, dummy_required_nullable_param, uppercase, content) To test nullable required parameters @@ -23,6 +23,7 @@ Name | Type | Description | Required | Notes **user_name** | **String** | The name that needs to be fetched. Use user1 for testing. | [required] | **dummy_required_nullable_param** | Option<**String**> | To test nullable required parameters | [required] | **uppercase** | Option<**String**> | To test parameter names in upper case | | +**content** | Option<**String**> | To test escaping of parameters in rust code works | | ### Return type diff --git a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/fake_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/fake_api.rs index 5a06ed6f11989..dbc4858a0eedd 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/fake_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/fake_api.rs @@ -22,7 +22,9 @@ pub struct TestNullableRequiredParamParams { /// To test nullable required parameters pub dummy_required_nullable_param: Option, /// To test parameter names in upper case - pub uppercase: Option + pub uppercase: Option, + /// To test escaping of parameters in rust code works + pub content: Option } @@ -46,45 +48,37 @@ pub enum TestNullableRequiredParamError { /// pub async fn test_nullable_required_param(configuration: &configuration::Configuration, params: TestNullableRequiredParamParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let user_name = params.user_name; - let dummy_required_nullable_param = params.dummy_required_nullable_param; - let uppercase = params.uppercase; + let uri_str = format!("{}/fake/user/{user_name}", configuration.base_path, user_name=crate::apis::urlencode(params.user_name)); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/fake/user/{user_name}", local_var_configuration.base_path, user_name=crate::apis::urlencode(user_name)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref param_value) = params.content { + req_builder = req_builder.query(&[("content", ¶m_value.to_string())]); + } + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - match dummy_required_nullable_param { - Some(local_var_param_value) => { local_var_req_builder = local_var_req_builder.header("dummy_required_nullable_param", local_var_param_value.to_string()); }, - None => { local_var_req_builder = local_var_req_builder.header("dummy_required_nullable_param", ""); }, + match params.dummy_required_nullable_param { + Some(param_value) => { req_builder = req_builder.header("dummy_required_nullable_param", param_value.to_string()); }, + None => { req_builder = req_builder.header("dummy_required_nullable_param", ""); }, } - if let Some(local_var_param_value) = uppercase { - local_var_req_builder = local_var_req_builder.header("UPPERCASE", local_var_param_value.to_string()); + if let Some(param_value) = params.uppercase { + req_builder = req_builder.header("UPPERCASE", param_value.to_string()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/pet_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/pet_api.rs index 9711d3819bce1..61a60d15904ff 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/pet_api.rs @@ -213,349 +213,271 @@ pub enum UploadFileError { /// pub async fn add_pet(configuration: &configuration::Configuration, params: AddPetParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let pet = params.pet; + let uri_str = format!("{}/pet", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/pet", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - local_var_req_builder = local_var_req_builder.json(&pet); + req_builder = req_builder.json(¶ms.pet); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn delete_pet(configuration: &configuration::Configuration, params: DeletePetParams) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - let pet_id = params.pet_id; - let api_key = params.api_key; - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/pet/{petId}", local_var_configuration.base_path, petId=pet_id); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str()); + let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=params.pet_id); + let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(local_var_param_value) = api_key { - local_var_req_builder = local_var_req_builder.header("api_key", local_var_param_value.to_string()); + if let Some(param_value) = params.api_key { + req_builder = req_builder.header("api_key", param_value.to_string()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// Multiple status values can be provided with comma separated strings pub async fn find_pets_by_status(configuration: &configuration::Configuration, params: FindPetsByStatusParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let status = params.status; - let r#type = params.r#type; + let uri_str = format!("{}/pet/findByStatus", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/pet/findByStatus", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - local_var_req_builder = match "csv" { - "multi" => local_var_req_builder.query(&status.into_iter().map(|p| ("status".to_owned(), p.to_string())).collect::>()), - _ => local_var_req_builder.query(&[("status", &status.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), + req_builder = match "csv" { + "multi" => req_builder.query(¶ms.status.into_iter().map(|p| ("status".to_owned(), p.to_string())).collect::>()), + _ => req_builder.query(&[("status", ¶ms.status.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), }; - if let Some(ref local_var_str) = r#type { - local_var_req_builder = match "csv" { - "multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("type".to_owned(), p.to_string())).collect::>()), - _ => local_var_req_builder.query(&[("type", &local_var_str.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), + if let Some(ref param_value) = params.r#type { + req_builder = match "csv" { + "multi" => req_builder.query(¶m_value.into_iter().map(|p| ("type".to_owned(), p.to_string())).collect::>()), + _ => req_builder.query(&[("type", ¶m_value.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), }; } - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. pub async fn find_pets_by_tags(configuration: &configuration::Configuration, params: FindPetsByTagsParams) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - let tags = params.tags; - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/pet/findByTags", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + let uri_str = format!("{}/pet/findByTags", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - local_var_req_builder = match "csv" { - "multi" => local_var_req_builder.query(&tags.into_iter().map(|p| ("tags".to_owned(), p.to_string())).collect::>()), - _ => local_var_req_builder.query(&[("tags", &tags.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), + req_builder = match "csv" { + "multi" => req_builder.query(¶ms.tags.into_iter().map(|p| ("tags".to_owned(), p.to_string())).collect::>()), + _ => req_builder.query(&[("tags", ¶ms.tags.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), }; - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// Returns a single pet pub async fn get_pet_by_id(configuration: &configuration::Configuration, params: GetPetByIdParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let pet_id = params.pet_id; + let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=params.pet_id); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/pet/{petId}", local_var_configuration.base_path, petId=pet_id); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn update_pet(configuration: &configuration::Configuration, params: UpdatePetParams) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - let pet = params.pet; - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/pet", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str()); + let uri_str = format!("{}/pet", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - local_var_req_builder = local_var_req_builder.json(&pet); + req_builder = req_builder.json(¶ms.pet); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn update_pet_with_form(configuration: &configuration::Configuration, params: UpdatePetWithFormParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let pet_id = params.pet_id; - let name = params.name; - let status = params.status; + let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=params.pet_id); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/pet/{petId}", local_var_configuration.base_path, petId=pet_id); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - let mut local_var_form_params = std::collections::HashMap::new(); - if let Some(local_var_param_value) = name { - local_var_form_params.insert("name", local_var_param_value.to_string()); + let mut multipart_form_params = std::collections::HashMap::new(); + if let Some(param_value) = params.name { + multipart_form_params.insert("name", param_value.to_string()); } - if let Some(local_var_param_value) = status { - local_var_form_params.insert("status", local_var_param_value.to_string()); + if let Some(param_value) = params.status { + multipart_form_params.insert("status", param_value.to_string()); } - local_var_req_builder = local_var_req_builder.form(&local_var_form_params); + req_builder = req_builder.form(&multipart_form_params); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn upload_file(configuration: &configuration::Configuration, params: UploadFileParams) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - let pet_id = params.pet_id; - let additional_metadata = params.additional_metadata; - let file = params.file; - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/pet/{petId}/uploadImage", local_var_configuration.base_path, petId=pet_id); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + let uri_str = format!("{}/pet/{petId}/uploadImage", configuration.base_path, petId=params.pet_id); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - let mut local_var_form = reqwest::multipart::Form::new(); - if let Some(local_var_param_value) = additional_metadata { - local_var_form = local_var_form.text("additionalMetadata", local_var_param_value.to_string()); + let mut multipart_form = reqwest::multipart::Form::new(); + if let Some(param_value) = params.additional_metadata { + multipart_form = multipart_form.text("additionalMetadata", param_value.to_string()); } // TODO: support file upload for 'file' parameter - local_var_req_builder = local_var_req_builder.multipart(local_var_form); + req_builder = req_builder.multipart(multipart_form); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/store_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/store_api.rs index 340e6f2dc97cc..17760b176768c 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/store_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/store_api.rs @@ -103,149 +103,114 @@ pub enum PlaceOrderError { /// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors pub async fn delete_order(configuration: &configuration::Configuration, params: DeleteOrderParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let order_id = params.order_id; + let uri_str = format!("{}/store/order/{orderId}", configuration.base_path, orderId=crate::apis::urlencode(params.order_id)); + let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/store/order/{orderId}", local_var_configuration.base_path, orderId=crate::apis::urlencode(order_id)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// Returns a map of status codes to quantities pub async fn get_inventory(configuration: &configuration::Configuration) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/store/inventory", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + let uri_str = format!("{}/store/inventory", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions pub async fn get_order_by_id(configuration: &configuration::Configuration, params: GetOrderByIdParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let order_id = params.order_id; + let uri_str = format!("{}/store/order/{orderId}", configuration.base_path, orderId=params.order_id); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/store/order/{orderId}", local_var_configuration.base_path, orderId=order_id); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn place_order(configuration: &configuration::Configuration, params: PlaceOrderParams) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - let order = params.order; - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/store/order", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + let uri_str = format!("{}/store/order", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - local_var_req_builder = local_var_req_builder.json(&order); + req_builder = req_builder.json(¶ms.order); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/testing_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/testing_api.rs index 0dafccec4b728..3f365095bf634 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/testing_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/testing_api.rs @@ -47,65 +47,50 @@ pub enum TestsTypeTestingGetError { pub async fn tests_file_response_get(configuration: &configuration::Configuration) -> Result> { - let local_var_configuration = configuration; - // unbox the parameters + let uri_str = format!("{}/tests/fileResponse", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/tests/fileResponse", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { - Ok(local_var_resp) + if !status.is_client_error() && !status.is_server_error() { + Ok(resp) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } pub async fn tests_type_testing_get(configuration: &configuration::Configuration) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/tests/typeTesting", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + let uri_str = format!("{}/tests/typeTesting", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/user_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/user_api.rs index 985f3b65e3173..e4dfae546d4cc 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/user_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-middleware/src/apis/user_api.rs @@ -196,336 +196,263 @@ pub enum UpdateUserError { /// This can only be done by the logged in user. pub async fn create_user(configuration: &configuration::Configuration, params: CreateUserParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let user = params.user; + let uri_str = format!("{}/user", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/user", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - local_var_req_builder = local_var_req_builder.json(&user); + req_builder = req_builder.json(¶ms.user); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn create_users_with_array_input(configuration: &configuration::Configuration, params: CreateUsersWithArrayInputParams) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - let user = params.user; - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/user/createWithArray", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + let uri_str = format!("{}/user/createWithArray", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - local_var_req_builder = local_var_req_builder.json(&user); + req_builder = req_builder.json(¶ms.user); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn create_users_with_list_input(configuration: &configuration::Configuration, params: CreateUsersWithListInputParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let user = params.user; + let uri_str = format!("{}/user/createWithList", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/user/createWithList", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - local_var_req_builder = local_var_req_builder.json(&user); + req_builder = req_builder.json(¶ms.user); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// This can only be done by the logged in user. pub async fn delete_user(configuration: &configuration::Configuration, params: DeleteUserParams) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - let username = params.username; - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/user/{username}", local_var_configuration.base_path, username=crate::apis::urlencode(username)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str()); + let uri_str = format!("{}/user/{username}", configuration.base_path, username=crate::apis::urlencode(params.username)); + let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn get_user_by_name(configuration: &configuration::Configuration, params: GetUserByNameParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let username = params.username; + let uri_str = format!("{}/user/{username}", configuration.base_path, username=crate::apis::urlencode(params.username)); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/user/{username}", local_var_configuration.base_path, username=crate::apis::urlencode(username)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn login_user(configuration: &configuration::Configuration, params: LoginUserParams) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - let username = params.username; - let password = params.password; - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/user/login", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + let uri_str = format!("{}/user/login", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - local_var_req_builder = local_var_req_builder.query(&[("username", &username.to_string())]); - local_var_req_builder = local_var_req_builder.query(&[("password", &password.to_string())]); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + req_builder = req_builder.query(&[("username", ¶ms.username.to_string())]); + req_builder = req_builder.query(&[("password", ¶ms.password.to_string())]); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn logout_user(configuration: &configuration::Configuration) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters + let uri_str = format!("{}/user/logout", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/user/logout", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// This can only be done by the logged in user. pub async fn update_user(configuration: &configuration::Configuration, params: UpdateUserParams) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - let username = params.username; - let user = params.user; - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/user/{username}", local_var_configuration.base_path, username=crate::apis::urlencode(username)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str()); + let uri_str = format!("{}/user/{username}", configuration.base_path, username=crate::apis::urlencode(params.username)); + let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - local_var_req_builder = local_var_req_builder.json(&user); + req_builder = req_builder.json(¶ms.user); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/docs/FakeApi.md b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/docs/FakeApi.md index 7fd650381887e..c41f7d7b0e2fe 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/docs/FakeApi.md +++ b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/docs/FakeApi.md @@ -10,7 +10,7 @@ Method | HTTP request | Description ## test_nullable_required_param -> test_nullable_required_param(user_name, dummy_required_nullable_param, uppercase) +> test_nullable_required_param(user_name, dummy_required_nullable_param, uppercase, content) To test nullable required parameters @@ -23,6 +23,7 @@ Name | Type | Description | Required | Notes **user_name** | **String** | The name that needs to be fetched. Use user1 for testing. | [required] | **dummy_required_nullable_param** | Option<**String**> | To test nullable required parameters | [required] | **uppercase** | Option<**String**> | To test parameter names in upper case | | +**content** | Option<**String**> | To test escaping of parameters in rust code works | | ### Return type diff --git a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/fake_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/fake_api.rs index 5a06ed6f11989..dbc4858a0eedd 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/fake_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/fake_api.rs @@ -22,7 +22,9 @@ pub struct TestNullableRequiredParamParams { /// To test nullable required parameters pub dummy_required_nullable_param: Option, /// To test parameter names in upper case - pub uppercase: Option + pub uppercase: Option, + /// To test escaping of parameters in rust code works + pub content: Option } @@ -46,45 +48,37 @@ pub enum TestNullableRequiredParamError { /// pub async fn test_nullable_required_param(configuration: &configuration::Configuration, params: TestNullableRequiredParamParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let user_name = params.user_name; - let dummy_required_nullable_param = params.dummy_required_nullable_param; - let uppercase = params.uppercase; + let uri_str = format!("{}/fake/user/{user_name}", configuration.base_path, user_name=crate::apis::urlencode(params.user_name)); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/fake/user/{user_name}", local_var_configuration.base_path, user_name=crate::apis::urlencode(user_name)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref param_value) = params.content { + req_builder = req_builder.query(&[("content", ¶m_value.to_string())]); + } + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - match dummy_required_nullable_param { - Some(local_var_param_value) => { local_var_req_builder = local_var_req_builder.header("dummy_required_nullable_param", local_var_param_value.to_string()); }, - None => { local_var_req_builder = local_var_req_builder.header("dummy_required_nullable_param", ""); }, + match params.dummy_required_nullable_param { + Some(param_value) => { req_builder = req_builder.header("dummy_required_nullable_param", param_value.to_string()); }, + None => { req_builder = req_builder.header("dummy_required_nullable_param", ""); }, } - if let Some(local_var_param_value) = uppercase { - local_var_req_builder = local_var_req_builder.header("UPPERCASE", local_var_param_value.to_string()); + if let Some(param_value) = params.uppercase { + req_builder = req_builder.header("UPPERCASE", param_value.to_string()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/pet_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/pet_api.rs index 45676bd822626..3f9d6c48db5cd 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/pet_api.rs @@ -213,360 +213,282 @@ pub enum UploadFileError { /// pub async fn add_pet(configuration: &configuration::Configuration, params: AddPetParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let pet = params.pet; + let uri_str = format!("{}/pet", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/pet", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } // Obtain a token from source provider. // Tokens can be Id or access tokens depending on the provider type and configuration. - let token = local_var_configuration.token_source.token().await.map_err(Error::TokenSource)?; + let token = configuration.token_source.token().await.map_err(Error::TokenSource)?; // The token format is the responsibility of the provider, thus we just set the authorization header with whatever is given. - local_var_req_builder = local_var_req_builder.header(reqwest::header::AUTHORIZATION, token); - local_var_req_builder = local_var_req_builder.json(&pet); + req_builder = req_builder.header(reqwest::header::AUTHORIZATION, token); + req_builder = req_builder.json(¶ms.pet); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn delete_pet(configuration: &configuration::Configuration, params: DeletePetParams) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - let pet_id = params.pet_id; - let api_key = params.api_key; - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/pet/{petId}", local_var_configuration.base_path, petId=pet_id); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str()); + let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=params.pet_id); + let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(local_var_param_value) = api_key { - local_var_req_builder = local_var_req_builder.header("api_key", local_var_param_value.to_string()); + if let Some(param_value) = params.api_key { + req_builder = req_builder.header("api_key", param_value.to_string()); } // Obtain a token from source provider. // Tokens can be Id or access tokens depending on the provider type and configuration. - let token = local_var_configuration.token_source.token().await.map_err(Error::TokenSource)?; + let token = configuration.token_source.token().await.map_err(Error::TokenSource)?; // The token format is the responsibility of the provider, thus we just set the authorization header with whatever is given. - local_var_req_builder = local_var_req_builder.header(reqwest::header::AUTHORIZATION, token); + req_builder = req_builder.header(reqwest::header::AUTHORIZATION, token); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// Multiple status values can be provided with comma separated strings pub async fn find_pets_by_status(configuration: &configuration::Configuration, params: FindPetsByStatusParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let status = params.status; - let r#type = params.r#type; + let uri_str = format!("{}/pet/findByStatus", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/pet/findByStatus", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - local_var_req_builder = match "csv" { - "multi" => local_var_req_builder.query(&status.into_iter().map(|p| ("status".to_owned(), p.to_string())).collect::>()), - _ => local_var_req_builder.query(&[("status", &status.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), + req_builder = match "csv" { + "multi" => req_builder.query(¶ms.status.into_iter().map(|p| ("status".to_owned(), p.to_string())).collect::>()), + _ => req_builder.query(&[("status", ¶ms.status.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), }; - if let Some(ref local_var_str) = r#type { - local_var_req_builder = match "csv" { - "multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("type".to_owned(), p.to_string())).collect::>()), - _ => local_var_req_builder.query(&[("type", &local_var_str.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), + if let Some(ref param_value) = params.r#type { + req_builder = match "csv" { + "multi" => req_builder.query(¶m_value.into_iter().map(|p| ("type".to_owned(), p.to_string())).collect::>()), + _ => req_builder.query(&[("type", ¶m_value.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), }; } - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } // Obtain a token from source provider. // Tokens can be Id or access tokens depending on the provider type and configuration. - let token = local_var_configuration.token_source.token().await.map_err(Error::TokenSource)?; + let token = configuration.token_source.token().await.map_err(Error::TokenSource)?; // The token format is the responsibility of the provider, thus we just set the authorization header with whatever is given. - local_var_req_builder = local_var_req_builder.header(reqwest::header::AUTHORIZATION, token); + req_builder = req_builder.header(reqwest::header::AUTHORIZATION, token); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. pub async fn find_pets_by_tags(configuration: &configuration::Configuration, params: FindPetsByTagsParams) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - let tags = params.tags; - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/pet/findByTags", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + let uri_str = format!("{}/pet/findByTags", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - local_var_req_builder = match "csv" { - "multi" => local_var_req_builder.query(&tags.into_iter().map(|p| ("tags".to_owned(), p.to_string())).collect::>()), - _ => local_var_req_builder.query(&[("tags", &tags.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), + req_builder = match "csv" { + "multi" => req_builder.query(¶ms.tags.into_iter().map(|p| ("tags".to_owned(), p.to_string())).collect::>()), + _ => req_builder.query(&[("tags", ¶ms.tags.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), }; - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } // Obtain a token from source provider. // Tokens can be Id or access tokens depending on the provider type and configuration. - let token = local_var_configuration.token_source.token().await.map_err(Error::TokenSource)?; + let token = configuration.token_source.token().await.map_err(Error::TokenSource)?; // The token format is the responsibility of the provider, thus we just set the authorization header with whatever is given. - local_var_req_builder = local_var_req_builder.header(reqwest::header::AUTHORIZATION, token); + req_builder = req_builder.header(reqwest::header::AUTHORIZATION, token); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// Returns a single pet pub async fn get_pet_by_id(configuration: &configuration::Configuration, params: GetPetByIdParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let pet_id = params.pet_id; + let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=params.pet_id); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/pet/{petId}", local_var_configuration.base_path, petId=pet_id); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } // Obtain a token from source provider. // Tokens can be Id or access tokens depending on the provider type and configuration. - let token = local_var_configuration.token_source.token().await.map_err(Error::TokenSource)?; + let token = configuration.token_source.token().await.map_err(Error::TokenSource)?; // The token format is the responsibility of the provider, thus we just set the authorization header with whatever is given. - local_var_req_builder = local_var_req_builder.header(reqwest::header::AUTHORIZATION, token); + req_builder = req_builder.header(reqwest::header::AUTHORIZATION, token); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn update_pet(configuration: &configuration::Configuration, params: UpdatePetParams) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - let pet = params.pet; - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/pet", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str()); + let uri_str = format!("{}/pet", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } // Obtain a token from source provider. // Tokens can be Id or access tokens depending on the provider type and configuration. - let token = local_var_configuration.token_source.token().await.map_err(Error::TokenSource)?; + let token = configuration.token_source.token().await.map_err(Error::TokenSource)?; // The token format is the responsibility of the provider, thus we just set the authorization header with whatever is given. - local_var_req_builder = local_var_req_builder.header(reqwest::header::AUTHORIZATION, token); - local_var_req_builder = local_var_req_builder.json(&pet); + req_builder = req_builder.header(reqwest::header::AUTHORIZATION, token); + req_builder = req_builder.json(¶ms.pet); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn update_pet_with_form(configuration: &configuration::Configuration, params: UpdatePetWithFormParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let pet_id = params.pet_id; - let name = params.name; - let status = params.status; + let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=params.pet_id); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/pet/{petId}", local_var_configuration.base_path, petId=pet_id); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } // Obtain a token from source provider. // Tokens can be Id or access tokens depending on the provider type and configuration. - let token = local_var_configuration.token_source.token().await.map_err(Error::TokenSource)?; + let token = configuration.token_source.token().await.map_err(Error::TokenSource)?; // The token format is the responsibility of the provider, thus we just set the authorization header with whatever is given. - local_var_req_builder = local_var_req_builder.header(reqwest::header::AUTHORIZATION, token); - let mut local_var_form_params = std::collections::HashMap::new(); - if let Some(local_var_param_value) = name { - local_var_form_params.insert("name", local_var_param_value.to_string()); + req_builder = req_builder.header(reqwest::header::AUTHORIZATION, token); + let mut multipart_form_params = std::collections::HashMap::new(); + if let Some(param_value) = params.name { + multipart_form_params.insert("name", param_value.to_string()); } - if let Some(local_var_param_value) = status { - local_var_form_params.insert("status", local_var_param_value.to_string()); + if let Some(param_value) = params.status { + multipart_form_params.insert("status", param_value.to_string()); } - local_var_req_builder = local_var_req_builder.form(&local_var_form_params); + req_builder = req_builder.form(&multipart_form_params); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn upload_file(configuration: &configuration::Configuration, params: UploadFileParams) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - let pet_id = params.pet_id; - let additional_metadata = params.additional_metadata; - let file = params.file; - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/pet/{petId}/uploadImage", local_var_configuration.base_path, petId=pet_id); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + let uri_str = format!("{}/pet/{petId}/uploadImage", configuration.base_path, petId=params.pet_id); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } // Obtain a token from source provider. // Tokens can be Id or access tokens depending on the provider type and configuration. - let token = local_var_configuration.token_source.token().await.map_err(Error::TokenSource)?; + let token = configuration.token_source.token().await.map_err(Error::TokenSource)?; // The token format is the responsibility of the provider, thus we just set the authorization header with whatever is given. - local_var_req_builder = local_var_req_builder.header(reqwest::header::AUTHORIZATION, token); - let mut local_var_form = reqwest::multipart::Form::new(); - if let Some(local_var_param_value) = additional_metadata { - local_var_form = local_var_form.text("additionalMetadata", local_var_param_value.to_string()); + req_builder = req_builder.header(reqwest::header::AUTHORIZATION, token); + let mut multipart_form = reqwest::multipart::Form::new(); + if let Some(param_value) = params.additional_metadata { + multipart_form = multipart_form.text("additionalMetadata", param_value.to_string()); } // TODO: support file upload for 'file' parameter - local_var_req_builder = local_var_req_builder.multipart(local_var_form); + req_builder = req_builder.multipart(multipart_form); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/store_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/store_api.rs index ef3f71dbb9cf9..859e3088916d5 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/store_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/store_api.rs @@ -103,146 +103,111 @@ pub enum PlaceOrderError { /// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors pub async fn delete_order(configuration: &configuration::Configuration, params: DeleteOrderParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let order_id = params.order_id; + let uri_str = format!("{}/store/order/{orderId}", configuration.base_path, orderId=crate::apis::urlencode(params.order_id)); + let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/store/order/{orderId}", local_var_configuration.base_path, orderId=crate::apis::urlencode(order_id)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// Returns a map of status codes to quantities pub async fn get_inventory(configuration: &configuration::Configuration) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/store/inventory", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + let uri_str = format!("{}/store/inventory", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } // Obtain a token from source provider. // Tokens can be Id or access tokens depending on the provider type and configuration. - let token = local_var_configuration.token_source.token().await.map_err(Error::TokenSource)?; + let token = configuration.token_source.token().await.map_err(Error::TokenSource)?; // The token format is the responsibility of the provider, thus we just set the authorization header with whatever is given. - local_var_req_builder = local_var_req_builder.header(reqwest::header::AUTHORIZATION, token); + req_builder = req_builder.header(reqwest::header::AUTHORIZATION, token); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions pub async fn get_order_by_id(configuration: &configuration::Configuration, params: GetOrderByIdParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let order_id = params.order_id; + let uri_str = format!("{}/store/order/{orderId}", configuration.base_path, orderId=params.order_id); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/store/order/{orderId}", local_var_configuration.base_path, orderId=order_id); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn place_order(configuration: &configuration::Configuration, params: PlaceOrderParams) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - let order = params.order; - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/store/order", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + let uri_str = format!("{}/store/order", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - local_var_req_builder = local_var_req_builder.json(&order); + req_builder = req_builder.json(¶ms.order); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/testing_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/testing_api.rs index 0dafccec4b728..3f365095bf634 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/testing_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/testing_api.rs @@ -47,65 +47,50 @@ pub enum TestsTypeTestingGetError { pub async fn tests_file_response_get(configuration: &configuration::Configuration) -> Result> { - let local_var_configuration = configuration; - // unbox the parameters + let uri_str = format!("{}/tests/fileResponse", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/tests/fileResponse", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { - Ok(local_var_resp) + if !status.is_client_error() && !status.is_server_error() { + Ok(resp) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } pub async fn tests_type_testing_get(configuration: &configuration::Configuration) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/tests/typeTesting", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + let uri_str = format!("{}/tests/typeTesting", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/user_api.rs b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/user_api.rs index b5b830ac64a1b..ddfebdf33851d 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/user_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async-tokensource/src/apis/user_api.rs @@ -196,318 +196,245 @@ pub enum UpdateUserError { /// This can only be done by the logged in user. pub async fn create_user(configuration: &configuration::Configuration, params: CreateUserParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let user = params.user; + let uri_str = format!("{}/user", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/user", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } // Obtain a token from source provider. // Tokens can be Id or access tokens depending on the provider type and configuration. - let token = local_var_configuration.token_source.token().await.map_err(Error::TokenSource)?; + let token = configuration.token_source.token().await.map_err(Error::TokenSource)?; // The token format is the responsibility of the provider, thus we just set the authorization header with whatever is given. - local_var_req_builder = local_var_req_builder.header(reqwest::header::AUTHORIZATION, token); - local_var_req_builder = local_var_req_builder.json(&user); + req_builder = req_builder.header(reqwest::header::AUTHORIZATION, token); + req_builder = req_builder.json(¶ms.user); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn create_users_with_array_input(configuration: &configuration::Configuration, params: CreateUsersWithArrayInputParams) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - let user = params.user; - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/user/createWithArray", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + let uri_str = format!("{}/user/createWithArray", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } // Obtain a token from source provider. // Tokens can be Id or access tokens depending on the provider type and configuration. - let token = local_var_configuration.token_source.token().await.map_err(Error::TokenSource)?; + let token = configuration.token_source.token().await.map_err(Error::TokenSource)?; // The token format is the responsibility of the provider, thus we just set the authorization header with whatever is given. - local_var_req_builder = local_var_req_builder.header(reqwest::header::AUTHORIZATION, token); - local_var_req_builder = local_var_req_builder.json(&user); + req_builder = req_builder.header(reqwest::header::AUTHORIZATION, token); + req_builder = req_builder.json(¶ms.user); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn create_users_with_list_input(configuration: &configuration::Configuration, params: CreateUsersWithListInputParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let user = params.user; + let uri_str = format!("{}/user/createWithList", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/user/createWithList", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } // Obtain a token from source provider. // Tokens can be Id or access tokens depending on the provider type and configuration. - let token = local_var_configuration.token_source.token().await.map_err(Error::TokenSource)?; + let token = configuration.token_source.token().await.map_err(Error::TokenSource)?; // The token format is the responsibility of the provider, thus we just set the authorization header with whatever is given. - local_var_req_builder = local_var_req_builder.header(reqwest::header::AUTHORIZATION, token); - local_var_req_builder = local_var_req_builder.json(&user); + req_builder = req_builder.header(reqwest::header::AUTHORIZATION, token); + req_builder = req_builder.json(¶ms.user); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// This can only be done by the logged in user. pub async fn delete_user(configuration: &configuration::Configuration, params: DeleteUserParams) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - let username = params.username; - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/user/{username}", local_var_configuration.base_path, username=crate::apis::urlencode(username)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str()); + let uri_str = format!("{}/user/{username}", configuration.base_path, username=crate::apis::urlencode(params.username)); + let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } // Obtain a token from source provider. // Tokens can be Id or access tokens depending on the provider type and configuration. - let token = local_var_configuration.token_source.token().await.map_err(Error::TokenSource)?; + let token = configuration.token_source.token().await.map_err(Error::TokenSource)?; // The token format is the responsibility of the provider, thus we just set the authorization header with whatever is given. - local_var_req_builder = local_var_req_builder.header(reqwest::header::AUTHORIZATION, token); + req_builder = req_builder.header(reqwest::header::AUTHORIZATION, token); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn get_user_by_name(configuration: &configuration::Configuration, params: GetUserByNameParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let username = params.username; + let uri_str = format!("{}/user/{username}", configuration.base_path, username=crate::apis::urlencode(params.username)); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/user/{username}", local_var_configuration.base_path, username=crate::apis::urlencode(username)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn login_user(configuration: &configuration::Configuration, params: LoginUserParams) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - let username = params.username; - let password = params.password; - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/user/login", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + let uri_str = format!("{}/user/login", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - local_var_req_builder = local_var_req_builder.query(&[("username", &username.to_string())]); - local_var_req_builder = local_var_req_builder.query(&[("password", &password.to_string())]); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + req_builder = req_builder.query(&[("username", ¶ms.username.to_string())]); + req_builder = req_builder.query(&[("password", ¶ms.password.to_string())]); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn logout_user(configuration: &configuration::Configuration) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters + let uri_str = format!("{}/user/logout", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/user/logout", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } // Obtain a token from source provider. // Tokens can be Id or access tokens depending on the provider type and configuration. - let token = local_var_configuration.token_source.token().await.map_err(Error::TokenSource)?; + let token = configuration.token_source.token().await.map_err(Error::TokenSource)?; // The token format is the responsibility of the provider, thus we just set the authorization header with whatever is given. - local_var_req_builder = local_var_req_builder.header(reqwest::header::AUTHORIZATION, token); + req_builder = req_builder.header(reqwest::header::AUTHORIZATION, token); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// This can only be done by the logged in user. pub async fn update_user(configuration: &configuration::Configuration, params: UpdateUserParams) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - let username = params.username; - let user = params.user; - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/user/{username}", local_var_configuration.base_path, username=crate::apis::urlencode(username)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str()); + let uri_str = format!("{}/user/{username}", configuration.base_path, username=crate::apis::urlencode(params.username)); + let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } // Obtain a token from source provider. // Tokens can be Id or access tokens depending on the provider type and configuration. - let token = local_var_configuration.token_source.token().await.map_err(Error::TokenSource)?; + let token = configuration.token_source.token().await.map_err(Error::TokenSource)?; // The token format is the responsibility of the provider, thus we just set the authorization header with whatever is given. - local_var_req_builder = local_var_req_builder.header(reqwest::header::AUTHORIZATION, token); - local_var_req_builder = local_var_req_builder.json(&user); + req_builder = req_builder.header(reqwest::header::AUTHORIZATION, token); + req_builder = req_builder.json(¶ms.user); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/petstore/rust/reqwest/petstore-async/docs/FakeApi.md b/samples/client/petstore/rust/reqwest/petstore-async/docs/FakeApi.md index 7fd650381887e..c41f7d7b0e2fe 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/docs/FakeApi.md +++ b/samples/client/petstore/rust/reqwest/petstore-async/docs/FakeApi.md @@ -10,7 +10,7 @@ Method | HTTP request | Description ## test_nullable_required_param -> test_nullable_required_param(user_name, dummy_required_nullable_param, uppercase) +> test_nullable_required_param(user_name, dummy_required_nullable_param, uppercase, content) To test nullable required parameters @@ -23,6 +23,7 @@ Name | Type | Description | Required | Notes **user_name** | **String** | The name that needs to be fetched. Use user1 for testing. | [required] | **dummy_required_nullable_param** | Option<**String**> | To test nullable required parameters | [required] | **uppercase** | Option<**String**> | To test parameter names in upper case | | +**content** | Option<**String**> | To test escaping of parameters in rust code works | | ### Return type diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/fake_api.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/fake_api.rs index 5a06ed6f11989..dbc4858a0eedd 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/fake_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/fake_api.rs @@ -22,7 +22,9 @@ pub struct TestNullableRequiredParamParams { /// To test nullable required parameters pub dummy_required_nullable_param: Option, /// To test parameter names in upper case - pub uppercase: Option + pub uppercase: Option, + /// To test escaping of parameters in rust code works + pub content: Option } @@ -46,45 +48,37 @@ pub enum TestNullableRequiredParamError { /// pub async fn test_nullable_required_param(configuration: &configuration::Configuration, params: TestNullableRequiredParamParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let user_name = params.user_name; - let dummy_required_nullable_param = params.dummy_required_nullable_param; - let uppercase = params.uppercase; + let uri_str = format!("{}/fake/user/{user_name}", configuration.base_path, user_name=crate::apis::urlencode(params.user_name)); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/fake/user/{user_name}", local_var_configuration.base_path, user_name=crate::apis::urlencode(user_name)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref param_value) = params.content { + req_builder = req_builder.query(&[("content", ¶m_value.to_string())]); + } + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - match dummy_required_nullable_param { - Some(local_var_param_value) => { local_var_req_builder = local_var_req_builder.header("dummy_required_nullable_param", local_var_param_value.to_string()); }, - None => { local_var_req_builder = local_var_req_builder.header("dummy_required_nullable_param", ""); }, + match params.dummy_required_nullable_param { + Some(param_value) => { req_builder = req_builder.header("dummy_required_nullable_param", param_value.to_string()); }, + None => { req_builder = req_builder.header("dummy_required_nullable_param", ""); }, } - if let Some(local_var_param_value) = uppercase { - local_var_req_builder = local_var_req_builder.header("UPPERCASE", local_var_param_value.to_string()); + if let Some(param_value) = params.uppercase { + req_builder = req_builder.header("UPPERCASE", param_value.to_string()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/pet_api.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/pet_api.rs index 9711d3819bce1..61a60d15904ff 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/pet_api.rs @@ -213,349 +213,271 @@ pub enum UploadFileError { /// pub async fn add_pet(configuration: &configuration::Configuration, params: AddPetParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let pet = params.pet; + let uri_str = format!("{}/pet", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/pet", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - local_var_req_builder = local_var_req_builder.json(&pet); + req_builder = req_builder.json(¶ms.pet); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn delete_pet(configuration: &configuration::Configuration, params: DeletePetParams) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - let pet_id = params.pet_id; - let api_key = params.api_key; - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/pet/{petId}", local_var_configuration.base_path, petId=pet_id); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str()); + let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=params.pet_id); + let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(local_var_param_value) = api_key { - local_var_req_builder = local_var_req_builder.header("api_key", local_var_param_value.to_string()); + if let Some(param_value) = params.api_key { + req_builder = req_builder.header("api_key", param_value.to_string()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// Multiple status values can be provided with comma separated strings pub async fn find_pets_by_status(configuration: &configuration::Configuration, params: FindPetsByStatusParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let status = params.status; - let r#type = params.r#type; + let uri_str = format!("{}/pet/findByStatus", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/pet/findByStatus", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - local_var_req_builder = match "csv" { - "multi" => local_var_req_builder.query(&status.into_iter().map(|p| ("status".to_owned(), p.to_string())).collect::>()), - _ => local_var_req_builder.query(&[("status", &status.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), + req_builder = match "csv" { + "multi" => req_builder.query(¶ms.status.into_iter().map(|p| ("status".to_owned(), p.to_string())).collect::>()), + _ => req_builder.query(&[("status", ¶ms.status.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), }; - if let Some(ref local_var_str) = r#type { - local_var_req_builder = match "csv" { - "multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("type".to_owned(), p.to_string())).collect::>()), - _ => local_var_req_builder.query(&[("type", &local_var_str.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), + if let Some(ref param_value) = params.r#type { + req_builder = match "csv" { + "multi" => req_builder.query(¶m_value.into_iter().map(|p| ("type".to_owned(), p.to_string())).collect::>()), + _ => req_builder.query(&[("type", ¶m_value.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), }; } - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. pub async fn find_pets_by_tags(configuration: &configuration::Configuration, params: FindPetsByTagsParams) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - let tags = params.tags; - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/pet/findByTags", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + let uri_str = format!("{}/pet/findByTags", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - local_var_req_builder = match "csv" { - "multi" => local_var_req_builder.query(&tags.into_iter().map(|p| ("tags".to_owned(), p.to_string())).collect::>()), - _ => local_var_req_builder.query(&[("tags", &tags.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), + req_builder = match "csv" { + "multi" => req_builder.query(¶ms.tags.into_iter().map(|p| ("tags".to_owned(), p.to_string())).collect::>()), + _ => req_builder.query(&[("tags", ¶ms.tags.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), }; - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// Returns a single pet pub async fn get_pet_by_id(configuration: &configuration::Configuration, params: GetPetByIdParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let pet_id = params.pet_id; + let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=params.pet_id); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/pet/{petId}", local_var_configuration.base_path, petId=pet_id); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn update_pet(configuration: &configuration::Configuration, params: UpdatePetParams) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - let pet = params.pet; - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/pet", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str()); + let uri_str = format!("{}/pet", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - local_var_req_builder = local_var_req_builder.json(&pet); + req_builder = req_builder.json(¶ms.pet); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn update_pet_with_form(configuration: &configuration::Configuration, params: UpdatePetWithFormParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let pet_id = params.pet_id; - let name = params.name; - let status = params.status; + let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=params.pet_id); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/pet/{petId}", local_var_configuration.base_path, petId=pet_id); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - let mut local_var_form_params = std::collections::HashMap::new(); - if let Some(local_var_param_value) = name { - local_var_form_params.insert("name", local_var_param_value.to_string()); + let mut multipart_form_params = std::collections::HashMap::new(); + if let Some(param_value) = params.name { + multipart_form_params.insert("name", param_value.to_string()); } - if let Some(local_var_param_value) = status { - local_var_form_params.insert("status", local_var_param_value.to_string()); + if let Some(param_value) = params.status { + multipart_form_params.insert("status", param_value.to_string()); } - local_var_req_builder = local_var_req_builder.form(&local_var_form_params); + req_builder = req_builder.form(&multipart_form_params); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn upload_file(configuration: &configuration::Configuration, params: UploadFileParams) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - let pet_id = params.pet_id; - let additional_metadata = params.additional_metadata; - let file = params.file; - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/pet/{petId}/uploadImage", local_var_configuration.base_path, petId=pet_id); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + let uri_str = format!("{}/pet/{petId}/uploadImage", configuration.base_path, petId=params.pet_id); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - let mut local_var_form = reqwest::multipart::Form::new(); - if let Some(local_var_param_value) = additional_metadata { - local_var_form = local_var_form.text("additionalMetadata", local_var_param_value.to_string()); + let mut multipart_form = reqwest::multipart::Form::new(); + if let Some(param_value) = params.additional_metadata { + multipart_form = multipart_form.text("additionalMetadata", param_value.to_string()); } // TODO: support file upload for 'file' parameter - local_var_req_builder = local_var_req_builder.multipart(local_var_form); + req_builder = req_builder.multipart(multipart_form); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/store_api.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/store_api.rs index 340e6f2dc97cc..17760b176768c 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/store_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/store_api.rs @@ -103,149 +103,114 @@ pub enum PlaceOrderError { /// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors pub async fn delete_order(configuration: &configuration::Configuration, params: DeleteOrderParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let order_id = params.order_id; + let uri_str = format!("{}/store/order/{orderId}", configuration.base_path, orderId=crate::apis::urlencode(params.order_id)); + let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/store/order/{orderId}", local_var_configuration.base_path, orderId=crate::apis::urlencode(order_id)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// Returns a map of status codes to quantities pub async fn get_inventory(configuration: &configuration::Configuration) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/store/inventory", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + let uri_str = format!("{}/store/inventory", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions pub async fn get_order_by_id(configuration: &configuration::Configuration, params: GetOrderByIdParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let order_id = params.order_id; + let uri_str = format!("{}/store/order/{orderId}", configuration.base_path, orderId=params.order_id); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/store/order/{orderId}", local_var_configuration.base_path, orderId=order_id); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn place_order(configuration: &configuration::Configuration, params: PlaceOrderParams) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - let order = params.order; - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/store/order", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + let uri_str = format!("{}/store/order", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - local_var_req_builder = local_var_req_builder.json(&order); + req_builder = req_builder.json(¶ms.order); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/testing_api.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/testing_api.rs index 0dafccec4b728..3f365095bf634 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/testing_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/testing_api.rs @@ -47,65 +47,50 @@ pub enum TestsTypeTestingGetError { pub async fn tests_file_response_get(configuration: &configuration::Configuration) -> Result> { - let local_var_configuration = configuration; - // unbox the parameters + let uri_str = format!("{}/tests/fileResponse", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/tests/fileResponse", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { - Ok(local_var_resp) + if !status.is_client_error() && !status.is_server_error() { + Ok(resp) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } pub async fn tests_type_testing_get(configuration: &configuration::Configuration) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/tests/typeTesting", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + let uri_str = format!("{}/tests/typeTesting", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/user_api.rs b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/user_api.rs index 985f3b65e3173..e4dfae546d4cc 100644 --- a/samples/client/petstore/rust/reqwest/petstore-async/src/apis/user_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-async/src/apis/user_api.rs @@ -196,336 +196,263 @@ pub enum UpdateUserError { /// This can only be done by the logged in user. pub async fn create_user(configuration: &configuration::Configuration, params: CreateUserParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let user = params.user; + let uri_str = format!("{}/user", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/user", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - local_var_req_builder = local_var_req_builder.json(&user); + req_builder = req_builder.json(¶ms.user); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn create_users_with_array_input(configuration: &configuration::Configuration, params: CreateUsersWithArrayInputParams) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - let user = params.user; - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/user/createWithArray", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + let uri_str = format!("{}/user/createWithArray", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - local_var_req_builder = local_var_req_builder.json(&user); + req_builder = req_builder.json(¶ms.user); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn create_users_with_list_input(configuration: &configuration::Configuration, params: CreateUsersWithListInputParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let user = params.user; + let uri_str = format!("{}/user/createWithList", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/user/createWithList", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - local_var_req_builder = local_var_req_builder.json(&user); + req_builder = req_builder.json(¶ms.user); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// This can only be done by the logged in user. pub async fn delete_user(configuration: &configuration::Configuration, params: DeleteUserParams) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - let username = params.username; - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/user/{username}", local_var_configuration.base_path, username=crate::apis::urlencode(username)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str()); + let uri_str = format!("{}/user/{username}", configuration.base_path, username=crate::apis::urlencode(params.username)); + let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn get_user_by_name(configuration: &configuration::Configuration, params: GetUserByNameParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let username = params.username; + let uri_str = format!("{}/user/{username}", configuration.base_path, username=crate::apis::urlencode(params.username)); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/user/{username}", local_var_configuration.base_path, username=crate::apis::urlencode(username)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn login_user(configuration: &configuration::Configuration, params: LoginUserParams) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - let username = params.username; - let password = params.password; - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/user/login", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + let uri_str = format!("{}/user/login", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - local_var_req_builder = local_var_req_builder.query(&[("username", &username.to_string())]); - local_var_req_builder = local_var_req_builder.query(&[("password", &password.to_string())]); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + req_builder = req_builder.query(&[("username", ¶ms.username.to_string())]); + req_builder = req_builder.query(&[("password", ¶ms.password.to_string())]); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn logout_user(configuration: &configuration::Configuration) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters + let uri_str = format!("{}/user/logout", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/user/logout", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// This can only be done by the logged in user. pub async fn update_user(configuration: &configuration::Configuration, params: UpdateUserParams) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - let username = params.username; - let user = params.user; - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/user/{username}", local_var_configuration.base_path, username=crate::apis::urlencode(username)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str()); + let uri_str = format!("{}/user/{username}", configuration.base_path, username=crate::apis::urlencode(params.username)); + let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - local_var_req_builder = local_var_req_builder.json(&user); + req_builder = req_builder.json(¶ms.user); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/petstore/rust/reqwest/petstore-avoid-box/docs/FakeApi.md b/samples/client/petstore/rust/reqwest/petstore-avoid-box/docs/FakeApi.md index 7fd650381887e..c41f7d7b0e2fe 100644 --- a/samples/client/petstore/rust/reqwest/petstore-avoid-box/docs/FakeApi.md +++ b/samples/client/petstore/rust/reqwest/petstore-avoid-box/docs/FakeApi.md @@ -10,7 +10,7 @@ Method | HTTP request | Description ## test_nullable_required_param -> test_nullable_required_param(user_name, dummy_required_nullable_param, uppercase) +> test_nullable_required_param(user_name, dummy_required_nullable_param, uppercase, content) To test nullable required parameters @@ -23,6 +23,7 @@ Name | Type | Description | Required | Notes **user_name** | **String** | The name that needs to be fetched. Use user1 for testing. | [required] | **dummy_required_nullable_param** | Option<**String**> | To test nullable required parameters | [required] | **uppercase** | Option<**String**> | To test parameter names in upper case | | +**content** | Option<**String**> | To test escaping of parameters in rust code works | | ### Return type diff --git a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/fake_api.rs b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/fake_api.rs index 5a06ed6f11989..dbc4858a0eedd 100644 --- a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/fake_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/fake_api.rs @@ -22,7 +22,9 @@ pub struct TestNullableRequiredParamParams { /// To test nullable required parameters pub dummy_required_nullable_param: Option, /// To test parameter names in upper case - pub uppercase: Option + pub uppercase: Option, + /// To test escaping of parameters in rust code works + pub content: Option } @@ -46,45 +48,37 @@ pub enum TestNullableRequiredParamError { /// pub async fn test_nullable_required_param(configuration: &configuration::Configuration, params: TestNullableRequiredParamParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let user_name = params.user_name; - let dummy_required_nullable_param = params.dummy_required_nullable_param; - let uppercase = params.uppercase; + let uri_str = format!("{}/fake/user/{user_name}", configuration.base_path, user_name=crate::apis::urlencode(params.user_name)); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/fake/user/{user_name}", local_var_configuration.base_path, user_name=crate::apis::urlencode(user_name)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref param_value) = params.content { + req_builder = req_builder.query(&[("content", ¶m_value.to_string())]); + } + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - match dummy_required_nullable_param { - Some(local_var_param_value) => { local_var_req_builder = local_var_req_builder.header("dummy_required_nullable_param", local_var_param_value.to_string()); }, - None => { local_var_req_builder = local_var_req_builder.header("dummy_required_nullable_param", ""); }, + match params.dummy_required_nullable_param { + Some(param_value) => { req_builder = req_builder.header("dummy_required_nullable_param", param_value.to_string()); }, + None => { req_builder = req_builder.header("dummy_required_nullable_param", ""); }, } - if let Some(local_var_param_value) = uppercase { - local_var_req_builder = local_var_req_builder.header("UPPERCASE", local_var_param_value.to_string()); + if let Some(param_value) = params.uppercase { + req_builder = req_builder.header("UPPERCASE", param_value.to_string()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/pet_api.rs b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/pet_api.rs index 9711d3819bce1..61a60d15904ff 100644 --- a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/pet_api.rs @@ -213,349 +213,271 @@ pub enum UploadFileError { /// pub async fn add_pet(configuration: &configuration::Configuration, params: AddPetParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let pet = params.pet; + let uri_str = format!("{}/pet", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/pet", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - local_var_req_builder = local_var_req_builder.json(&pet); + req_builder = req_builder.json(¶ms.pet); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn delete_pet(configuration: &configuration::Configuration, params: DeletePetParams) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - let pet_id = params.pet_id; - let api_key = params.api_key; - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/pet/{petId}", local_var_configuration.base_path, petId=pet_id); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str()); + let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=params.pet_id); + let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(local_var_param_value) = api_key { - local_var_req_builder = local_var_req_builder.header("api_key", local_var_param_value.to_string()); + if let Some(param_value) = params.api_key { + req_builder = req_builder.header("api_key", param_value.to_string()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// Multiple status values can be provided with comma separated strings pub async fn find_pets_by_status(configuration: &configuration::Configuration, params: FindPetsByStatusParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let status = params.status; - let r#type = params.r#type; + let uri_str = format!("{}/pet/findByStatus", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/pet/findByStatus", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - local_var_req_builder = match "csv" { - "multi" => local_var_req_builder.query(&status.into_iter().map(|p| ("status".to_owned(), p.to_string())).collect::>()), - _ => local_var_req_builder.query(&[("status", &status.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), + req_builder = match "csv" { + "multi" => req_builder.query(¶ms.status.into_iter().map(|p| ("status".to_owned(), p.to_string())).collect::>()), + _ => req_builder.query(&[("status", ¶ms.status.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), }; - if let Some(ref local_var_str) = r#type { - local_var_req_builder = match "csv" { - "multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("type".to_owned(), p.to_string())).collect::>()), - _ => local_var_req_builder.query(&[("type", &local_var_str.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), + if let Some(ref param_value) = params.r#type { + req_builder = match "csv" { + "multi" => req_builder.query(¶m_value.into_iter().map(|p| ("type".to_owned(), p.to_string())).collect::>()), + _ => req_builder.query(&[("type", ¶m_value.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), }; } - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. pub async fn find_pets_by_tags(configuration: &configuration::Configuration, params: FindPetsByTagsParams) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - let tags = params.tags; - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/pet/findByTags", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + let uri_str = format!("{}/pet/findByTags", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - local_var_req_builder = match "csv" { - "multi" => local_var_req_builder.query(&tags.into_iter().map(|p| ("tags".to_owned(), p.to_string())).collect::>()), - _ => local_var_req_builder.query(&[("tags", &tags.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), + req_builder = match "csv" { + "multi" => req_builder.query(¶ms.tags.into_iter().map(|p| ("tags".to_owned(), p.to_string())).collect::>()), + _ => req_builder.query(&[("tags", ¶ms.tags.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), }; - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// Returns a single pet pub async fn get_pet_by_id(configuration: &configuration::Configuration, params: GetPetByIdParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let pet_id = params.pet_id; + let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=params.pet_id); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/pet/{petId}", local_var_configuration.base_path, petId=pet_id); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn update_pet(configuration: &configuration::Configuration, params: UpdatePetParams) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - let pet = params.pet; - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/pet", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str()); + let uri_str = format!("{}/pet", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - local_var_req_builder = local_var_req_builder.json(&pet); + req_builder = req_builder.json(¶ms.pet); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn update_pet_with_form(configuration: &configuration::Configuration, params: UpdatePetWithFormParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let pet_id = params.pet_id; - let name = params.name; - let status = params.status; + let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=params.pet_id); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/pet/{petId}", local_var_configuration.base_path, petId=pet_id); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - let mut local_var_form_params = std::collections::HashMap::new(); - if let Some(local_var_param_value) = name { - local_var_form_params.insert("name", local_var_param_value.to_string()); + let mut multipart_form_params = std::collections::HashMap::new(); + if let Some(param_value) = params.name { + multipart_form_params.insert("name", param_value.to_string()); } - if let Some(local_var_param_value) = status { - local_var_form_params.insert("status", local_var_param_value.to_string()); + if let Some(param_value) = params.status { + multipart_form_params.insert("status", param_value.to_string()); } - local_var_req_builder = local_var_req_builder.form(&local_var_form_params); + req_builder = req_builder.form(&multipart_form_params); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn upload_file(configuration: &configuration::Configuration, params: UploadFileParams) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - let pet_id = params.pet_id; - let additional_metadata = params.additional_metadata; - let file = params.file; - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/pet/{petId}/uploadImage", local_var_configuration.base_path, petId=pet_id); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + let uri_str = format!("{}/pet/{petId}/uploadImage", configuration.base_path, petId=params.pet_id); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - let mut local_var_form = reqwest::multipart::Form::new(); - if let Some(local_var_param_value) = additional_metadata { - local_var_form = local_var_form.text("additionalMetadata", local_var_param_value.to_string()); + let mut multipart_form = reqwest::multipart::Form::new(); + if let Some(param_value) = params.additional_metadata { + multipart_form = multipart_form.text("additionalMetadata", param_value.to_string()); } // TODO: support file upload for 'file' parameter - local_var_req_builder = local_var_req_builder.multipart(local_var_form); + req_builder = req_builder.multipart(multipart_form); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/store_api.rs b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/store_api.rs index 340e6f2dc97cc..17760b176768c 100644 --- a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/store_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/store_api.rs @@ -103,149 +103,114 @@ pub enum PlaceOrderError { /// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors pub async fn delete_order(configuration: &configuration::Configuration, params: DeleteOrderParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let order_id = params.order_id; + let uri_str = format!("{}/store/order/{orderId}", configuration.base_path, orderId=crate::apis::urlencode(params.order_id)); + let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/store/order/{orderId}", local_var_configuration.base_path, orderId=crate::apis::urlencode(order_id)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// Returns a map of status codes to quantities pub async fn get_inventory(configuration: &configuration::Configuration) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/store/inventory", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + let uri_str = format!("{}/store/inventory", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions pub async fn get_order_by_id(configuration: &configuration::Configuration, params: GetOrderByIdParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let order_id = params.order_id; + let uri_str = format!("{}/store/order/{orderId}", configuration.base_path, orderId=params.order_id); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/store/order/{orderId}", local_var_configuration.base_path, orderId=order_id); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn place_order(configuration: &configuration::Configuration, params: PlaceOrderParams) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - let order = params.order; - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/store/order", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + let uri_str = format!("{}/store/order", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - local_var_req_builder = local_var_req_builder.json(&order); + req_builder = req_builder.json(¶ms.order); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/testing_api.rs b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/testing_api.rs index 0dafccec4b728..3f365095bf634 100644 --- a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/testing_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/testing_api.rs @@ -47,65 +47,50 @@ pub enum TestsTypeTestingGetError { pub async fn tests_file_response_get(configuration: &configuration::Configuration) -> Result> { - let local_var_configuration = configuration; - // unbox the parameters + let uri_str = format!("{}/tests/fileResponse", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/tests/fileResponse", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { - Ok(local_var_resp) + if !status.is_client_error() && !status.is_server_error() { + Ok(resp) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } pub async fn tests_type_testing_get(configuration: &configuration::Configuration) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/tests/typeTesting", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + let uri_str = format!("{}/tests/typeTesting", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/user_api.rs b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/user_api.rs index 985f3b65e3173..e4dfae546d4cc 100644 --- a/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/user_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-avoid-box/src/apis/user_api.rs @@ -196,336 +196,263 @@ pub enum UpdateUserError { /// This can only be done by the logged in user. pub async fn create_user(configuration: &configuration::Configuration, params: CreateUserParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let user = params.user; + let uri_str = format!("{}/user", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/user", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - local_var_req_builder = local_var_req_builder.json(&user); + req_builder = req_builder.json(¶ms.user); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn create_users_with_array_input(configuration: &configuration::Configuration, params: CreateUsersWithArrayInputParams) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - let user = params.user; - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/user/createWithArray", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + let uri_str = format!("{}/user/createWithArray", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - local_var_req_builder = local_var_req_builder.json(&user); + req_builder = req_builder.json(¶ms.user); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn create_users_with_list_input(configuration: &configuration::Configuration, params: CreateUsersWithListInputParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let user = params.user; + let uri_str = format!("{}/user/createWithList", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/user/createWithList", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - local_var_req_builder = local_var_req_builder.json(&user); + req_builder = req_builder.json(¶ms.user); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// This can only be done by the logged in user. pub async fn delete_user(configuration: &configuration::Configuration, params: DeleteUserParams) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - let username = params.username; - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/user/{username}", local_var_configuration.base_path, username=crate::apis::urlencode(username)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str()); + let uri_str = format!("{}/user/{username}", configuration.base_path, username=crate::apis::urlencode(params.username)); + let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn get_user_by_name(configuration: &configuration::Configuration, params: GetUserByNameParams) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters - let username = params.username; + let uri_str = format!("{}/user/{username}", configuration.base_path, username=crate::apis::urlencode(params.username)); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/user/{username}", local_var_configuration.base_path, username=crate::apis::urlencode(username)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn login_user(configuration: &configuration::Configuration, params: LoginUserParams) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - let username = params.username; - let password = params.password; - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/user/login", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + let uri_str = format!("{}/user/login", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - local_var_req_builder = local_var_req_builder.query(&[("username", &username.to_string())]); - local_var_req_builder = local_var_req_builder.query(&[("password", &password.to_string())]); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + req_builder = req_builder.query(&[("username", ¶ms.username.to_string())]); + req_builder = req_builder.query(&[("password", ¶ms.password.to_string())]); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub async fn logout_user(configuration: &configuration::Configuration) -> Result, Error> { - let local_var_configuration = configuration; - // unbox the parameters + let uri_str = format!("{}/user/logout", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - - let local_var_client = &local_var_configuration.client; - - let local_var_uri_str = format!("{}/user/logout", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// This can only be done by the logged in user. pub async fn update_user(configuration: &configuration::Configuration, params: UpdateUserParams) -> Result, Error> { - let local_var_configuration = configuration; - - // unbox the parameters - let username = params.username; - let user = params.user; - - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/user/{username}", local_var_configuration.base_path, username=crate::apis::urlencode(username)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str()); + let uri_str = format!("{}/user/{username}", configuration.base_path, username=crate::apis::urlencode(params.username)); + let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - local_var_req_builder = local_var_req_builder.json(&user); + req_builder = req_builder.json(¶ms.user); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req).await?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req).await?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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 = 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Ok(ResponseContent { status, content, entity }) } else { - let local_var_content = local_var_resp.text().await?; - let local_var_entity: Option = 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)) + let content = resp.text().await?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/docs/FakeApi.md b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/docs/FakeApi.md index 7fd650381887e..c41f7d7b0e2fe 100644 --- a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/docs/FakeApi.md +++ b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/docs/FakeApi.md @@ -10,7 +10,7 @@ Method | HTTP request | Description ## test_nullable_required_param -> test_nullable_required_param(user_name, dummy_required_nullable_param, uppercase) +> test_nullable_required_param(user_name, dummy_required_nullable_param, uppercase, content) To test nullable required parameters @@ -23,6 +23,7 @@ Name | Type | Description | Required | Notes **user_name** | **String** | The name that needs to be fetched. Use user1 for testing. | [required] | **dummy_required_nullable_param** | Option<**String**> | To test nullable required parameters | [required] | **uppercase** | Option<**String**> | To test parameter names in upper case | | +**content** | Option<**String**> | To test escaping of parameters in rust code works | | ### Return type diff --git a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/fake_api.rs b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/fake_api.rs index 3f39f065eb138..f607b9b069d48 100644 --- a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/fake_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/fake_api.rs @@ -26,37 +26,41 @@ pub enum TestNullableRequiredParamError { /// -pub fn test_nullable_required_param(configuration: &configuration::Configuration, user_name: &str, dummy_required_nullable_param: Option<&str>, uppercase: Option<&str>) -> Result<(), Error> { - let local_var_configuration = configuration; +pub fn test_nullable_required_param(configuration: &configuration::Configuration, user_name: &str, dummy_required_nullable_param: Option<&str>, uppercase: Option<&str>, content: Option<&str>) -> Result<(), Error> { + // add a prefix to parameters to efficiently prevent name collisions + let p_user_name = user_name; + let p_dummy_required_nullable_param = dummy_required_nullable_param; + let p_uppercase = uppercase; + let p_content = content; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/fake/user/{user_name}", configuration.base_path, user_name=crate::apis::urlencode(p_user_name)); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - let local_var_uri_str = format!("{}/fake/user/{user_name}", local_var_configuration.base_path, user_name=crate::apis::urlencode(user_name)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref param_value) = p_content { + req_builder = req_builder.query(&[("content", ¶m_value.to_string())]); + } + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - match dummy_required_nullable_param { - Some(local_var_param_value) => { local_var_req_builder = local_var_req_builder.header("dummy_required_nullable_param", local_var_param_value.to_string()); }, - None => { local_var_req_builder = local_var_req_builder.header("dummy_required_nullable_param", ""); }, + match p_dummy_required_nullable_param { + Some(param_value) => { req_builder = req_builder.header("dummy_required_nullable_param", param_value.to_string()); }, + None => { req_builder = req_builder.header("dummy_required_nullable_param", ""); }, } - if let Some(local_var_param_value) = uppercase { - local_var_req_builder = local_var_req_builder.header("UPPERCASE", local_var_param_value.to_string()); + if let Some(param_value) = p_uppercase { + req_builder = req_builder.header("UPPERCASE", param_value.to_string()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + if !status.is_client_error() && !status.is_server_error() { Ok(()) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/pet_api.rs b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/pet_api.rs index 34cbc404de0aa..a3cf62d241313 100644 --- a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/pet_api.rs @@ -84,399 +84,389 @@ pub enum UploadFileError { /// pub fn add_pet(configuration: &configuration::Configuration, pet: models::Pet) -> Result> { - let local_var_configuration = configuration; + // add a prefix to parameters to efficiently prevent name collisions + let p_pet = pet; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/pet", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - let local_var_uri_str = format!("{}/pet", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); - - if let Some(ref local_var_aws_v4_key) = local_var_configuration.aws_v4_key { - let local_var_new_headers = match local_var_aws_v4_key.sign( - &local_var_uri_str, + if let Some(ref aws_v4_key) = configuration.aws_v4_key { + let new_headers = match aws_v4_key.sign( + &uri_str, "POST", - &serde_json::to_string(&pet).expect("param should serialize to string"), + &serde_json::to_string(&p_pet).expect("param should serialize to string"), ) { Ok(new_headers) => new_headers, Err(err) => return Err(Error::AWSV4SignatureError(err)), }; - for (local_var_name, local_var_value) in local_var_new_headers.iter() { - local_var_req_builder = local_var_req_builder.header(local_var_name.as_str(), local_var_value.as_str()); + for (name, value) in new_headers.iter() { + req_builder = req_builder.header(name.as_str(), value.as_str()); } } - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - local_var_req_builder = local_var_req_builder.json(&pet); + req_builder = req_builder.json(&p_pet); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub fn delete_pet(configuration: &configuration::Configuration, pet_id: i64, api_key: Option<&str>) -> Result<(), Error> { - let local_var_configuration = configuration; - - let local_var_client = &local_var_configuration.client; + // add a prefix to parameters to efficiently prevent name collisions + let p_pet_id = pet_id; + let p_api_key = api_key; - let local_var_uri_str = format!("{}/pet/{petId}", local_var_configuration.base_path, petId=pet_id); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str()); + let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=p_pet_id); + let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str); - if let Some(ref local_var_aws_v4_key) = local_var_configuration.aws_v4_key { - let local_var_new_headers = match local_var_aws_v4_key.sign( - &local_var_uri_str, + if let Some(ref aws_v4_key) = configuration.aws_v4_key { + let new_headers = match aws_v4_key.sign( + &uri_str, "DELETE", "", ) { Ok(new_headers) => new_headers, Err(err) => return Err(Error::AWSV4SignatureError(err)), }; - for (local_var_name, local_var_value) in local_var_new_headers.iter() { - local_var_req_builder = local_var_req_builder.header(local_var_name.as_str(), local_var_value.as_str()); + for (name, value) in new_headers.iter() { + req_builder = req_builder.header(name.as_str(), value.as_str()); } } - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(local_var_param_value) = api_key { - local_var_req_builder = local_var_req_builder.header("api_key", local_var_param_value.to_string()); + if let Some(param_value) = p_api_key { + req_builder = req_builder.header("api_key", param_value.to_string()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + if !status.is_client_error() && !status.is_server_error() { Ok(()) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// Multiple status values can be provided with comma separated strings pub fn find_pets_by_status(configuration: &configuration::Configuration, status: Vec, r#type: Option>) -> Result, Error> { - let local_var_configuration = configuration; + // add a prefix to parameters to efficiently prevent name collisions + let p_status = status; + let p_type = r#type; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/pet/findByStatus", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - let local_var_uri_str = format!("{}/pet/findByStatus", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - local_var_req_builder = match "csv" { - "multi" => local_var_req_builder.query(&status.into_iter().map(|p| ("status".to_owned(), p.to_string())).collect::>()), - _ => local_var_req_builder.query(&[("status", &status.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), + req_builder = match "csv" { + "multi" => req_builder.query(&p_status.into_iter().map(|p| ("status".to_owned(), p.to_string())).collect::>()), + _ => req_builder.query(&[("status", &p_status.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), }; - if let Some(ref local_var_str) = r#type { - local_var_req_builder = match "csv" { - "multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("type".to_owned(), p.to_string())).collect::>()), - _ => local_var_req_builder.query(&[("type", &local_var_str.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), + if let Some(ref param_value) = p_type { + req_builder = match "csv" { + "multi" => req_builder.query(¶m_value.into_iter().map(|p| ("type".to_owned(), p.to_string())).collect::>()), + _ => req_builder.query(&[("type", ¶m_value.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), }; } - if let Some(ref local_var_aws_v4_key) = local_var_configuration.aws_v4_key { - let local_var_new_headers = match local_var_aws_v4_key.sign( - &local_var_uri_str, + if let Some(ref aws_v4_key) = configuration.aws_v4_key { + let new_headers = match aws_v4_key.sign( + &uri_str, "GET", "", ) { Ok(new_headers) => new_headers, Err(err) => return Err(Error::AWSV4SignatureError(err)), }; - for (local_var_name, local_var_value) in local_var_new_headers.iter() { - local_var_req_builder = local_var_req_builder.header(local_var_name.as_str(), local_var_value.as_str()); + for (name, value) in new_headers.iter() { + req_builder = req_builder.header(name.as_str(), value.as_str()); } } - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. pub fn find_pets_by_tags(configuration: &configuration::Configuration, tags: Vec) -> Result, Error> { - let local_var_configuration = configuration; - - let local_var_client = &local_var_configuration.client; + // add a prefix to parameters to efficiently prevent name collisions + let p_tags = tags; - let local_var_uri_str = format!("{}/pet/findByTags", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + let uri_str = format!("{}/pet/findByTags", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - local_var_req_builder = match "csv" { - "multi" => local_var_req_builder.query(&tags.into_iter().map(|p| ("tags".to_owned(), p.to_string())).collect::>()), - _ => local_var_req_builder.query(&[("tags", &tags.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), + req_builder = match "csv" { + "multi" => req_builder.query(&p_tags.into_iter().map(|p| ("tags".to_owned(), p.to_string())).collect::>()), + _ => req_builder.query(&[("tags", &p_tags.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), }; - if let Some(ref local_var_aws_v4_key) = local_var_configuration.aws_v4_key { - let local_var_new_headers = match local_var_aws_v4_key.sign( - &local_var_uri_str, + if let Some(ref aws_v4_key) = configuration.aws_v4_key { + let new_headers = match aws_v4_key.sign( + &uri_str, "GET", "", ) { Ok(new_headers) => new_headers, Err(err) => return Err(Error::AWSV4SignatureError(err)), }; - for (local_var_name, local_var_value) in local_var_new_headers.iter() { - local_var_req_builder = local_var_req_builder.header(local_var_name.as_str(), local_var_value.as_str()); + for (name, value) in new_headers.iter() { + req_builder = req_builder.header(name.as_str(), value.as_str()); } } - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// Returns a single pet pub fn get_pet_by_id(configuration: &configuration::Configuration, pet_id: i64) -> Result> { - let local_var_configuration = configuration; + // add a prefix to parameters to efficiently prevent name collisions + let p_pet_id = pet_id; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=p_pet_id); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - let local_var_uri_str = format!("{}/pet/{petId}", local_var_configuration.base_path, petId=pet_id); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_aws_v4_key) = local_var_configuration.aws_v4_key { - let local_var_new_headers = match local_var_aws_v4_key.sign( - &local_var_uri_str, + if let Some(ref aws_v4_key) = configuration.aws_v4_key { + let new_headers = match aws_v4_key.sign( + &uri_str, "GET", "", ) { Ok(new_headers) => new_headers, Err(err) => return Err(Error::AWSV4SignatureError(err)), }; - for (local_var_name, local_var_value) in local_var_new_headers.iter() { - local_var_req_builder = local_var_req_builder.header(local_var_name.as_str(), local_var_value.as_str()); + for (name, value) in new_headers.iter() { + req_builder = req_builder.header(name.as_str(), value.as_str()); } } - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub fn update_pet(configuration: &configuration::Configuration, pet: models::Pet) -> Result> { - let local_var_configuration = configuration; - - let local_var_client = &local_var_configuration.client; + // add a prefix to parameters to efficiently prevent name collisions + let p_pet = pet; - let local_var_uri_str = format!("{}/pet", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str()); + let uri_str = format!("{}/pet", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str); - if let Some(ref local_var_aws_v4_key) = local_var_configuration.aws_v4_key { - let local_var_new_headers = match local_var_aws_v4_key.sign( - &local_var_uri_str, + if let Some(ref aws_v4_key) = configuration.aws_v4_key { + let new_headers = match aws_v4_key.sign( + &uri_str, "PUT", - &serde_json::to_string(&pet).expect("param should serialize to string"), + &serde_json::to_string(&p_pet).expect("param should serialize to string"), ) { Ok(new_headers) => new_headers, Err(err) => return Err(Error::AWSV4SignatureError(err)), }; - for (local_var_name, local_var_value) in local_var_new_headers.iter() { - local_var_req_builder = local_var_req_builder.header(local_var_name.as_str(), local_var_value.as_str()); + for (name, value) in new_headers.iter() { + req_builder = req_builder.header(name.as_str(), value.as_str()); } } - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - local_var_req_builder = local_var_req_builder.json(&pet); + req_builder = req_builder.json(&p_pet); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub fn update_pet_with_form(configuration: &configuration::Configuration, pet_id: i64, name: Option<&str>, status: Option<&str>) -> Result<(), Error> { - let local_var_configuration = configuration; + // add a prefix to parameters to efficiently prevent name collisions + let p_pet_id = pet_id; + let p_name = name; + let p_status = status; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=p_pet_id); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - let local_var_uri_str = format!("{}/pet/{petId}", local_var_configuration.base_path, petId=pet_id); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); - - if let Some(ref local_var_aws_v4_key) = local_var_configuration.aws_v4_key { - let local_var_new_headers = match local_var_aws_v4_key.sign( - &local_var_uri_str, + if let Some(ref aws_v4_key) = configuration.aws_v4_key { + let new_headers = match aws_v4_key.sign( + &uri_str, "POST", "", ) { Ok(new_headers) => new_headers, Err(err) => return Err(Error::AWSV4SignatureError(err)), }; - for (local_var_name, local_var_value) in local_var_new_headers.iter() { - local_var_req_builder = local_var_req_builder.header(local_var_name.as_str(), local_var_value.as_str()); + for (name, value) in new_headers.iter() { + req_builder = req_builder.header(name.as_str(), value.as_str()); } } - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - let mut local_var_form_params = std::collections::HashMap::new(); - if let Some(local_var_param_value) = name { - local_var_form_params.insert("name", local_var_param_value.to_string()); + let mut multipart_form_params = std::collections::HashMap::new(); + if let Some(param_value) = p_name { + multipart_form_params.insert("name", param_value.to_string()); } - if let Some(local_var_param_value) = status { - local_var_form_params.insert("status", local_var_param_value.to_string()); + if let Some(param_value) = p_status { + multipart_form_params.insert("status", param_value.to_string()); } - local_var_req_builder = local_var_req_builder.form(&local_var_form_params); + req_builder = req_builder.form(&multipart_form_params); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + if !status.is_client_error() && !status.is_server_error() { Ok(()) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub fn upload_file(configuration: &configuration::Configuration, pet_id: i64, additional_metadata: Option<&str>, file: Option) -> Result> { - let local_var_configuration = configuration; - - let local_var_client = &local_var_configuration.client; + // add a prefix to parameters to efficiently prevent name collisions + let p_pet_id = pet_id; + let p_additional_metadata = additional_metadata; + let p_file = file; - let local_var_uri_str = format!("{}/pet/{petId}/uploadImage", local_var_configuration.base_path, petId=pet_id); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + let uri_str = format!("{}/pet/{petId}/uploadImage", configuration.base_path, petId=p_pet_id); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - if let Some(ref local_var_aws_v4_key) = local_var_configuration.aws_v4_key { - let local_var_new_headers = match local_var_aws_v4_key.sign( - &local_var_uri_str, + if let Some(ref aws_v4_key) = configuration.aws_v4_key { + let new_headers = match aws_v4_key.sign( + &uri_str, "POST", "", ) { Ok(new_headers) => new_headers, Err(err) => return Err(Error::AWSV4SignatureError(err)), }; - for (local_var_name, local_var_value) in local_var_new_headers.iter() { - local_var_req_builder = local_var_req_builder.header(local_var_name.as_str(), local_var_value.as_str()); + for (name, value) in new_headers.iter() { + req_builder = req_builder.header(name.as_str(), value.as_str()); } } - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - let mut local_var_form = reqwest::blocking::multipart::Form::new(); - if let Some(local_var_param_value) = additional_metadata { - local_var_form = local_var_form.text("additionalMetadata", local_var_param_value.to_string()); + let mut multipart_form = reqwest::blocking::multipart::Form::new(); + if let Some(param_value) = p_additional_metadata { + multipart_form = multipart_form.text("additionalMetadata", param_value.to_string()); } - if let Some(local_var_param_value) = file { - local_var_form = local_var_form.file("file", local_var_param_value)?; + if let Some(param_value) = p_file { + multipart_form = multipart_form.file("file", param_value)?; } - local_var_req_builder = local_var_req_builder.multipart(local_var_form); + req_builder = req_builder.multipart(multipart_form); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/store_api.rs b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/store_api.rs index d1ad7c4a4fc6b..c4d6b07478e1f 100644 --- a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/store_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/store_api.rs @@ -51,138 +51,128 @@ pub enum PlaceOrderError { /// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors pub fn delete_order(configuration: &configuration::Configuration, order_id: &str) -> Result<(), Error> { - let local_var_configuration = configuration; + // add a prefix to parameters to efficiently prevent name collisions + let p_order_id = order_id; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/store/order/{orderId}", configuration.base_path, orderId=crate::apis::urlencode(p_order_id)); + let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str); - let local_var_uri_str = format!("{}/store/order/{orderId}", local_var_configuration.base_path, orderId=crate::apis::urlencode(order_id)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + if !status.is_client_error() && !status.is_server_error() { Ok(()) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// Returns a map of status codes to quantities pub fn get_inventory(configuration: &configuration::Configuration, ) -> Result, Error> { - let local_var_configuration = configuration; - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/store/inventory", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + let uri_str = format!("{}/store/inventory", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - if let Some(ref local_var_aws_v4_key) = local_var_configuration.aws_v4_key { - let local_var_new_headers = match local_var_aws_v4_key.sign( - &local_var_uri_str, + if let Some(ref aws_v4_key) = configuration.aws_v4_key { + let new_headers = match aws_v4_key.sign( + &uri_str, "GET", "", ) { Ok(new_headers) => new_headers, Err(err) => return Err(Error::AWSV4SignatureError(err)), }; - for (local_var_name, local_var_value) in local_var_new_headers.iter() { - local_var_req_builder = local_var_req_builder.header(local_var_name.as_str(), local_var_value.as_str()); + for (name, value) in new_headers.iter() { + req_builder = req_builder.header(name.as_str(), value.as_str()); } } - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions pub fn get_order_by_id(configuration: &configuration::Configuration, order_id: i64) -> Result> { - let local_var_configuration = configuration; + // add a prefix to parameters to efficiently prevent name collisions + let p_order_id = order_id; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/store/order/{orderId}", configuration.base_path, orderId=p_order_id); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - let local_var_uri_str = format!("{}/store/order/{orderId}", local_var_configuration.base_path, orderId=order_id); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub fn place_order(configuration: &configuration::Configuration, order: models::Order) -> Result> { - let local_var_configuration = configuration; - - let local_var_client = &local_var_configuration.client; + // add a prefix to parameters to efficiently prevent name collisions + let p_order = order; - let local_var_uri_str = format!("{}/store/order", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + let uri_str = format!("{}/store/order", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - local_var_req_builder = local_var_req_builder.json(&order); + req_builder = req_builder.json(&p_order); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/testing_api.rs b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/testing_api.rs index 634576260d6ac..285fc2e06996d 100644 --- a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/testing_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/testing_api.rs @@ -31,57 +31,49 @@ pub enum TestsTypeTestingGetError { pub fn tests_file_response_get(configuration: &configuration::Configuration, ) -> Result> { - let local_var_configuration = configuration; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/tests/fileResponse", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - let local_var_uri_str = format!("{}/tests/fileResponse", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { - Ok(local_var_resp) + if !status.is_client_error() && !status.is_server_error() { + Ok(resp) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } pub fn tests_type_testing_get(configuration: &configuration::Configuration, ) -> Result> { - let local_var_configuration = configuration; - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/tests/typeTesting", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + let uri_str = format!("{}/tests/typeTesting", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/user_api.rs b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/user_api.rs index 3c186de94f980..c1fc777613d14 100644 --- a/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/user_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/apis/user_api.rs @@ -85,359 +85,343 @@ pub enum UpdateUserError { /// This can only be done by the logged in user. pub fn create_user(configuration: &configuration::Configuration, user: models::User) -> Result<(), Error> { - let local_var_configuration = configuration; + // add a prefix to parameters to efficiently prevent name collisions + let p_user = user; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/user", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - let local_var_uri_str = format!("{}/user", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); - - if let Some(ref local_var_aws_v4_key) = local_var_configuration.aws_v4_key { - let local_var_new_headers = match local_var_aws_v4_key.sign( - &local_var_uri_str, + if let Some(ref aws_v4_key) = configuration.aws_v4_key { + let new_headers = match aws_v4_key.sign( + &uri_str, "POST", - &serde_json::to_string(&user).expect("param should serialize to string"), + &serde_json::to_string(&p_user).expect("param should serialize to string"), ) { Ok(new_headers) => new_headers, Err(err) => return Err(Error::AWSV4SignatureError(err)), }; - for (local_var_name, local_var_value) in local_var_new_headers.iter() { - local_var_req_builder = local_var_req_builder.header(local_var_name.as_str(), local_var_value.as_str()); + for (name, value) in new_headers.iter() { + req_builder = req_builder.header(name.as_str(), value.as_str()); } } - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - local_var_req_builder = local_var_req_builder.json(&user); + req_builder = req_builder.json(&p_user); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + if !status.is_client_error() && !status.is_server_error() { Ok(()) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub fn create_users_with_array_input(configuration: &configuration::Configuration, user: Vec) -> Result<(), Error> { - let local_var_configuration = configuration; - - let local_var_client = &local_var_configuration.client; + // add a prefix to parameters to efficiently prevent name collisions + let p_user = user; - let local_var_uri_str = format!("{}/user/createWithArray", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + let uri_str = format!("{}/user/createWithArray", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - if let Some(ref local_var_aws_v4_key) = local_var_configuration.aws_v4_key { - let local_var_new_headers = match local_var_aws_v4_key.sign( - &local_var_uri_str, + if let Some(ref aws_v4_key) = configuration.aws_v4_key { + let new_headers = match aws_v4_key.sign( + &uri_str, "POST", - &serde_json::to_string(&user).expect("param should serialize to string"), + &serde_json::to_string(&p_user).expect("param should serialize to string"), ) { Ok(new_headers) => new_headers, Err(err) => return Err(Error::AWSV4SignatureError(err)), }; - for (local_var_name, local_var_value) in local_var_new_headers.iter() { - local_var_req_builder = local_var_req_builder.header(local_var_name.as_str(), local_var_value.as_str()); + for (name, value) in new_headers.iter() { + req_builder = req_builder.header(name.as_str(), value.as_str()); } } - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - local_var_req_builder = local_var_req_builder.json(&user); + req_builder = req_builder.json(&p_user); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + if !status.is_client_error() && !status.is_server_error() { Ok(()) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub fn create_users_with_list_input(configuration: &configuration::Configuration, user: Vec) -> Result<(), Error> { - let local_var_configuration = configuration; + // add a prefix to parameters to efficiently prevent name collisions + let p_user = user; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/user/createWithList", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - let local_var_uri_str = format!("{}/user/createWithList", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); - - if let Some(ref local_var_aws_v4_key) = local_var_configuration.aws_v4_key { - let local_var_new_headers = match local_var_aws_v4_key.sign( - &local_var_uri_str, + if let Some(ref aws_v4_key) = configuration.aws_v4_key { + let new_headers = match aws_v4_key.sign( + &uri_str, "POST", - &serde_json::to_string(&user).expect("param should serialize to string"), + &serde_json::to_string(&p_user).expect("param should serialize to string"), ) { Ok(new_headers) => new_headers, Err(err) => return Err(Error::AWSV4SignatureError(err)), }; - for (local_var_name, local_var_value) in local_var_new_headers.iter() { - local_var_req_builder = local_var_req_builder.header(local_var_name.as_str(), local_var_value.as_str()); + for (name, value) in new_headers.iter() { + req_builder = req_builder.header(name.as_str(), value.as_str()); } } - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - local_var_req_builder = local_var_req_builder.json(&user); + req_builder = req_builder.json(&p_user); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + if !status.is_client_error() && !status.is_server_error() { Ok(()) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// This can only be done by the logged in user. pub fn delete_user(configuration: &configuration::Configuration, username: &str) -> Result<(), Error> { - let local_var_configuration = configuration; - - let local_var_client = &local_var_configuration.client; + // add a prefix to parameters to efficiently prevent name collisions + let p_username = username; - let local_var_uri_str = format!("{}/user/{username}", local_var_configuration.base_path, username=crate::apis::urlencode(username)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str()); + let uri_str = format!("{}/user/{username}", configuration.base_path, username=crate::apis::urlencode(p_username)); + let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str); - if let Some(ref local_var_aws_v4_key) = local_var_configuration.aws_v4_key { - let local_var_new_headers = match local_var_aws_v4_key.sign( - &local_var_uri_str, + if let Some(ref aws_v4_key) = configuration.aws_v4_key { + let new_headers = match aws_v4_key.sign( + &uri_str, "DELETE", "", ) { Ok(new_headers) => new_headers, Err(err) => return Err(Error::AWSV4SignatureError(err)), }; - for (local_var_name, local_var_value) in local_var_new_headers.iter() { - local_var_req_builder = local_var_req_builder.header(local_var_name.as_str(), local_var_value.as_str()); + for (name, value) in new_headers.iter() { + req_builder = req_builder.header(name.as_str(), value.as_str()); } } - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + if !status.is_client_error() && !status.is_server_error() { Ok(()) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub fn get_user_by_name(configuration: &configuration::Configuration, username: &str) -> Result> { - let local_var_configuration = configuration; + // add a prefix to parameters to efficiently prevent name collisions + let p_username = username; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/user/{username}", configuration.base_path, username=crate::apis::urlencode(p_username)); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - let local_var_uri_str = format!("{}/user/{username}", local_var_configuration.base_path, username=crate::apis::urlencode(username)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub fn login_user(configuration: &configuration::Configuration, username: &str, password: &str) -> Result> { - let local_var_configuration = configuration; - - let local_var_client = &local_var_configuration.client; + // add a prefix to parameters to efficiently prevent name collisions + let p_username = username; + let p_password = password; - let local_var_uri_str = format!("{}/user/login", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + let uri_str = format!("{}/user/login", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - local_var_req_builder = local_var_req_builder.query(&[("username", &username.to_string())]); - local_var_req_builder = local_var_req_builder.query(&[("password", &password.to_string())]); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + req_builder = req_builder.query(&[("username", &p_username.to_string())]); + req_builder = req_builder.query(&[("password", &p_password.to_string())]); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub fn logout_user(configuration: &configuration::Configuration, ) -> Result<(), Error> { - let local_var_configuration = configuration; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/user/logout", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - let local_var_uri_str = format!("{}/user/logout", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_aws_v4_key) = local_var_configuration.aws_v4_key { - let local_var_new_headers = match local_var_aws_v4_key.sign( - &local_var_uri_str, + if let Some(ref aws_v4_key) = configuration.aws_v4_key { + let new_headers = match aws_v4_key.sign( + &uri_str, "GET", "", ) { Ok(new_headers) => new_headers, Err(err) => return Err(Error::AWSV4SignatureError(err)), }; - for (local_var_name, local_var_value) in local_var_new_headers.iter() { - local_var_req_builder = local_var_req_builder.header(local_var_name.as_str(), local_var_value.as_str()); + for (name, value) in new_headers.iter() { + req_builder = req_builder.header(name.as_str(), value.as_str()); } } - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + if !status.is_client_error() && !status.is_server_error() { Ok(()) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// This can only be done by the logged in user. pub fn update_user(configuration: &configuration::Configuration, username: &str, user: models::User) -> Result<(), Error> { - let local_var_configuration = configuration; - - let local_var_client = &local_var_configuration.client; + // add a prefix to parameters to efficiently prevent name collisions + let p_username = username; + let p_user = user; - let local_var_uri_str = format!("{}/user/{username}", local_var_configuration.base_path, username=crate::apis::urlencode(username)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str()); + let uri_str = format!("{}/user/{username}", configuration.base_path, username=crate::apis::urlencode(p_username)); + let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str); - if let Some(ref local_var_aws_v4_key) = local_var_configuration.aws_v4_key { - let local_var_new_headers = match local_var_aws_v4_key.sign( - &local_var_uri_str, + if let Some(ref aws_v4_key) = configuration.aws_v4_key { + let new_headers = match aws_v4_key.sign( + &uri_str, "PUT", - &serde_json::to_string(&user).expect("param should serialize to string"), + &serde_json::to_string(&p_user).expect("param should serialize to string"), ) { Ok(new_headers) => new_headers, Err(err) => return Err(Error::AWSV4SignatureError(err)), }; - for (local_var_name, local_var_value) in local_var_new_headers.iter() { - local_var_req_builder = local_var_req_builder.header(local_var_name.as_str(), local_var_value.as_str()); + for (name, value) in new_headers.iter() { + req_builder = req_builder.header(name.as_str(), value.as_str()); } } - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - local_var_req_builder = local_var_req_builder.json(&user); + req_builder = req_builder.json(&p_user); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + if !status.is_client_error() && !status.is_server_error() { Ok(()) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/docs/FakeApi.md b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/docs/FakeApi.md index 7fd650381887e..c41f7d7b0e2fe 100644 --- a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/docs/FakeApi.md +++ b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/docs/FakeApi.md @@ -10,7 +10,7 @@ Method | HTTP request | Description ## test_nullable_required_param -> test_nullable_required_param(user_name, dummy_required_nullable_param, uppercase) +> test_nullable_required_param(user_name, dummy_required_nullable_param, uppercase, content) To test nullable required parameters @@ -23,6 +23,7 @@ Name | Type | Description | Required | Notes **user_name** | **String** | The name that needs to be fetched. Use user1 for testing. | [required] | **dummy_required_nullable_param** | Option<**String**> | To test nullable required parameters | [required] | **uppercase** | Option<**String**> | To test parameter names in upper case | | +**content** | Option<**String**> | To test escaping of parameters in rust code works | | ### Return type diff --git a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/fake_api.rs b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/fake_api.rs index 3f39f065eb138..f607b9b069d48 100644 --- a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/fake_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/fake_api.rs @@ -26,37 +26,41 @@ pub enum TestNullableRequiredParamError { /// -pub fn test_nullable_required_param(configuration: &configuration::Configuration, user_name: &str, dummy_required_nullable_param: Option<&str>, uppercase: Option<&str>) -> Result<(), Error> { - let local_var_configuration = configuration; +pub fn test_nullable_required_param(configuration: &configuration::Configuration, user_name: &str, dummy_required_nullable_param: Option<&str>, uppercase: Option<&str>, content: Option<&str>) -> Result<(), Error> { + // add a prefix to parameters to efficiently prevent name collisions + let p_user_name = user_name; + let p_dummy_required_nullable_param = dummy_required_nullable_param; + let p_uppercase = uppercase; + let p_content = content; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/fake/user/{user_name}", configuration.base_path, user_name=crate::apis::urlencode(p_user_name)); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - let local_var_uri_str = format!("{}/fake/user/{user_name}", local_var_configuration.base_path, user_name=crate::apis::urlencode(user_name)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref param_value) = p_content { + req_builder = req_builder.query(&[("content", ¶m_value.to_string())]); + } + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - match dummy_required_nullable_param { - Some(local_var_param_value) => { local_var_req_builder = local_var_req_builder.header("dummy_required_nullable_param", local_var_param_value.to_string()); }, - None => { local_var_req_builder = local_var_req_builder.header("dummy_required_nullable_param", ""); }, + match p_dummy_required_nullable_param { + Some(param_value) => { req_builder = req_builder.header("dummy_required_nullable_param", param_value.to_string()); }, + None => { req_builder = req_builder.header("dummy_required_nullable_param", ""); }, } - if let Some(local_var_param_value) = uppercase { - local_var_req_builder = local_var_req_builder.header("UPPERCASE", local_var_param_value.to_string()); + if let Some(param_value) = p_uppercase { + req_builder = req_builder.header("UPPERCASE", param_value.to_string()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + if !status.is_client_error() && !status.is_server_error() { Ok(()) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/pet_api.rs b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/pet_api.rs index 7e57307d321ac..4e45df6ba1cde 100644 --- a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/pet_api.rs @@ -84,295 +84,285 @@ pub enum UploadFileError { /// pub fn add_pet(configuration: &configuration::Configuration, foo_pet: models::FooPet) -> Result> { - let local_var_configuration = configuration; + // add a prefix to parameters to efficiently prevent name collisions + let p_foo_pet = foo_pet; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/pet", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - let local_var_uri_str = format!("{}/pet", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - local_var_req_builder = local_var_req_builder.json(&foo_pet); + req_builder = req_builder.json(&p_foo_pet); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub fn delete_pet(configuration: &configuration::Configuration, pet_id: i64, api_key: Option<&str>) -> Result<(), Error> { - let local_var_configuration = configuration; - - let local_var_client = &local_var_configuration.client; + // add a prefix to parameters to efficiently prevent name collisions + let p_pet_id = pet_id; + let p_api_key = api_key; - let local_var_uri_str = format!("{}/pet/{petId}", local_var_configuration.base_path, petId=pet_id); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str()); + let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=p_pet_id); + let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(local_var_param_value) = api_key { - local_var_req_builder = local_var_req_builder.header("api_key", local_var_param_value.to_string()); + if let Some(param_value) = p_api_key { + req_builder = req_builder.header("api_key", param_value.to_string()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + if !status.is_client_error() && !status.is_server_error() { Ok(()) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// Multiple status values can be provided with comma separated strings pub fn find_pets_by_status(configuration: &configuration::Configuration, status: Vec, r#type: Option>) -> Result, Error> { - let local_var_configuration = configuration; + // add a prefix to parameters to efficiently prevent name collisions + let p_status = status; + let p_type = r#type; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/pet/findByStatus", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - let local_var_uri_str = format!("{}/pet/findByStatus", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - local_var_req_builder = match "csv" { - "multi" => local_var_req_builder.query(&status.into_iter().map(|p| ("status".to_owned(), p.to_string())).collect::>()), - _ => local_var_req_builder.query(&[("status", &status.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), + req_builder = match "csv" { + "multi" => req_builder.query(&p_status.into_iter().map(|p| ("status".to_owned(), p.to_string())).collect::>()), + _ => req_builder.query(&[("status", &p_status.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), }; - if let Some(ref local_var_str) = r#type { - local_var_req_builder = match "csv" { - "multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("type".to_owned(), p.to_string())).collect::>()), - _ => local_var_req_builder.query(&[("type", &local_var_str.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), + if let Some(ref param_value) = p_type { + req_builder = match "csv" { + "multi" => req_builder.query(¶m_value.into_iter().map(|p| ("type".to_owned(), p.to_string())).collect::>()), + _ => req_builder.query(&[("type", ¶m_value.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), }; } - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. pub fn find_pets_by_tags(configuration: &configuration::Configuration, tags: Vec) -> Result, Error> { - let local_var_configuration = configuration; - - let local_var_client = &local_var_configuration.client; + // add a prefix to parameters to efficiently prevent name collisions + let p_tags = tags; - let local_var_uri_str = format!("{}/pet/findByTags", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + let uri_str = format!("{}/pet/findByTags", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - local_var_req_builder = match "csv" { - "multi" => local_var_req_builder.query(&tags.into_iter().map(|p| ("tags".to_owned(), p.to_string())).collect::>()), - _ => local_var_req_builder.query(&[("tags", &tags.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), + req_builder = match "csv" { + "multi" => req_builder.query(&p_tags.into_iter().map(|p| ("tags".to_owned(), p.to_string())).collect::>()), + _ => req_builder.query(&[("tags", &p_tags.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), }; - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// Returns a single pet pub fn get_pet_by_id(configuration: &configuration::Configuration, pet_id: i64) -> Result> { - let local_var_configuration = configuration; + // add a prefix to parameters to efficiently prevent name collisions + let p_pet_id = pet_id; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=p_pet_id); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - let local_var_uri_str = format!("{}/pet/{petId}", local_var_configuration.base_path, petId=pet_id); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub fn update_pet(configuration: &configuration::Configuration, foo_pet: models::FooPet) -> Result> { - let local_var_configuration = configuration; - - let local_var_client = &local_var_configuration.client; + // add a prefix to parameters to efficiently prevent name collisions + let p_foo_pet = foo_pet; - let local_var_uri_str = format!("{}/pet", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str()); + let uri_str = format!("{}/pet", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - local_var_req_builder = local_var_req_builder.json(&foo_pet); + req_builder = req_builder.json(&p_foo_pet); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub fn update_pet_with_form(configuration: &configuration::Configuration, pet_id: i64, name: Option<&str>, status: Option<&str>) -> Result<(), Error> { - let local_var_configuration = configuration; + // add a prefix to parameters to efficiently prevent name collisions + let p_pet_id = pet_id; + let p_name = name; + let p_status = status; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=p_pet_id); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - let local_var_uri_str = format!("{}/pet/{petId}", local_var_configuration.base_path, petId=pet_id); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - let mut local_var_form_params = std::collections::HashMap::new(); - if let Some(local_var_param_value) = name { - local_var_form_params.insert("name", local_var_param_value.to_string()); + let mut multipart_form_params = std::collections::HashMap::new(); + if let Some(param_value) = p_name { + multipart_form_params.insert("name", param_value.to_string()); } - if let Some(local_var_param_value) = status { - local_var_form_params.insert("status", local_var_param_value.to_string()); + if let Some(param_value) = p_status { + multipart_form_params.insert("status", param_value.to_string()); } - local_var_req_builder = local_var_req_builder.form(&local_var_form_params); + req_builder = req_builder.form(&multipart_form_params); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + if !status.is_client_error() && !status.is_server_error() { Ok(()) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub fn upload_file(configuration: &configuration::Configuration, pet_id: i64, additional_metadata: Option<&str>, file: Option) -> Result> { - let local_var_configuration = configuration; - - let local_var_client = &local_var_configuration.client; + // add a prefix to parameters to efficiently prevent name collisions + let p_pet_id = pet_id; + let p_additional_metadata = additional_metadata; + let p_file = file; - let local_var_uri_str = format!("{}/pet/{petId}/uploadImage", local_var_configuration.base_path, petId=pet_id); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + let uri_str = format!("{}/pet/{petId}/uploadImage", configuration.base_path, petId=p_pet_id); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - let mut local_var_form = reqwest::blocking::multipart::Form::new(); - if let Some(local_var_param_value) = additional_metadata { - local_var_form = local_var_form.text("additionalMetadata", local_var_param_value.to_string()); + let mut multipart_form = reqwest::blocking::multipart::Form::new(); + if let Some(param_value) = p_additional_metadata { + multipart_form = multipart_form.text("additionalMetadata", param_value.to_string()); } - if let Some(local_var_param_value) = file { - local_var_form = local_var_form.file("file", local_var_param_value)?; + if let Some(param_value) = p_file { + multipart_form = multipart_form.file("file", param_value)?; } - local_var_req_builder = local_var_req_builder.multipart(local_var_form); + req_builder = req_builder.multipart(multipart_form); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/store_api.rs b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/store_api.rs index 6bce786967c45..bfcdf8e075ebb 100644 --- a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/store_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/store_api.rs @@ -51,125 +51,115 @@ pub enum PlaceOrderError { /// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors pub fn delete_order(configuration: &configuration::Configuration, order_id: &str) -> Result<(), Error> { - let local_var_configuration = configuration; + // add a prefix to parameters to efficiently prevent name collisions + let p_order_id = order_id; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/store/order/{orderId}", configuration.base_path, orderId=crate::apis::urlencode(p_order_id)); + let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str); - let local_var_uri_str = format!("{}/store/order/{orderId}", local_var_configuration.base_path, orderId=crate::apis::urlencode(order_id)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + if !status.is_client_error() && !status.is_server_error() { Ok(()) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// Returns a map of status codes to quantities pub fn get_inventory(configuration: &configuration::Configuration, ) -> Result, Error> { - let local_var_configuration = configuration; - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/store/inventory", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + let uri_str = format!("{}/store/inventory", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions pub fn get_order_by_id(configuration: &configuration::Configuration, order_id: i64) -> Result> { - let local_var_configuration = configuration; + // add a prefix to parameters to efficiently prevent name collisions + let p_order_id = order_id; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/store/order/{orderId}", configuration.base_path, orderId=p_order_id); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - let local_var_uri_str = format!("{}/store/order/{orderId}", local_var_configuration.base_path, orderId=order_id); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub fn place_order(configuration: &configuration::Configuration, foo_order: models::FooOrder) -> Result> { - let local_var_configuration = configuration; - - let local_var_client = &local_var_configuration.client; + // add a prefix to parameters to efficiently prevent name collisions + let p_foo_order = foo_order; - let local_var_uri_str = format!("{}/store/order", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + let uri_str = format!("{}/store/order", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - local_var_req_builder = local_var_req_builder.json(&foo_order); + req_builder = req_builder.json(&p_foo_order); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/testing_api.rs b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/testing_api.rs index 1b22593cdab6f..fb0745d6a62cb 100644 --- a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/testing_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/testing_api.rs @@ -31,57 +31,49 @@ pub enum TestsTypeTestingGetError { pub fn tests_file_response_get(configuration: &configuration::Configuration, ) -> Result> { - let local_var_configuration = configuration; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/tests/fileResponse", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - let local_var_uri_str = format!("{}/tests/fileResponse", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { - Ok(local_var_resp) + if !status.is_client_error() && !status.is_server_error() { + Ok(resp) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } pub fn tests_type_testing_get(configuration: &configuration::Configuration, ) -> Result> { - let local_var_configuration = configuration; - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/tests/typeTesting", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + let uri_str = format!("{}/tests/typeTesting", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/user_api.rs b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/user_api.rs index dbb0bf2ff5ffa..0d2f0f327dddc 100644 --- a/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/user_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore-model-name-prefix/src/apis/user_api.rs @@ -85,281 +85,265 @@ pub enum UpdateUserError { /// This can only be done by the logged in user. pub fn create_user(configuration: &configuration::Configuration, foo_user: models::FooUser) -> Result<(), Error> { - let local_var_configuration = configuration; + // add a prefix to parameters to efficiently prevent name collisions + let p_foo_user = foo_user; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/user", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - let local_var_uri_str = format!("{}/user", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - local_var_req_builder = local_var_req_builder.json(&foo_user); + req_builder = req_builder.json(&p_foo_user); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + if !status.is_client_error() && !status.is_server_error() { Ok(()) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub fn create_users_with_array_input(configuration: &configuration::Configuration, user: Vec) -> Result<(), Error> { - let local_var_configuration = configuration; - - let local_var_client = &local_var_configuration.client; + // add a prefix to parameters to efficiently prevent name collisions + let p_user = user; - let local_var_uri_str = format!("{}/user/createWithArray", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + let uri_str = format!("{}/user/createWithArray", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - local_var_req_builder = local_var_req_builder.json(&user); + req_builder = req_builder.json(&p_user); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + if !status.is_client_error() && !status.is_server_error() { Ok(()) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub fn create_users_with_list_input(configuration: &configuration::Configuration, user: Vec) -> Result<(), Error> { - let local_var_configuration = configuration; + // add a prefix to parameters to efficiently prevent name collisions + let p_user = user; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/user/createWithList", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - let local_var_uri_str = format!("{}/user/createWithList", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - local_var_req_builder = local_var_req_builder.json(&user); + req_builder = req_builder.json(&p_user); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + if !status.is_client_error() && !status.is_server_error() { Ok(()) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// This can only be done by the logged in user. pub fn delete_user(configuration: &configuration::Configuration, username: &str) -> Result<(), Error> { - let local_var_configuration = configuration; - - let local_var_client = &local_var_configuration.client; + // add a prefix to parameters to efficiently prevent name collisions + let p_username = username; - let local_var_uri_str = format!("{}/user/{username}", local_var_configuration.base_path, username=crate::apis::urlencode(username)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str()); + let uri_str = format!("{}/user/{username}", configuration.base_path, username=crate::apis::urlencode(p_username)); + let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + if !status.is_client_error() && !status.is_server_error() { Ok(()) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub fn get_user_by_name(configuration: &configuration::Configuration, username: &str) -> Result> { - let local_var_configuration = configuration; + // add a prefix to parameters to efficiently prevent name collisions + let p_username = username; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/user/{username}", configuration.base_path, username=crate::apis::urlencode(p_username)); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - let local_var_uri_str = format!("{}/user/{username}", local_var_configuration.base_path, username=crate::apis::urlencode(username)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub fn login_user(configuration: &configuration::Configuration, username: &str, password: &str) -> Result> { - let local_var_configuration = configuration; - - let local_var_client = &local_var_configuration.client; + // add a prefix to parameters to efficiently prevent name collisions + let p_username = username; + let p_password = password; - let local_var_uri_str = format!("{}/user/login", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + let uri_str = format!("{}/user/login", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - local_var_req_builder = local_var_req_builder.query(&[("username", &username.to_string())]); - local_var_req_builder = local_var_req_builder.query(&[("password", &password.to_string())]); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + req_builder = req_builder.query(&[("username", &p_username.to_string())]); + req_builder = req_builder.query(&[("password", &p_password.to_string())]); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub fn logout_user(configuration: &configuration::Configuration, ) -> Result<(), Error> { - let local_var_configuration = configuration; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/user/logout", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - let local_var_uri_str = format!("{}/user/logout", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + if !status.is_client_error() && !status.is_server_error() { Ok(()) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// This can only be done by the logged in user. pub fn update_user(configuration: &configuration::Configuration, username: &str, foo_user: models::FooUser) -> Result<(), Error> { - let local_var_configuration = configuration; - - let local_var_client = &local_var_configuration.client; + // add a prefix to parameters to efficiently prevent name collisions + let p_username = username; + let p_foo_user = foo_user; - let local_var_uri_str = format!("{}/user/{username}", local_var_configuration.base_path, username=crate::apis::urlencode(username)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str()); + let uri_str = format!("{}/user/{username}", configuration.base_path, username=crate::apis::urlencode(p_username)); + let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - local_var_req_builder = local_var_req_builder.json(&foo_user); + req_builder = req_builder.json(&p_foo_user); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + if !status.is_client_error() && !status.is_server_error() { Ok(()) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/petstore/rust/reqwest/petstore/docs/FakeApi.md b/samples/client/petstore/rust/reqwest/petstore/docs/FakeApi.md index 7fd650381887e..c41f7d7b0e2fe 100644 --- a/samples/client/petstore/rust/reqwest/petstore/docs/FakeApi.md +++ b/samples/client/petstore/rust/reqwest/petstore/docs/FakeApi.md @@ -10,7 +10,7 @@ Method | HTTP request | Description ## test_nullable_required_param -> test_nullable_required_param(user_name, dummy_required_nullable_param, uppercase) +> test_nullable_required_param(user_name, dummy_required_nullable_param, uppercase, content) To test nullable required parameters @@ -23,6 +23,7 @@ Name | Type | Description | Required | Notes **user_name** | **String** | The name that needs to be fetched. Use user1 for testing. | [required] | **dummy_required_nullable_param** | Option<**String**> | To test nullable required parameters | [required] | **uppercase** | Option<**String**> | To test parameter names in upper case | | +**content** | Option<**String**> | To test escaping of parameters in rust code works | | ### Return type diff --git a/samples/client/petstore/rust/reqwest/petstore/src/apis/fake_api.rs b/samples/client/petstore/rust/reqwest/petstore/src/apis/fake_api.rs index 3f39f065eb138..f607b9b069d48 100644 --- a/samples/client/petstore/rust/reqwest/petstore/src/apis/fake_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore/src/apis/fake_api.rs @@ -26,37 +26,41 @@ pub enum TestNullableRequiredParamError { /// -pub fn test_nullable_required_param(configuration: &configuration::Configuration, user_name: &str, dummy_required_nullable_param: Option<&str>, uppercase: Option<&str>) -> Result<(), Error> { - let local_var_configuration = configuration; +pub fn test_nullable_required_param(configuration: &configuration::Configuration, user_name: &str, dummy_required_nullable_param: Option<&str>, uppercase: Option<&str>, content: Option<&str>) -> Result<(), Error> { + // add a prefix to parameters to efficiently prevent name collisions + let p_user_name = user_name; + let p_dummy_required_nullable_param = dummy_required_nullable_param; + let p_uppercase = uppercase; + let p_content = content; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/fake/user/{user_name}", configuration.base_path, user_name=crate::apis::urlencode(p_user_name)); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - let local_var_uri_str = format!("{}/fake/user/{user_name}", local_var_configuration.base_path, user_name=crate::apis::urlencode(user_name)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref param_value) = p_content { + req_builder = req_builder.query(&[("content", ¶m_value.to_string())]); + } + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - match dummy_required_nullable_param { - Some(local_var_param_value) => { local_var_req_builder = local_var_req_builder.header("dummy_required_nullable_param", local_var_param_value.to_string()); }, - None => { local_var_req_builder = local_var_req_builder.header("dummy_required_nullable_param", ""); }, + match p_dummy_required_nullable_param { + Some(param_value) => { req_builder = req_builder.header("dummy_required_nullable_param", param_value.to_string()); }, + None => { req_builder = req_builder.header("dummy_required_nullable_param", ""); }, } - if let Some(local_var_param_value) = uppercase { - local_var_req_builder = local_var_req_builder.header("UPPERCASE", local_var_param_value.to_string()); + if let Some(param_value) = p_uppercase { + req_builder = req_builder.header("UPPERCASE", param_value.to_string()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + if !status.is_client_error() && !status.is_server_error() { Ok(()) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/petstore/rust/reqwest/petstore/src/apis/pet_api.rs b/samples/client/petstore/rust/reqwest/petstore/src/apis/pet_api.rs index ee502419401a2..7f7d08fef5a0d 100644 --- a/samples/client/petstore/rust/reqwest/petstore/src/apis/pet_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore/src/apis/pet_api.rs @@ -84,295 +84,285 @@ pub enum UploadFileError { /// pub fn add_pet(configuration: &configuration::Configuration, pet: models::Pet) -> Result> { - let local_var_configuration = configuration; + // add a prefix to parameters to efficiently prevent name collisions + let p_pet = pet; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/pet", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - let local_var_uri_str = format!("{}/pet", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - local_var_req_builder = local_var_req_builder.json(&pet); + req_builder = req_builder.json(&p_pet); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub fn delete_pet(configuration: &configuration::Configuration, pet_id: i64, api_key: Option<&str>) -> Result<(), Error> { - let local_var_configuration = configuration; - - let local_var_client = &local_var_configuration.client; + // add a prefix to parameters to efficiently prevent name collisions + let p_pet_id = pet_id; + let p_api_key = api_key; - let local_var_uri_str = format!("{}/pet/{petId}", local_var_configuration.base_path, petId=pet_id); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str()); + let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=p_pet_id); + let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(local_var_param_value) = api_key { - local_var_req_builder = local_var_req_builder.header("api_key", local_var_param_value.to_string()); + if let Some(param_value) = p_api_key { + req_builder = req_builder.header("api_key", param_value.to_string()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + if !status.is_client_error() && !status.is_server_error() { Ok(()) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// Multiple status values can be provided with comma separated strings pub fn find_pets_by_status(configuration: &configuration::Configuration, status: Vec, r#type: Option>) -> Result, Error> { - let local_var_configuration = configuration; + // add a prefix to parameters to efficiently prevent name collisions + let p_status = status; + let p_type = r#type; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/pet/findByStatus", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - let local_var_uri_str = format!("{}/pet/findByStatus", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - local_var_req_builder = match "csv" { - "multi" => local_var_req_builder.query(&status.into_iter().map(|p| ("status".to_owned(), p.to_string())).collect::>()), - _ => local_var_req_builder.query(&[("status", &status.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), + req_builder = match "csv" { + "multi" => req_builder.query(&p_status.into_iter().map(|p| ("status".to_owned(), p.to_string())).collect::>()), + _ => req_builder.query(&[("status", &p_status.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), }; - if let Some(ref local_var_str) = r#type { - local_var_req_builder = match "csv" { - "multi" => local_var_req_builder.query(&local_var_str.into_iter().map(|p| ("type".to_owned(), p.to_string())).collect::>()), - _ => local_var_req_builder.query(&[("type", &local_var_str.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), + if let Some(ref param_value) = p_type { + req_builder = match "csv" { + "multi" => req_builder.query(¶m_value.into_iter().map(|p| ("type".to_owned(), p.to_string())).collect::>()), + _ => req_builder.query(&[("type", ¶m_value.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), }; } - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. pub fn find_pets_by_tags(configuration: &configuration::Configuration, tags: Vec) -> Result, Error> { - let local_var_configuration = configuration; - - let local_var_client = &local_var_configuration.client; + // add a prefix to parameters to efficiently prevent name collisions + let p_tags = tags; - let local_var_uri_str = format!("{}/pet/findByTags", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + let uri_str = format!("{}/pet/findByTags", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - local_var_req_builder = match "csv" { - "multi" => local_var_req_builder.query(&tags.into_iter().map(|p| ("tags".to_owned(), p.to_string())).collect::>()), - _ => local_var_req_builder.query(&[("tags", &tags.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), + req_builder = match "csv" { + "multi" => req_builder.query(&p_tags.into_iter().map(|p| ("tags".to_owned(), p.to_string())).collect::>()), + _ => req_builder.query(&[("tags", &p_tags.into_iter().map(|p| p.to_string()).collect::>().join(",").to_string())]), }; - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// Returns a single pet pub fn get_pet_by_id(configuration: &configuration::Configuration, pet_id: i64) -> Result> { - let local_var_configuration = configuration; + // add a prefix to parameters to efficiently prevent name collisions + let p_pet_id = pet_id; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=p_pet_id); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - let local_var_uri_str = format!("{}/pet/{petId}", local_var_configuration.base_path, petId=pet_id); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub fn update_pet(configuration: &configuration::Configuration, pet: models::Pet) -> Result> { - let local_var_configuration = configuration; - - let local_var_client = &local_var_configuration.client; + // add a prefix to parameters to efficiently prevent name collisions + let p_pet = pet; - let local_var_uri_str = format!("{}/pet", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str()); + let uri_str = format!("{}/pet", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - local_var_req_builder = local_var_req_builder.json(&pet); + req_builder = req_builder.json(&p_pet); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub fn update_pet_with_form(configuration: &configuration::Configuration, pet_id: i64, name: Option<&str>, status: Option<&str>) -> Result<(), Error> { - let local_var_configuration = configuration; + // add a prefix to parameters to efficiently prevent name collisions + let p_pet_id = pet_id; + let p_name = name; + let p_status = status; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/pet/{petId}", configuration.base_path, petId=p_pet_id); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - let local_var_uri_str = format!("{}/pet/{petId}", local_var_configuration.base_path, petId=pet_id); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - let mut local_var_form_params = std::collections::HashMap::new(); - if let Some(local_var_param_value) = name { - local_var_form_params.insert("name", local_var_param_value.to_string()); + let mut multipart_form_params = std::collections::HashMap::new(); + if let Some(param_value) = p_name { + multipart_form_params.insert("name", param_value.to_string()); } - if let Some(local_var_param_value) = status { - local_var_form_params.insert("status", local_var_param_value.to_string()); + if let Some(param_value) = p_status { + multipart_form_params.insert("status", param_value.to_string()); } - local_var_req_builder = local_var_req_builder.form(&local_var_form_params); + req_builder = req_builder.form(&multipart_form_params); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + if !status.is_client_error() && !status.is_server_error() { Ok(()) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub fn upload_file(configuration: &configuration::Configuration, pet_id: i64, additional_metadata: Option<&str>, file: Option) -> Result> { - let local_var_configuration = configuration; - - let local_var_client = &local_var_configuration.client; + // add a prefix to parameters to efficiently prevent name collisions + let p_pet_id = pet_id; + let p_additional_metadata = additional_metadata; + let p_file = file; - let local_var_uri_str = format!("{}/pet/{petId}/uploadImage", local_var_configuration.base_path, petId=pet_id); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + let uri_str = format!("{}/pet/{petId}/uploadImage", configuration.base_path, petId=p_pet_id); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_token) = local_var_configuration.oauth_access_token { - local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); + if let Some(ref token) = configuration.oauth_access_token { + req_builder = req_builder.bearer_auth(token.to_owned()); }; - let mut local_var_form = reqwest::blocking::multipart::Form::new(); - if let Some(local_var_param_value) = additional_metadata { - local_var_form = local_var_form.text("additionalMetadata", local_var_param_value.to_string()); + let mut multipart_form = reqwest::blocking::multipart::Form::new(); + if let Some(param_value) = p_additional_metadata { + multipart_form = multipart_form.text("additionalMetadata", param_value.to_string()); } - if let Some(local_var_param_value) = file { - local_var_form = local_var_form.file("file", local_var_param_value)?; + if let Some(param_value) = p_file { + multipart_form = multipart_form.file("file", param_value)?; } - local_var_req_builder = local_var_req_builder.multipart(local_var_form); + req_builder = req_builder.multipart(multipart_form); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/petstore/rust/reqwest/petstore/src/apis/store_api.rs b/samples/client/petstore/rust/reqwest/petstore/src/apis/store_api.rs index e62feebbf8d90..9918f21ad4a4b 100644 --- a/samples/client/petstore/rust/reqwest/petstore/src/apis/store_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore/src/apis/store_api.rs @@ -51,125 +51,115 @@ pub enum PlaceOrderError { /// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors pub fn delete_order(configuration: &configuration::Configuration, order_id: &str) -> Result<(), Error> { - let local_var_configuration = configuration; + // add a prefix to parameters to efficiently prevent name collisions + let p_order_id = order_id; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/store/order/{orderId}", configuration.base_path, orderId=crate::apis::urlencode(p_order_id)); + let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str); - let local_var_uri_str = format!("{}/store/order/{orderId}", local_var_configuration.base_path, orderId=crate::apis::urlencode(order_id)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + if !status.is_client_error() && !status.is_server_error() { Ok(()) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// Returns a map of status codes to quantities pub fn get_inventory(configuration: &configuration::Configuration, ) -> Result, Error> { - let local_var_configuration = configuration; - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/store/inventory", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + let uri_str = format!("{}/store/inventory", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions pub fn get_order_by_id(configuration: &configuration::Configuration, order_id: i64) -> Result> { - let local_var_configuration = configuration; + // add a prefix to parameters to efficiently prevent name collisions + let p_order_id = order_id; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/store/order/{orderId}", configuration.base_path, orderId=p_order_id); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - let local_var_uri_str = format!("{}/store/order/{orderId}", local_var_configuration.base_path, orderId=order_id); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub fn place_order(configuration: &configuration::Configuration, order: models::Order) -> Result> { - let local_var_configuration = configuration; - - let local_var_client = &local_var_configuration.client; + // add a prefix to parameters to efficiently prevent name collisions + let p_order = order; - let local_var_uri_str = format!("{}/store/order", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + let uri_str = format!("{}/store/order", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - local_var_req_builder = local_var_req_builder.json(&order); + req_builder = req_builder.json(&p_order); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/petstore/rust/reqwest/petstore/src/apis/testing_api.rs b/samples/client/petstore/rust/reqwest/petstore/src/apis/testing_api.rs index 634576260d6ac..285fc2e06996d 100644 --- a/samples/client/petstore/rust/reqwest/petstore/src/apis/testing_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore/src/apis/testing_api.rs @@ -31,57 +31,49 @@ pub enum TestsTypeTestingGetError { pub fn tests_file_response_get(configuration: &configuration::Configuration, ) -> Result> { - let local_var_configuration = configuration; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/tests/fileResponse", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - let local_var_uri_str = format!("{}/tests/fileResponse", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { - Ok(local_var_resp) + if !status.is_client_error() && !status.is_server_error() { + Ok(resp) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } pub fn tests_type_testing_get(configuration: &configuration::Configuration, ) -> Result> { - let local_var_configuration = configuration; - - let local_var_client = &local_var_configuration.client; - let local_var_uri_str = format!("{}/tests/typeTesting", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + let uri_str = format!("{}/tests/typeTesting", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/client/petstore/rust/reqwest/petstore/src/apis/user_api.rs b/samples/client/petstore/rust/reqwest/petstore/src/apis/user_api.rs index 40505efb17f21..299e19063df29 100644 --- a/samples/client/petstore/rust/reqwest/petstore/src/apis/user_api.rs +++ b/samples/client/petstore/rust/reqwest/petstore/src/apis/user_api.rs @@ -85,281 +85,265 @@ pub enum UpdateUserError { /// This can only be done by the logged in user. pub fn create_user(configuration: &configuration::Configuration, user: models::User) -> Result<(), Error> { - let local_var_configuration = configuration; + // add a prefix to parameters to efficiently prevent name collisions + let p_user = user; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/user", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - let local_var_uri_str = format!("{}/user", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - local_var_req_builder = local_var_req_builder.json(&user); + req_builder = req_builder.json(&p_user); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + if !status.is_client_error() && !status.is_server_error() { Ok(()) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub fn create_users_with_array_input(configuration: &configuration::Configuration, user: Vec) -> Result<(), Error> { - let local_var_configuration = configuration; - - let local_var_client = &local_var_configuration.client; + // add a prefix to parameters to efficiently prevent name collisions + let p_user = user; - let local_var_uri_str = format!("{}/user/createWithArray", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); + let uri_str = format!("{}/user/createWithArray", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - local_var_req_builder = local_var_req_builder.json(&user); + req_builder = req_builder.json(&p_user); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + if !status.is_client_error() && !status.is_server_error() { Ok(()) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub fn create_users_with_list_input(configuration: &configuration::Configuration, user: Vec) -> Result<(), Error> { - let local_var_configuration = configuration; + // add a prefix to parameters to efficiently prevent name collisions + let p_user = user; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/user/createWithList", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str); - let local_var_uri_str = format!("{}/user/createWithList", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - local_var_req_builder = local_var_req_builder.json(&user); + req_builder = req_builder.json(&p_user); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + if !status.is_client_error() && !status.is_server_error() { Ok(()) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// This can only be done by the logged in user. pub fn delete_user(configuration: &configuration::Configuration, username: &str) -> Result<(), Error> { - let local_var_configuration = configuration; - - let local_var_client = &local_var_configuration.client; + // add a prefix to parameters to efficiently prevent name collisions + let p_username = username; - let local_var_uri_str = format!("{}/user/{username}", local_var_configuration.base_path, username=crate::apis::urlencode(username)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str()); + let uri_str = format!("{}/user/{username}", configuration.base_path, username=crate::apis::urlencode(p_username)); + let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + if !status.is_client_error() && !status.is_server_error() { Ok(()) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub fn get_user_by_name(configuration: &configuration::Configuration, username: &str) -> Result> { - let local_var_configuration = configuration; + // add a prefix to parameters to efficiently prevent name collisions + let p_username = username; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/user/{username}", configuration.base_path, username=crate::apis::urlencode(p_username)); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - let local_var_uri_str = format!("{}/user/{username}", local_var_configuration.base_path, username=crate::apis::urlencode(username)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub fn login_user(configuration: &configuration::Configuration, username: &str, password: &str) -> Result> { - let local_var_configuration = configuration; - - let local_var_client = &local_var_configuration.client; + // add a prefix to parameters to efficiently prevent name collisions + let p_username = username; + let p_password = password; - let local_var_uri_str = format!("{}/user/login", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); + let uri_str = format!("{}/user/login", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - local_var_req_builder = local_var_req_builder.query(&[("username", &username.to_string())]); - local_var_req_builder = local_var_req_builder.query(&[("password", &password.to_string())]); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + req_builder = req_builder.query(&[("username", &p_username.to_string())]); + req_builder = req_builder.query(&[("password", &p_password.to_string())]); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - 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) + if !status.is_client_error() && !status.is_server_error() { + let content = resp.text()?; + serde_json::from_str(&content).map_err(Error::from) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// pub fn logout_user(configuration: &configuration::Configuration, ) -> Result<(), Error> { - let local_var_configuration = configuration; - let local_var_client = &local_var_configuration.client; + let uri_str = format!("{}/user/logout", configuration.base_path); + let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str); - let local_var_uri_str = format!("{}/user/logout", local_var_configuration.base_path); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str()); - - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + if !status.is_client_error() && !status.is_server_error() { Ok(()) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } /// This can only be done by the logged in user. pub fn update_user(configuration: &configuration::Configuration, username: &str, user: models::User) -> Result<(), Error> { - let local_var_configuration = configuration; - - let local_var_client = &local_var_configuration.client; + // add a prefix to parameters to efficiently prevent name collisions + let p_username = username; + let p_user = user; - let local_var_uri_str = format!("{}/user/{username}", local_var_configuration.base_path, username=crate::apis::urlencode(username)); - let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str()); + let uri_str = format!("{}/user/{username}", configuration.base_path, username=crate::apis::urlencode(p_username)); + let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str); - if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { - local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); + if let Some(ref user_agent) = configuration.user_agent { + req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone()); } - if let Some(ref local_var_apikey) = local_var_configuration.api_key { - let local_var_key = local_var_apikey.key.clone(); - let local_var_value = match local_var_apikey.prefix { - Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key), - None => local_var_key, + if let Some(ref apikey) = configuration.api_key { + let key = apikey.key.clone(); + let value = match apikey.prefix { + Some(ref prefix) => format!("{} {}", prefix, key), + None => key, }; - local_var_req_builder = local_var_req_builder.header("api_key", local_var_value); + req_builder = req_builder.header("api_key", value); }; - local_var_req_builder = local_var_req_builder.json(&user); + req_builder = req_builder.json(&p_user); - let local_var_req = local_var_req_builder.build()?; - let local_var_resp = local_var_client.execute(local_var_req)?; + let req = req_builder.build()?; + let resp = configuration.client.execute(req)?; - let local_var_status = local_var_resp.status(); + let status = resp.status(); - if !local_var_status.is_client_error() && !local_var_status.is_server_error() { + if !status.is_client_error() && !status.is_server_error() { Ok(()) } else { - let local_var_content = local_var_resp.text()?; - let local_var_entity: Option = 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)) + let content = resp.text()?; + let entity: Option = serde_json::from_str(&content).ok(); + Err(Error::ResponseError(ResponseContent { status, content, entity })) } } diff --git a/samples/openapi3/client/petstore/dart-dio/oneof/pubspec.yaml b/samples/openapi3/client/petstore/dart-dio/oneof/pubspec.yaml index efc0d4ccd7021..d4121509b9096 100644 --- a/samples/openapi3/client/petstore/dart-dio/oneof/pubspec.yaml +++ b/samples/openapi3/client/petstore/dart-dio/oneof/pubspec.yaml @@ -3,11 +3,12 @@ version: 1.0.0 description: OpenAPI API client homepage: homepage + environment: - sdk: '>=2.15.0 <4.0.0' + sdk: '>=2.18.0 <4.0.0' dependencies: - dio: '^5.2.0' + dio: '^5.7.0' one_of: '>=1.5.0 <2.0.0' one_of_serializer: '>=1.5.0 <2.0.0' built_value: '>=8.4.0 <9.0.0' @@ -16,4 +17,4 @@ dependencies: dev_dependencies: built_value_generator: '>=8.4.0 <9.0.0' build_runner: any - test: ^1.16.0 + test: '^1.16.0' diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/pubspec.yaml b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/pubspec.yaml index efc0d4ccd7021..d4121509b9096 100644 --- a/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/pubspec.yaml +++ b/samples/openapi3/client/petstore/dart-dio/oneof_polymorphism_and_inheritance/pubspec.yaml @@ -3,11 +3,12 @@ version: 1.0.0 description: OpenAPI API client homepage: homepage + environment: - sdk: '>=2.15.0 <4.0.0' + sdk: '>=2.18.0 <4.0.0' dependencies: - dio: '^5.2.0' + dio: '^5.7.0' one_of: '>=1.5.0 <2.0.0' one_of_serializer: '>=1.5.0 <2.0.0' built_value: '>=8.4.0 <9.0.0' @@ -16,4 +17,4 @@ dependencies: dev_dependencies: built_value_generator: '>=8.4.0 <9.0.0' build_runner: any - test: ^1.16.0 + test: '^1.16.0' diff --git a/samples/openapi3/client/petstore/dart-dio/oneof_primitive/pubspec.yaml b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/pubspec.yaml index efc0d4ccd7021..d4121509b9096 100644 --- a/samples/openapi3/client/petstore/dart-dio/oneof_primitive/pubspec.yaml +++ b/samples/openapi3/client/petstore/dart-dio/oneof_primitive/pubspec.yaml @@ -3,11 +3,12 @@ version: 1.0.0 description: OpenAPI API client homepage: homepage + environment: - sdk: '>=2.15.0 <4.0.0' + sdk: '>=2.18.0 <4.0.0' dependencies: - dio: '^5.2.0' + dio: '^5.7.0' one_of: '>=1.5.0 <2.0.0' one_of_serializer: '>=1.5.0 <2.0.0' built_value: '>=8.4.0 <9.0.0' @@ -16,4 +17,4 @@ dependencies: dev_dependencies: built_value_generator: '>=8.4.0 <9.0.0' build_runner: any - test: ^1.16.0 + test: '^1.16.0' diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/pubspec.yaml b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/pubspec.yaml index 8a32778ad38ad..cbfddf172a6ce 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/pubspec.yaml +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake-json_serializable/pubspec.yaml @@ -3,14 +3,15 @@ version: 1.0.0 description: OpenAPI API client homepage: homepage + environment: - sdk: '>=2.17.0 <4.0.0' + sdk: '>=3.5.0 <4.0.0' dependencies: - dio: '^5.2.0' - json_annotation: '^4.4.0' + dio: '^5.7.0' + json_annotation: '^4.9.0' dev_dependencies: build_runner: any - json_serializable: '^6.1.5' - test: ^1.16.0 + json_serializable: '^6.9.3' + test: '^1.16.0' diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/pubspec.yaml b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/pubspec.yaml index efc0d4ccd7021..d4121509b9096 100644 --- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/pubspec.yaml +++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/pubspec.yaml @@ -3,11 +3,12 @@ version: 1.0.0 description: OpenAPI API client homepage: homepage + environment: - sdk: '>=2.15.0 <4.0.0' + sdk: '>=2.18.0 <4.0.0' dependencies: - dio: '^5.2.0' + dio: '^5.7.0' one_of: '>=1.5.0 <2.0.0' one_of_serializer: '>=1.5.0 <2.0.0' built_value: '>=8.4.0 <9.0.0' @@ -16,4 +17,4 @@ dependencies: dev_dependencies: built_value_generator: '>=8.4.0 <9.0.0' build_runner: any - test: ^1.16.0 + test: '^1.16.0'