feat: add --resource-name-alias flag to resolve namespace collisions#16769
feat: add --resource-name-alias flag to resolve namespace collisions#16769
--resource-name-alias flag to resolve namespace collisions#16769Conversation
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
- 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.
Introduces the
--resource-name-aliasCLI flag to allow API ownersto 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:
Towards: b/505425328