Skip to content

feat: add --resource-name-alias flag to resolve namespace collisions#16769

Open
ohmayr wants to merge 9 commits intomainfrom
configure-resource-name-aliases
Open

feat: add --resource-name-alias flag to resolve namespace collisions#16769
ohmayr wants to merge 9 commits intomainfrom
configure-resource-name-aliases

Conversation

@ohmayr
Copy link
Copy Markdown
Contributor

@ohmayr ohmayr commented Apr 22, 2026

Introduces the --resource-name-alias CLI flag to allow API owners
to safely disambiguate fully qualified resource paths that flatten
to identical method names in the generated client.

The flag accepts mappings in the format resource.path/Name:AliasName.
The configuration is parsed natively into the compiler Options and
injected into the schema models during construction, avoiding global
state mutations.

Example usage in BUILD.bazel:

--resource-name-alias=ces.googleapis.com/Tool:CesTool

Towards: b/505425328

@ohmayr ohmayr requested a review from a team as a code owner April 22, 2026 22:07
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 introduces a mechanism to resolve resource name collisions in the GAPIC generator via a new --resource-name-alias CLI parameter. Key changes include updating the Options and MessageType classes to handle these aliases and implementing a fail-fast collision detection check that raises a ValueError when conflicts occur. Feedback suggests that the generator should raise an error for malformed alias inputs to ensure fail-fast behavior instead of merely issuing a warning.


try:
# split(":", 1) ensures we only split on the FIRST colon
res_path, alias_name = mapping.split(":", 1)
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.

medium

The use of split(":", 1) correctly handles cases where the resource path itself might contain a colon. However, if the input string does not contain a colon, this will raise a ValueError. If the current logic in the except block returns an empty value, it should be changed to raise a ProgrammingError to ensure fail-fast behavior for unsupported input formats, rather than silently continuing.

References
  1. When a function receives parameters of an unsupported type, it should raise an error (e.g., ProgrammingError) instead of silently returning empty values. This ensures fail-fast behavior and prevents potential issues with missing parameter values in database operations.

parthea
parthea previously approved these changes Apr 22, 2026
Comment thread packages/gapic-generator/tests/unit/generator/test_options.py Outdated
@parthea parthea dismissed their stale review April 23, 2026 16:34

presubmits are failing

Comment thread packages/gapic-generator/gapic/schema/wrappers.py Outdated
@ohmayr ohmayr added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not merge Indicates a pull request not ready for merge, due to either quality or timing.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants