but_api macro: Auto export#13712
Draft
estib-vega wants to merge 4 commits into
Draft
Conversation
8f0810f to
bb3cdc2
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a new #[but_transport] attribute macro to standardize/auto-generate transport DTO boilerplate (serde + schemars + SDK registration), and updates many Rust DTOs across crates to use it. It also tightens schema export behavior by enforcing transport-marker usage and improving schema collection/duplicate handling for TypeScript generation.
Changes:
- Added
#[but_api_macros::but_transport]and applied it broadly to transport structs/enums to reduce repeated serde/schemars/SDK-registration boilerplate. - Updated
#[but_api]macro to collect/enforce exported transport types via a newbut_schemars::SdkTransportTypemarker. - Improved
but-tsschema collection to allow identical duplicate registrations while rejecting incompatible duplicates; updated generated SDK typings accordingly.
Reviewed changes
Copilot reviewed 69 out of 71 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/but-sdk/src/generated/index.d.ts | Regenerated SDK typings reflecting new transport macro behavior (notably casing changes). |
| crates/gitbutler-project/src/project.rs | Migrated project DTOs to #[but_transport]; adjusted schema hints for select fields. |
| crates/gitbutler-project/src/api.rs | Migrated API project wrapper DTO to #[but_transport]. |
| crates/gitbutler-project/Cargo.toml | Added but-api-macros dependency. |
| crates/gitbutler-operating-modes/src/lib.rs | Converted operating mode DTOs to #[but_transport] and removed manual schema registration boilerplate. |
| crates/gitbutler-operating-modes/Cargo.toml | Added but-api-macros dependency. |
| crates/gitbutler-edit-mode/src/lib.rs | Converted conflict DTO to #[but_transport]. |
| crates/gitbutler-edit-mode/Cargo.toml | Added but-api-macros dependency. |
| crates/gitbutler-branch/src/branch.rs | Converted BranchIdentity to #[but_transport] (with serialize/debug disabled due to custom impls). |
| crates/gitbutler-branch/Cargo.toml | Added but-api-macros dependency. |
| crates/gitbutler-branch-actions/src/upstream_integration.rs | Converted multiple upstream integration DTOs to #[but_transport]. |
| crates/gitbutler-branch-actions/src/remote.rs | Converted RemoteCommit DTO to #[but_transport]. |
| crates/gitbutler-branch-actions/src/branch.rs | Converted branch listing DTOs to #[but_transport]. |
| crates/gitbutler-branch-actions/src/base.rs | Converted base-branch DTO to #[but_transport]. |
| crates/gitbutler-branch-actions/Cargo.toml | Added but-api-macros dependency; expanded export-schema feature to include but-settings/export-schema. |
| crates/but-workspace/src/ui/ref_info.rs | Converted ref-info UI DTOs to #[but_transport]; adjusted imports. |
| crates/but-workspace/src/ui/mod.rs | Converted several UI DTOs/enums to #[but_transport] and removed manual schema registration. |
| crates/but-workspace/src/ui/author.rs | Converted UI author DTO to #[but_transport]. |
| crates/but-workspace/src/legacy/ui.rs | Converted legacy UI DTOs to #[but_transport]. |
| crates/but-workspace/src/legacy/mod.rs | Converted StacksFilter to #[but_transport] (not registered). |
| crates/but-workspace/src/commit/squash_commits.rs | Converted message-combination strategy enum to #[but_transport]. |
| crates/but-workspace/Cargo.toml | Added but-api-macros dependency. |
| crates/but-ts/src/main.rs | Refactored schema duplicate validation; added tests for duplicate handling. |
| crates/but-settings/src/app_settings.rs | Converted settings DTOs to #[but_transport]; removed manual registration calls. |
| crates/but-settings/Cargo.toml | Added but-api-macros dependency; added export-schema feature flag (empty). |
| crates/but-schemars/src/lib.rs | Added SdkTransportType marker trait for transport DTO enforcement. |
| crates/but-rebase/src/graph_rebase/mutate.rs | Converted InsertSide enum to #[but_transport]. |
| crates/but-rebase/Cargo.toml | Added but-api-macros dependency. |
| crates/but-irc/Cargo.toml | Switched but-settings dependency to workspace dependency. |
| crates/but-hunk-dependency/src/ui.rs | Converted hunk dependency UI DTOs to #[but_transport]. |
| crates/but-hunk-dependency/src/ranges/mod.rs | Converted calculation error DTO to #[but_transport]. |
| crates/but-hunk-dependency/Cargo.toml | Added but-api-macros dependency. |
| crates/but-hunk-assignment/src/lib.rs | Converted multiple hunk assignment DTOs/enums to #[but_transport] with tagging/rename options. |
| crates/but-hunk-assignment/Cargo.toml | Added but-api-macros dependency; reformatted export-schema feature list. |
| crates/but-gitlab/src/token.rs | Converted GitLab account identifier DTO to #[but_transport]. |
| crates/but-gitlab/src/lib.rs | Converted sensitive JSON response DTOs to #[but_transport]. |
| crates/but-gitlab/Cargo.toml | Added but-api-macros dependency. |
| crates/but-github/src/token.rs | Converted GitHub account identifier DTO to #[but_transport]. |
| crates/but-github/src/lib.rs | Converted sensitive JSON response DTOs to #[but_transport]. |
| crates/but-github/Cargo.toml | Added but-api-macros dependency; expanded export-schema feature to include but-settings/export-schema. |
| crates/but-forge/src/review.rs | Converted forge review DTOs to #[but_transport]; added schema hints for select chrono fields. |
| crates/but-forge/src/forge.rs | Converted ForgeName/ForgeUser transport enums to #[but_transport]. |
| crates/but-forge/src/ci.rs | Converted CI DTOs to #[but_transport]; added schema hints for chrono fields. |
| crates/but-forge/Cargo.toml | Added but-api-macros dependency. |
| crates/but-error/src/lib.rs | Converted error Code enum to #[but_transport]; added serde dependency/import. |
| crates/but-error/Cargo.toml | Added but-api-macros + serde dependencies. |
| crates/but-core/src/unified_diff.rs | Converted DiffHunk to #[but_transport]. |
| crates/but-core/src/ui.rs | Converted UI worktree change DTOs/enums to #[but_transport]. |
| crates/but-core/src/tree/mod.rs | Converted RejectionReason to #[but_transport]. |
| crates/but-core/src/settings.rs | Converted git-config UI DTO to #[but_transport]. |
| crates/but-core/src/ref_metadata.rs | Converted metadata DTOs to #[but_transport] with schema rename. |
| crates/but-core/src/lib.rs | Converted UnifiedPatch and ignored-worktree DTOs to #[but_transport]. |
| crates/but-core/src/diff/commit_details.rs | Converted LineStats to #[but_transport]. |
| crates/but-core/src/diff_types.rs | Converted diff-spec and hunk header DTOs to #[but_transport]. |
| crates/but-core/src/commit/mod.rs | Converted ConflictEntries to #[but_transport]. |
| crates/but-core/Cargo.toml | Added but-api-macros dependency. |
| crates/but-api/src/workspace.rs | Converted workspace JSON DTOs to #[but_transport]. |
| crates/but-api/src/watcher.rs | Converted watcher payload DTOs to #[but_transport]; removed direct schemars derive usage. |
| crates/but-api/src/platform.rs | Converted ServerCapabilities to #[but_transport(register = false)]. |
| crates/but-api/src/legacy/stack.rs | Converted legacy push result DTO to #[but_transport]. |
| crates/but-api/src/legacy/projects.rs | Converted ProjectForFrontend DTO to #[but_transport]. |
| crates/but-api/src/legacy/modes.rs | Converted legacy mode DTOs to #[but_transport]. |
| crates/but-api/src/legacy/forge.rs | Converted review template DTO to #[but_transport]. |
| crates/but-api/src/json.rs | Converted shared JSON DTOs to #[but_transport]. |
| crates/but-api/src/diff.rs | Converted diff JSON DTO to #[but_transport]. |
| crates/but-api/src/commit/json.rs | Converted commit JSON DTOs to #[but_transport]. |
| crates/but-api/src/branch.rs | Converted branch JSON DTOs to #[but_transport]. |
| crates/but-api/Cargo.toml | Made but-schemars optional and tied to export-schema; expanded export-schema feature deps. |
| crates/but-api-macros/src/lib.rs | Implemented #[but_transport]; added schema-export type collection and transport-marker enforcement in #[but_api]. |
| Cargo.lock | Updated lockfile for new/adjusted dependencies. |
Comments suppressed due to low confidence (1)
crates/gitbutler-project/src/api.rs:18
#[but_transport(register = false)]defaults to#[serde(rename_all = "camelCase")], which renames these computed fields fromgerrit_mode/forge_review_template_pathtogerritMode/forgeReviewTemplatePathin JSON and in the generated SDK typings. The desktop app still expects the original snake_case keys (e.g.projectsService.getProject(...).response?.gerrit_mode). If the legacy API is meant to remain snake_case, passrename_all = "snake_case"here (and keep#[serde(default)]behavior), or update all consumers in the same change set to use the camelCase keys.
Comment on lines
+179
to
185
| #[but_api_macros::but_transport] | ||
| pub struct ProjectForFrontend { | ||
| #[serde(flatten)] | ||
| pub inner: gitbutler_project::api::Project, | ||
| /// Tell if the project is known to be open in a Window in the frontend. | ||
| pub is_open: bool, | ||
| } |
9e1ad56 to
e44b673
Compare
e44b673 to
591dd4b
Compare
Automagically export the ‘complex types’ referenced in the function signatures. - Introduce `but_transport`, substituting most of the necessary boilerplate.
- Allow unexpected cfgs - Update snapshot to the new lines
591dd4b to
769a0a5
Compare
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.
Automagically export the ‘complex types’ referenced in the function
signatures.
but_transport, substituting most of the necessaryboilerplate.