-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Description
Is your feature request related to a problem? Please describe.
I'm always frustrated when I try to read the api code and the only thing i see is local_var_ everywhere, makes it really hard to focus on the code.
Describe the solution you'd like
get rid of local_var_
Additional context
The majority of languages supported don't have local_var_.
So it seems like most of this coding is 3-4 years old, I found one specific issue linked to this: #10421 , It's kinda hard to reproduce whats the original error, because the referenced logs are long gone. but from they change: #10419 I guess that have a parameter called configuration and then wanted to generate the source code with the flag useSingleRequestParameter .
That results in a problem when unboxing the single parameter here:
openapi-generator/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache
Line 88 in 47665aa
| let {{paramName}} = params.{{paramName}}; |
The solution kinda works, because the internal variable is no longer called configuration but now local_var_configuration. However this makes it very hard to read and will fails as soon as someone tries to insert a parameter local_var_configuration.
Knowing that most of the code is ~3 years old I can imagine the borrow checker having problems back then which needed this unboxing. However we could prob completely avoid it, and thus avoid any problems due to parameter names.
Note: as you have seen, this issue could also be interpreted as [BUG]. For me its a feature, because I want to read the code, but if you want me to rephrase it, just tell me and I will open another ticket.
Example
pub async fn get_auth_token(configuration: &configuration::Configuration, username: &str, get_auth_token_request: models::GetAuthTokenRequest) -> Result<String, Error<GetAuthTokenError>> {
let local_var_configuration = configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/auth/v1/{username}/token", local_var_configuration.base_path, username=crate::apis::urlencode(username));
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());
}
local_var_req_builder = local_var_req_builder.json(&get_auth_token_request);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<GetAuthTokenError> = 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))
}
}vs
pub async fn get_auth_token(configuration: &configuration::Configuration, username: &str, get_auth_token_request: models::GetAuthTokenRequest) -> Result<String, Error<GetAuthTokenError>> {
let uri_str = format!("{}/auth/v1/{username}/token", configuration.base_path, username=crate::apis::urlencode(username));
let mut req_builder = configuration.client.request(reqwest::Method::POST, uri_str.as_str());
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = req_builder.json(&get_auth_token_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content = resp.text().await?;
if !status.is_client_error() && !status.is_server_error() {
serde_json::from_str(&content).map_err(Error::from)
} else {
let entity: Option<GetAuthTokenError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
``