Skip to content

Conversation

@dani-garcia
Copy link
Member

@dani-garcia dani-garcia commented Jul 4, 2025

๐ŸŽŸ๏ธ Tracking

https://bitwarden.atlassian.net/browse/PM-25542

๐Ÿ“” Objective

Note: The PR is absolutely massive because the generated code is very verbose (something that I plan to optimize in the future) and github is pretty bad about filtering out whitespace changes ๐Ÿ˜ž. To facilitate review I include some recommendations at the bottom of this block.

This template is trait based which should allow easier mocking. It also follows a similar pattern to our clients which I think would make it easier to use:

let config = client.internal.get_api_configurations().await;

// Old API
let res = bitwarden_api_api::apis::projects_api::projects_create(
    &config.api,
    input.organization_id,
    project,
).await?;

// New API
let res = config.api_client
    .projects_api()
    .create(input.organization_id, project)
    .await?;

The provided mocks are also typesafe and easy to use:

        let api_client = ApiClient::new_mocked(move |mock| {
            mock.folders_api
                .expect_post()
                .returning(move |model| {
                    Ok(FolderResponseModel {
                        id: Some(folder_id),
                        name: Some(model.unwrap().name),
                        revision_date: Some("2025-01-01T00:00:00Z".to_string()),
                        object: Some("folder".to_string()),
                    })
                })
                .once();
        });

PR structure

The PR is split in four commits:

  • Update OpenAPI and templates to latest version: Updates the openapi generator and the templates to the latest version. These files should match with the files at https://github.com/OpenAPITools/openapi-generator/tree/ee40887d47f6d7a16318772f49c63b8eb0553488/modules/openapi-generator/src/main/resources/rust I've also gone ahead and deleted some unused files to make it clearer which files are being used.
  • Add our changes to the templates
    • Updates to templates
      • README.mustache: Added the server commit hash to the readme
      • model.mustache and model_mod.mustache: Remove double option pattern, as we don't differentiate between not required and nullable, and they just add noise.
      • api.mustache: Made async-traits ?Send to support WASM
      • api.mustache: Used our custom x-action-name instead of operationID, so that function names are just functionName instead of ControllerName_FunctionName
      • api.mustache: Filtered deprecated operations out, no need to generate code for them when they shouldn't be used
      • api.mustache: Use uuid instead of &str for request parameters
      • api.mustache: Replaced all the function lifetimes by a single one. Previously it would create one per parameter, which is more flexible but made for some terrible function signatures.
      • api_mod.mustache: Replaced the root Api trait and implementations by a single ApiClient enum with both real and mock impls. This is functionally the same but allows the compiler to better optimize out the unused functions (from 3.7MB to 2.2MB WASM blob size)
  • ๐Ÿค– Generate bindings: Generate the bindings using the template from the previous step. this is based on the server bindings from bitwarden/server@d384c0c
  • Update code to new api. Updated our code to build with the new template, most changes are very simple API adjustments, the biggest changes are in the client/internal.rs file and consist in modifications to how we initialize and update the ApiConfigurations struct to match the newer API.

PR review recommendation

As this PR edits the generated bindings, the total changes are huge and difficult to review. As such, I've written a suggested review guide for the teams.

For vault/auth

Filter by team owned, the vault/auth related changes are fairly small:

  • small update in the /sync code to use the new API
  • updated the folder API code to use the new API and new mocks
  • updated the send access code to use the new configuration

If filtering by team owned doesn't work, the non-platform changes are contained entirely in the fourth commit: 320ea80

For platform

Due to the big autogenerated changes, I recommend reviewing commit by commit. The first, third and fourth commits should be reviewed as normal. The second commit, marked as ๐Ÿค–, should instead be reviewed by regenerating the bindings and making sure that nothing is changed:

cd server
git checkout c93c3464732c93c9be593a3a55b032c029c4bd6f
pwsh ./dev/generate_openapi_files.ps1

cd ../sdk-internal
git pull
git checkout ps/migrate-to-openapi-rust-trait
./support/build-api.sh

git status
# This should report a clean work tree

โฐ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Protected functional changes with optionality (feature flags)
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation (Confluence, contributing docs) or informed the documentation
    team

๐Ÿฆฎ Reviewer guidelines

  • ๐Ÿ‘ (:+1:) or similar for great changes
  • ๐Ÿ“ (:memo:) or โ„น๏ธ (:information_source:) for notes or general info
  • โ“ (:question:) for questions
  • ๐Ÿค” (:thinking:) or ๐Ÿ’ญ (:thought_balloon:) for more open inquiry that's not quite a confirmed
    issue and could potentially benefit from discussion
  • ๐ŸŽจ (:art:) for suggestions / improvements
  • โŒ (:x:) or โš ๏ธ (:warning:) for more significant problems or concerns needing attention
  • ๐ŸŒฑ (:seedling:) or โ™ป๏ธ (:recycle:) for future improvements or indications of technical debt
  • โ› (:pick:) for minor or nitpick changes

@github-actions

This comment was marked as resolved.

@codecov

