Skip to content

feat(internal/sidekick/rust): add helper functions for annotation list fields#4915

Open
perashanid wants to merge 1 commit intogoogleapis:mainfrom
perashanid:fix/sidekick-rust-helper-functions-1603
Open

feat(internal/sidekick/rust): add helper functions for annotation list fields#4915
perashanid wants to merge 1 commit intogoogleapis:mainfrom
perashanid:fix/sidekick-rust-helper-functions-1603

Conversation

@perashanid
Copy link
Copy Markdown
Contributor

@perashanid perashanid commented Mar 30, 2026

This PR adds helper functions to annotation structs in the Rust sidekick generator to check if list fields are non-empty. This eliminates the need for duplicate boolean fields in templates, making them cleaner and reducing opportunities for mistakes.

Changes Made:

  • Added HasRequiredPackages() to modelAnnotations
  • Added HasExternPackages() to modelAnnotations
  • Added HasDisabledRustdocWarnings() to modelAnnotations
  • Added HasDisabledClippyWarnings() to modelAnnotations
  • Added HasDefaultSystemParameters() to modelAnnotations
  • Added HasDefaultFeatures() to modelAnnotations
  • Added HasExtraModules() to modelAnnotations
  • Added HasSystemParameters() to methodAnnotation
  • Added HasAttributes() to methodAnnotation
  • Added HasQueryParams() to pathBindingAnnotation
  • Added HasSubstitutions() to pathBindingAnnotation
  • Added HasUniqueParameters() to pathInfoAnnotation
  • Added HasPollingPathParameters() to discoveryLroAnnotations
  • Added HasOtherFieldsInGroup() to fieldAnnotations

Technical Implementation:
Following the existing pattern in the codebase (e.g., HasServices(), HasLROs(), HasBindings()), each helper function returns true if the corresponding list field has a non-zero length. These functions can be used in mustache templates to conditionally render sections based on whether lists are populated.

Testing:

  • No errors or linting issues detected with getDiagnostics
  • Changes follow existing code patterns in the file
  • All helper functions follow the same simple pattern: return len(field) > 0

Fixes #1603

…t fields

Add helper functions to check if list fields are non-empty in annotation structs, replacing the need for duplicate boolean fields in templates. This makes templates cleaner and reduces opportunities for mistakes.

Helper functions added:
- modelAnnotations: HasRequiredPackages, HasExternPackages, HasDisabledRustdocWarnings, HasDisabledClippyWarnings, HasDefaultSystemParameters, HasDefaultFeatures, HasExtraModules
- methodAnnotation: HasSystemParameters, HasAttributes
- pathBindingAnnotation: HasQueryParams, HasSubstitutions
- pathInfoAnnotation: HasUniqueParameters
- discoveryLroAnnotations: HasPollingPathParameters
- fieldAnnotations: HasOtherFieldsInGroup

Fixes googleapis#1603
@perashanid perashanid requested a review from a team as a code owner March 30, 2026 17:54
@google-cla
Copy link
Copy Markdown

google-cla bot commented Mar 30, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds several helper methods to structs in internal/sidekick/rust/annotate.go to check for non-empty slices or maps using a Has naming convention. A review comment points out that the new HasSubstitutions method duplicates the existing HasVariablePath method and recommends consolidating them to avoid redundancy.

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.

sidekick: prefer helper functions over duplicate fields in codec annotations

1 participant