[Rust] Use named lifetimes for UUID params in reqwest-trait (fix mockall build) - #24930
Open
brbousnguar wants to merge 1 commit into
Open
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the Rust
reqwest-traitclient failing to compile withmockall=truewhen an operation has an optional (or required-nullable) UUID parameter.Closes #24912
Root cause
rust/reqwest-trait/api.mustachedeclares 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:#[automock]can handle an elided reference at the top level of an argument (id: &strcompiles), but not one nested inside another type. SoOption<&str>fails withE0106: 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:Only the
reqwest-traittemplate changes. The plainreqwesttemplate doesn't declare named lifetimes or use mockall, so it isn't affected. UUID arrays render asVec<uuid::Uuid>and are unchanged.Testing
RustClientCodegenTest#testReqwestTraitUuidParamsUseNamedLifetimeswith a regression spec atsrc/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:library=reqwest-trait,mockall=true,supportMiddleware=true,reqwestDefaultFeatures=rustls), then rancargo build --features mockall. Before the fix it failed with the E0106/E0637 errors from the issue. After the fix it builds, and plaincargo buildstill builds too.cargo test --features mockallthat sets expectations on and calls the generatedMockWidgetApimethods. It passes../bin/generate-samples.sh bin/configs/rust-reqwest-trait-petstore.yaml: no changes tosamples/, 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:
(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 -DskipTestsand 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-traitclient failing to compile withmockall=truewhen an operation has an optional (or required-nullable) UUID parameter. UUID parameters now render with the same named lifetime as string parameters (&'<param> str), soOption<&str>no longer causes E0106/E0637. Closes #24912.Written for commit d0265e1. Summary will update on new commits.