Skip to content

Commit

Permalink
fix: Update module alias to resolve naming conflict (#820)
Browse files Browse the repository at this point in the history
In the current design, the first character of each package is used to create an alias. I'd like to append the first character before underscores in the package name to further reduce conflicts.

Previously google.appengine_admin would have an alias prefix of ga. With this change, the alias prefix will be gaa.

Fixes: #819
  • Loading branch information
parthea committed Mar 23, 2021
1 parent a4b877d commit f5e9f36
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 6 additions & 3 deletions gapic/schema/metadata.py
Expand Up @@ -115,9 +115,12 @@ def module_alias(self) -> str:
return '_'.join(
(
''.join(
i[0]
for i in self.package
if i != self.api_naming.version
[
partial_name[0]
for i in self.package
for partial_name in i.split("_")
if i != self.api_naming.version
]
),
self.module,
)
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/schema/test_metadata.py
Expand Up @@ -184,6 +184,14 @@ def test_address_name_builtin_keyword():
)
assert addr_kword.module_alias == "gp_class"

addr_kword = metadata.Address(
name="Class",
module="class",
package=("google", "appengine_admin"),
api_naming=naming.NewNaming(proto_package="foo.bar.baz.v1"),
)
assert addr_kword.module_alias == "gaa_class"


def test_doc_nothing():
meta = metadata.Metadata()
Expand Down

0 comments on commit f5e9f36

Please sign in to comment.