Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/gapic-generator/gapic/schema/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class Proto:
meta: metadata.Metadata = dataclasses.field(
default_factory=metadata.Metadata,
)
resource_name_aliases: Mapping[str, str] = dataclasses.field(default_factory=dict)

def __getattr__(self, name: str):
return getattr(self.file_pb2, name)
Expand Down Expand Up @@ -159,7 +160,7 @@ def messages(self) -> Mapping[str, wrappers.MessageType]:
def resource_messages(self) -> Mapping[str, wrappers.MessageType]:
"""Return the file level resources of the proto."""
file_resource_messages = (
(res.type, wrappers.CommonResource.build(res).message_type)
(res.type, wrappers.CommonResource.build(res, aliases=self.resource_name_aliases).message_type)
for res in self.file_pb2.options.Extensions[
resource_pb2.resource_definition
]
Expand Down Expand Up @@ -1214,6 +1215,7 @@ def proto(self) -> Proto:
meta=metadata.Metadata(
address=self.address,
),
resource_name_aliases=self.opts.resource_name_aliases,
)

# If this is not a file being generated, we do not need to
Expand Down
7 changes: 5 additions & 2 deletions packages/gapic-generator/gapic/schema/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2081,10 +2081,11 @@ def with_internal_methods(self, *, public_methods: Set[str]) -> "Method":
class CommonResource:
type_name: str
pattern: str
resource_name_aliases: Mapping[str, str] = dataclasses.field(default_factory=dict)

@classmethod
def build(cls, resource: resource_pb2.ResourceDescriptor):
return cls(type_name=resource.type, pattern=next(iter(resource.pattern)))
def build(cls, resource: resource_pb2.ResourceDescriptor, aliases: Optional[Mapping[str, str]] = None):
return cls(type_name=resource.type, pattern=next(iter(resource.pattern)), resource_name_aliases=aliases or {})

@utils.cached_property
def message_type(self):
Expand All @@ -2098,6 +2099,7 @@ def message_type(self):
fields={},
nested_enums={},
nested_messages={},
resource_name_aliases=self.resource_name_aliases,
)


Expand Down Expand Up @@ -2343,6 +2345,7 @@ def gen_indirect_resources_used(message):
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}"
)
Comment on lines 2345 to 2348
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"
                )

seen_types[res_type] = msg

Expand Down
Loading