Skip to content

fix: pass resource aliases to file-level CommonResources#16945

Merged
jskeet merged 2 commits intomainfrom
add-namespace-alias-to-CommonResource
May 6, 2026
Merged

fix: pass resource aliases to file-level CommonResources#16945
jskeet merged 2 commits intomainfrom
add-namespace-alias-to-CommonResource

Conversation

@ohmayr
Copy link
Copy Markdown
Contributor

@ohmayr ohmayr commented May 5, 2026

File-level resources (like imported dependencies) were previously starved of CLI aliases during dummy MessageType creation. This caused false-positive namespace collisions because the collision checker couldn't see the explicit aliases.

This wires opts.resource_name_aliases down through api.py into CommonResource.build() so the alias resolution works as originally intended.

Fixes: #16952

@ohmayr ohmayr requested a review from a team as a code owner May 5, 2026 16:32
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 support for resource name aliases by introducing a resource_name_aliases field to the Proto and CommonResource classes and ensuring its propagation throughout the schema generation process. A review comment identifies a potential debug leftover in an error message within wrappers.py where a raw dictionary is printed, suggesting its removal to ensure the output remains clean and user-friendly.

Comment on lines 2345 to 2349
f"To protect backward compatibility, explicitly alias one of these using "
f"the `--resource-name-alias` CLI parameter.\n"
f"Example: --resource-name-alias={msg.resource_type_full_path}:CustomName\n"
f"{seen_types}"
)
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 inclusion of {seen_types} in the error message appears to be a debug leftover. Printing a raw dictionary of objects in a user-facing error message is generally not recommended as it can be very verbose and difficult to read. If you intended to provide more context about the collision, consider formatting the output to only show the relevant conflicting types.

                    f"To protect backward compatibility, explicitly alias one of these using "
                    f"the --resource-name-alias CLI parameter.\\n"
                    f"Example: --resource-name-alias={msg.resource_type_full_path}:CustomName\\n"
                )

Copy link
Copy Markdown
Contributor

@parthea parthea left a comment

Choose a reason for hiding this comment

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

nit: This PR fixes issue #16952 but does not add tests. We should add tests to avoid regressions

@jskeet jskeet merged commit 9652a08 into main May 6, 2026
141 of 146 checks passed
@jskeet jskeet deleted the add-namespace-alias-to-CommonResource branch May 6, 2026 16:19
ohmayr added a commit that referenced this pull request May 6, 2026
Add a test case for resource name alias functionality in
CommonResources. This is to support
#16945.
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.

gapic-generator: --resource-name-alias is ignored for file-level resource definitions, causing false-positive namespace collisions

3 participants