From 48c6524af03432d510328c0e93a3f69d945a1922 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=A4rtens?= Date: Thu, 28 Nov 2024 12:42:37 +0100 Subject: [PATCH] fix #20198 get rid of `local_var_` in order to make the code more readable. Get rid of the "unbox" of parameters at function start, so that we dont have any problem with name clashes. --- .../codegen/languages/RustClientCodegen.java | 142 +++++++++++++ .../main/resources/rust/reqwest/api.mustache | 201 ++++++++---------- 2 files changed, 236 insertions(+), 107 deletions(-) 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 a82a3e0f96ce..1f808103b845 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 @@ -31,6 +31,7 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; +import java.util.Set; import java.util.stream.Collectors; import org.openapitools.codegen.CliOption; @@ -39,6 +40,7 @@ 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.meta.features.ClientModificationFeature; @@ -62,6 +64,8 @@ import io.swagger.v3.oas.models.media.Discriminator; import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.parameters.Parameter; +import io.swagger.v3.oas.models.parameters.RequestBody; import io.swagger.v3.parser.util.SchemaTypeUtil; import joptsimple.internal.Strings; import lombok.AccessLevel; @@ -678,4 +682,142 @@ public String toDefaultValue(Schema p) { return null; } } + + public class ExtendedCodegenParameter extends CodegenParameter { + @Setter protected String paramIdentifier; // either `{{paramName}}` or `params.{{paramName}}` + + + public ExtendedCodegenParameter(CodegenParameter cp) { + super(); + + // CodegenParameter members + this.isFormParam = cp.isFormParam; + this.isQueryParam = cp.isQueryParam; + this.isPathParam = cp.isPathParam; + this.isHeaderParam = cp.isHeaderParam; + this.isCookieParam = cp.isCookieParam; + this.isBodyParam = cp.isBodyParam; + this.isContainer = cp.isContainer; + this.isCollectionFormatMulti = cp.isCollectionFormatMulti; + this.isPrimitiveType = cp.isPrimitiveType; + this.isModel = cp.isModel; + this.isExplode = cp.isExplode; + this.baseName = cp.baseName; + this.paramName = cp.paramName; + this.dataType = cp.dataType; + this.datatypeWithEnum = cp.datatypeWithEnum; + this.dataFormat = cp.dataFormat; + this.contentType = cp.contentType; + this.collectionFormat = cp.collectionFormat; + this.description = cp.description; + this.unescapedDescription = cp.unescapedDescription; + this.baseType = cp.baseType; + this.defaultValue = cp.defaultValue; + this.enumName = cp.enumName; + this.style = cp.style; + this.nameInLowerCase = cp.nameInLowerCase; + this.example = cp.example; + this.jsonSchema = cp.jsonSchema; + this.isString = cp.isString; + this.isNumeric = cp.isNumeric; + this.isInteger = cp.isInteger; + this.isLong = cp.isLong; + this.isNumber = cp.isNumber; + this.isFloat = cp.isFloat; + this.isDouble = cp.isDouble; + this.isDecimal = cp.isDecimal; + this.isByteArray = cp.isByteArray; + this.isBinary = cp.isBinary; + this.isBoolean = cp.isBoolean; + this.isDate = cp.isDate; + this.isDateTime = cp.isDateTime; + this.isUuid = cp.isUuid; + this.isUri = cp.isUri; + this.isEmail = cp.isEmail; + this.isFreeFormObject = cp.isFreeFormObject; + this.isAnyType = cp.isAnyType; + this.isArray = cp.isArray; + this.isMap = cp.isMap; + this.isFile = cp.isFile; + this.isEnum = cp.isEnum; + this.isEnumRef = cp.isEnumRef; + this._enum = cp._enum; + this.allowableValues = cp.allowableValues; + this.items = cp.items; + this.additionalProperties = cp.additionalProperties; + this.vars = cp.vars; + this.requiredVars = cp.requiredVars; + this.mostInnerItems = cp.mostInnerItems; + this.vendorExtensions = cp.vendorExtensions; + this.hasValidation = cp.hasValidation; + this.isNullable = cp.isNullable; + this.required = cp.required; + this.maximum = cp.maximum; + this.exclusiveMaximum = cp.exclusiveMaximum; + this.minimum = cp.minimum; + this.exclusiveMinimum = cp.exclusiveMinimum; + this.maxLength = cp.maxLength; + this.minLength = cp.minLength; + this.pattern = cp.pattern; + this.maxItems = cp.maxItems; + this.minItems = cp.minItems; + this.uniqueItems = cp.uniqueItems; + this.multipleOf = cp.multipleOf; + this.setHasVars(cp.getHasVars()); + this.setHasRequired(cp.getHasRequired()); + this.setMaxProperties(cp.getMaxProperties()); + this.setMinProperties(cp.getMinProperties()); + + this.paramIdentifier = cp.paramName; + } + + @Override + public ExtendedCodegenParameter copy() { + CodegenParameter superCopy = super.copy(); + ExtendedCodegenParameter output = new ExtendedCodegenParameter(superCopy); + output.paramIdentifier = this.paramIdentifier; + return output; + } + + @Override + public String toString() { + String superString = super.toString(); + final StringBuilder sb = new StringBuilder(superString); + sb.append(", paramIdentifier=").append(paramIdentifier).append('\''); + return sb.toString(); + } + + protected void setPrefix(boolean prefix) { + if (prefix) { + this.paramIdentifier = "params." + this.paramName; + } else { + this.paramIdentifier = this.paramName; + } + } + } + + @Override + public ExtendedCodegenParameter fromParameter(Parameter parameter, Set imports) { + CodegenParameter cp = super.fromParameter(parameter, imports); + ExtendedCodegenParameter ecp = new ExtendedCodegenParameter(cp); + ecp.setPrefix(this.useSingleRequestParameter); + return ecp; + } + + @Override + public CodegenParameter fromFormProperty(String name, Schema propertySchema, Set imports) { + CodegenParameter cp = super.fromFormProperty(name, propertySchema, imports); + ExtendedCodegenParameter ecp = new ExtendedCodegenParameter(cp); + ecp.setPrefix(this.useSingleRequestParameter); + return ecp; + } + + @Override + public CodegenParameter fromRequestBody(RequestBody body, Set imports, String bodyParameterName) { + CodegenParameter cp = super.fromRequestBody(body, imports, bodyParameterName); + ExtendedCodegenParameter ecp = new ExtendedCodegenParameter(cp); + ecp.setPrefix(this.useSingleRequestParameter); + return ecp; + } + } 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 b96063531e61..208cee67c8b0 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,55 @@ 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; {{/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}}{{{paramIdentifier}}}{{^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(&{{{paramIdentifier}}}.into_iter().map(|p| ("{{{baseName}}}".to_owned(), p.to_string())).collect::>()), + _ => req_builder.query(&[("{{{baseName}}}", &{{{paramIdentifier}}}.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}}}", &{{{paramIdentifier}}}.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) = {{{paramIdentifier}}} { + 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) = {{{paramIdentifier}}} { + 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) = {{{paramIdentifier}}} { {{#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 +139,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 +153,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(&{{{paramIdentifier}}}).expect("param should serialize to string"), {{/bodyParams}} {{/hasBodyParam}} {{^hasBodyParam}} @@ -180,31 +169,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}}}", {{{paramIdentifier}}}{{#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 {{{paramIdentifier}}} { + 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) = {{{paramIdentifier}}} { + req_builder = req_builder.header("{{{baseName}}}", param_value{{#isArray}}.join(","){{/isArray}}.to_string()); } {{/required}} {{/headerParams}} @@ -214,38 +203,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 +242,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}}}", {{{paramIdentifier}}})?; {{/isNullable}} {{#isNullable}} - match {{{paramName}}} { - Some(local_var_param_value) => { local_var_form = local_var_form.file("{{{baseName}}}", local_var_param_value)?; }, + match {{{paramIdentifier}}} { + 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) = {{{paramIdentifier}}} { + multipart_form = multipart_form.file("{{{baseName}}}", param_value)?; } {{/required}} {{/supportAsync}} @@ -281,116 +270,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}}}", {{{paramIdentifier}}}{{#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 {{{paramIdentifier}}} { + 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) = {{{paramIdentifier}}} { + 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 {{{paramIdentifier}}} { + 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) = {{{paramIdentifier}}} { + 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}}}", {{{paramIdentifier}}}{{#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 {{{paramIdentifier}}} { + 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) = {{{paramIdentifier}}} { + 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({{{paramIdentifier}}}); {{/isFile}} {{^isFile}} - local_var_req_builder = local_var_req_builder.json(&{{{paramName}}}); + req_builder = req_builder.json(&{{{paramIdentifier}}}); {{/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 })) } }