Skip to content

[Rust] Use named lifetimes for UUID params in reqwest-trait (fix mockall build) - #24930

Open
brbousnguar wants to merge 1 commit into
OpenAPITools:masterfrom
brbousnguar:forge/24912-bug-rust-missing-lifetime-when-u
Open

[Rust] Use named lifetimes for UUID params in reqwest-trait (fix mockall build)#24930
brbousnguar wants to merge 1 commit into
OpenAPITools:masterfrom
brbousnguar:forge/24912-bug-rust-missing-lifetime-when-u

Conversation

@brbousnguar

@brbousnguar brbousnguar commented Sep 11, 2026

Copy link
Copy Markdown

Fixes the Rust reqwest-trait client failing to compile with mockall=true when an operation has an optional (or required-nullable) UUID parameter.

Closes #24912

Root cause

rust/reqwest-trait/api.mustache declares a lifetime per parameter on every trait method (fn list_widget_items<'id, 'run_id>(...)) and string parameters use it (&'status str). The UUID branch was left with a bare &str, so the issue's spec generated:

async fn list_widget_items<'id, 'run_id>(&self, id: &str, run_id: Option<&str>) -> ...

#[automock] can handle an elided reference at the top level of an argument (id: &str compiles), but not one nested inside another type. So Option<&str> fails with E0106: missing lifetime specifier / E0637. Plain string params never hit this because they already use the named lifetime.

Change

In both the trait declaration and the impl, the UUID branch now renders &'<param> str, the same as the string branch:

async fn list_widget_items<'id, 'run_id>(&self, id: &'id str, run_id: Option<&'run_id str>) -> ...

Only the reqwest-trait template changes. The plain reqwest template doesn't declare named lifetimes or use mockall, so it isn't affected. UUID arrays render as Vec<uuid::Uuid> and are unchanged.

Testing

  • New RustClientCodegenTest#testReqwestTraitUuidParamsUseNamedLifetimes with a regression spec at src/test/resources/3_0/rust/reqwest-trait-uuid-params.yaml (taken from the issue). It fails on the old template and passes with the fix:
    ./mvnw -B -pl modules/openapi-generator -am test -Dtest='RustClientCodegenTest' -Dsurefire.failIfNoSpecifiedTests=false
    
  • Generated the client from the issue's spec with the reporter's exact options (library=reqwest-trait,mockall=true,supportMiddleware=true,reqwestDefaultFeatures=rustls), then ran cargo build --features mockall. Before the fix it failed with the E0106/E0637 errors from the issue. After the fix it builds, and plain cargo build still builds too.
  • Also generated a wider spec (required-nullable UUID query param, optional UUID header param, UUID array query param) and ran a cargo test --features mockall that sets expectations on and calls the generated MockWidgetApi methods. It passes.
  • ./bin/generate-samples.sh bin/configs/rust-reqwest-trait-petstore.yaml: no changes to samples/, because the shared Rust petstore spec has no UUID operation parameters.

PR checklist

  • Read the contribution guidelines.

  • Run the following to build the project and update samples:

    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    

    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.

    Built with ./mvnw -pl modules/openapi-generator-cli -am package -DskipTests and regenerated the only affected config, bin/configs/rust-reqwest-trait-petstore.yaml (no diff). No generator options changed, so the docs export is unaffected.

  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

cc Rust technical committee: @frol @farcaller @richardwhiuk @paladinzh @jacob-pro @dsteeley


Summary by cubic

Fixes the Rust reqwest-trait client failing to compile with mockall=true when an operation has an optional (or required-nullable) UUID parameter. UUID parameters now render with the same named lifetime as string parameters (&'<param> str), so Option<&str> no longer causes E0106/E0637. Closes #24912.

  • Adds a regression test and OpenAPI spec covering an optional UUID query parameter.

Written for commit d0265e1. Summary will update on new commits.

Review in cubic

…all build)

The reqwest-trait template declares a lifetime for every parameter and
uses it for string parameters, but UUID parameters were rendered as a
bare `&str`. mockall's #[automock] cannot elide a reference nested in
another type, so an optional UUID parameter (`Option<&str>`) failed to
compile with E0106/E0637 when the mockall feature was enabled.

Render UUID parameters as `&'<param> str` in both the trait declaration
and the impl, matching the string branch.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Re-trigger cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] [RUST] Missing lifetime when using mockall feature and optional query parameter

1 participant