oxidecomputer / oxidecomputer/progenitor

Code generation produces invalid code when a query parameter is named "query"

Open
#717 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
1k
Forks
136
Avg merge
8h 36m
Merged PRs (30d)
14

Description

A query parameter named query results in variable shadowing that prevents the generated code from compiling. I would expect progenitor to detect this case and rename the generated query variable on line 7 to avoid the name collision.

See minimal example below:

    ///Sends a `GET` request to `/v0/leaderboards/ranked_1v1`
    pub async fn get_leaderboard<'a>(
        &'a self,
        query: Option<&'a str>,
    ) -> Result<ResponseValue<types::LeaderboardResponse>, Error<types::ErrorResponse>> {
        let url = format!("{}/v0/leaderboards/ranked_1v1", self.baseurl,);
        let mut query = Vec::with_capacity(1usize);

        if let Some(v) = &query {
            query.push(("query", v.to_string()));
        }

        let request = self
            .client
            .get(url)
            .header(
                reqwest::header::ACCEPT,
                reqwest::header::HeaderValue::from_static("application/json"),
            )
            .query(&query)
            .build()?;
        let result = self.client.execute(request).await;
        let response = result?;
        match response.status().as_u16() {
            200u16 => ResponseValue::from_response(response).await,
            500u16 => Err(Error::ErrorResponse(
                ResponseValue::from_response(response).await?,
            )),
            _ => Err(Error::UnexpectedResponse(response)),
        }
    }

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the minimal Rust example in the issue and the generator path that emits its query handling; reproduce the problem by compiling the generated function. Done when a query parameter named query no longer shadows the generated query collection and the generated Rust compiles.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api, devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.