This comment was marked as resolved.

@Hinton
Copy link
Member

Hinton commented Jul 7, 2025

Should we open upstream issues and see if any of the changes can upstreamed?

It would be interesting to see how the mocked usage would be as a comparison to using wiremock.

@dani-garcia dani-garcia force-pushed the ps/migrate-to-openapi-rust-trait branch 3 times, most recently from 285bb80 to 94dbf76 Compare July 7, 2025 11:40
@dani-garcia

This comment was marked as outdated.

@dani-garcia dani-garcia force-pushed the ps/migrate-to-openapi-rust-trait branch 3 times, most recently from 689da35 to d98d249 Compare July 11, 2025 17:34
@dani-garcia dani-garcia force-pushed the ps/migrate-to-openapi-rust-trait branch 2 times, most recently from 60d0b85 to f867177 Compare July 21, 2025 15:52
@dani-garcia dani-garcia marked this pull request as ready for review July 21, 2025 16:37
@dani-garcia dani-garcia requested review from a team as code owners July 21, 2025 16:37
Hinton
Hinton previously approved these changes Jul 21, 2025
@dani-garcia dani-garcia marked this pull request as draft July 21, 2025 19:31
@dani-garcia

This comment was marked as outdated.

@dani-garcia dani-garcia force-pushed the ps/migrate-to-openapi-rust-trait branch 3 times, most recently from d4c8e00 to 90007b7 Compare July 31, 2025 16:43
@sonarqubecloud

This comment was marked as outdated.

@dani-garcia dani-garcia marked this pull request as ready for review July 31, 2025 16:53
@dani-garcia dani-garcia requested a review from Hinton July 31, 2025 16:53
@trmartin4 trmartin4 requested review from coroiu and removed request for justindbaur September 5, 2025 23:28
@dani-garcia dani-garcia force-pushed the ps/migrate-to-openapi-rust-trait branch 7 times, most recently from 96e306e to 320ea80 Compare September 19, 2025 14:06
@dani-garcia dani-garcia marked this pull request as ready for review September 19, 2025 14:24
@dani-garcia dani-garcia requested a review from a team as a code owner September 19, 2025 14:24
@dani-garcia dani-garcia requested a review from rr-bw September 19, 2025 14:24
@dani-garcia dani-garcia force-pushed the ps/migrate-to-openapi-rust-trait branch from 320ea80 to cfc6a0a Compare September 23, 2025 11:23
Copy link
Member

@Hinton Hinton left a comment

Choose a reason for hiding this comment

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

I've reviewed all code except the auto generated which i've confirmed matches the output from manually running it.

Copy link
Contributor

@JaredSnider-Bitwarden JaredSnider-Bitwarden left a comment

Choose a reason for hiding this comment

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

Auth file change LGTM!

@sonarqubecloud
Copy link

@dani-garcia dani-garcia merged commit d7ce769 into main Sep 26, 2025
50 checks passed
@dani-garcia dani-garcia deleted the ps/migrate-to-openapi-rust-trait branch September 26, 2025 17:35
bw-ghapp bot pushed a commit to bitwarden/sdk-swift that referenced this pull request Sep 26, 2025
dani-garcia added a commit that referenced this pull request Oct 3, 2025
## ๐ŸŽŸ๏ธ Tracking

<!-- Paste the link to the Jira or GitHub issue or otherwise describe /
point to where this change is coming from. -->

## ๐Ÿ“” Objective

In #343 I've made the bindings traits always ?Send as the `reqwest`
client on WASM is not Send. The issue is that this introduces problems
for other SDK clients where that require the code to be Send, for
example NAPI, which is used by Secrets Manager.

This PR updates the bindings to be ?Send only for the WASM architecture.

## โฐ Reminders before review

- Contributor guidelines followed
- All formatters and local linters executed and passed
- Written new unit and / or integration tests where applicable
- Protected functional changes with optionality (feature flags)
- Used internationalization (i18n) for all UI strings
- CI builds passed
- Communicated to DevOps any deployment requirements
- Updated any necessary documentation (Confluence, contributing docs) or
informed the documentation
  team

## ๐Ÿฆฎ Reviewer guidelines

<!-- Suggested interactions but feel free to use (or not) as you desire!
-->

- ๐Ÿ‘ (`:+1:`) or similar for great changes
- ๐Ÿ“ (`:memo:`) or โ„น๏ธ (`:information_source:`) for notes or general info
- โ“ (`:question:`) for questions
- ๐Ÿค” (`:thinking:`) or ๐Ÿ’ญ (`:thought_balloon:`) for more open inquiry
that's not quite a confirmed
  issue and could potentially benefit from discussion
- ๐ŸŽจ (`:art:`) for suggestions / improvements
- โŒ (`:x:`) or โš ๏ธ (`:warning:`) for more significant problems or
concerns needing attention
- ๐ŸŒฑ (`:seedling:`) or โ™ป๏ธ (`:recycle:`) for future improvements or
indications of technical debt
- โ› (`:pick:`) for minor or nitpick changes
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.

7 participants