Skip to content

[BUG] Rust generator does not do the local variable protection #7269

@UkonnRa

Description

@UkonnRa

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

Rust generator does not protect the local variables, so something like the followings will be generated:

    // Here, both input and local var have the param `client`, so the second one will shadow the first one
    fn revoke_consent_sessions(&self, subject: &str, client: Option<&str>, all: Option<bool>) -> Result<(), Error> {
        let configuration: &configuration::Configuration = self.configuration.borrow();
        // Maybe something like `localVarClient` is better
        // It would be better if conflict detection can be provided by the generator?
        let client = &configuration.client;

        let uri_str = format!("{}/oauth2/auth/sessions/consent", configuration.base_path);
        let mut req_builder = client.delete(uri_str.as_str());

        req_builder = req_builder.query(&[("subject", &subject.to_string())]);

        // Wrong `client`
        if let Some(ref s) = client {
            req_builder = req_builder.query(&[("client", &s.to_string())]);
        }
        if let Some(ref s) = all {
            req_builder = req_builder.query(&[("all", &s.to_string())]);
        }
        if let Some(ref user_agent) = configuration.user_agent {
            req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
        }

        // send request
        let req = req_builder.build()?;

        client.execute(req)?.error_for_status()?;
        Ok(())
    }
openapi-generator version

4.3.1

OpenAPI declaration file content or url

https://raw.githubusercontent.com/ory/hydra/master/.schema/api.swagger.json

Generation Details

config.yaml

library: reqwest

command

  openapi-generator generate -i https://raw.githubusercontent.com/ory/hydra/master/.schema/api.swagger.json -g rust -o output -c config.yaml
Steps to reproduce
  • Run the command before
  • You will see the error part in output/src/apis/admin_api.rs, function revoke_consent_sessions
Related issues/PRs
Suggest a fix
  • Maybe something like localVarClient is better
  • It would be better if conflict detection can be provided by the generator?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions