Skip to content

Commit 6410558

Browse files
committed
address feedback
1 parent ada2ecc commit 6410558

2 files changed

Lines changed: 8 additions & 10 deletions

File tree

packages/gapic-generator/gapic/schema/wrappers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2346,8 +2346,8 @@ def gen_indirect_resources_used(message):
23462346
f"Resources '{incumbent.resource_type_full_path}' and '{msg.resource_type_full_path}' "
23472347
f"both flatten to the exact same method name.\n"
23482348
f"To protect backward compatibility, explicitly alias one of these using "
2349-
f"the `--resource-name-aliases` CLI parameter.\n"
2350-
f"Example: --resource-name-aliases='{{\"{msg.resource_type_full_path}\": \"CustomName\"}}'\n"
2349+
f"the `--resource-name-alias` CLI parameter.\n"
2350+
f"Example: --resource-name-alias={msg.resource_type_full_path}:CustomName\n"
23512351
)
23522352
seen_types[res_type] = msg
23532353

packages/gapic-generator/gapic/utils/options.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class Options:
7474
# For example, 'google.cloud.api.v1+google.cloud.anotherapi.v2'
7575
"proto-plus-deps",
7676
"gapic-version", # A version string following https://peps.python.org/pep-0440
77-
"resource-name-aliases",
77+
"resource-name-alias",
7878
)
7979
)
8080

@@ -191,14 +191,12 @@ def tweak_path(p):
191191
proto_plus_deps = tuple(proto_plus_deps[0].split("+"))
192192

193193
resource_name_aliases = {}
194-
resource_alias_strings = opts.pop("resource-name-aliases", None)
195-
if resource_alias_strings:
194+
for alias_mapping in opts.pop("resource-name-alias", []):
196195
try:
197-
# Strip single quotes that survive the Bazel/Shell transition
198-
raw_string = resource_alias_strings[-1].strip("'")
199-
resource_name_aliases = json.loads(raw_string)
200-
except json.JSONDecodeError as e:
201-
warnings.warn(f"Failed to parse resource-name-aliases JSON: {e} from string: {resource_alias_strings[-1]}")
196+
res_path, alias_name = alias_mapping.split(":", 1)
197+
resource_name_aliases[res_path.strip()] = alias_name.strip()
198+
except ValueError:
199+
warnings.warn(f"Invalid format for resource-name-alias: '{alias_mapping}'. Expected format 'resource.path/Name:AliasName'")
202200

203201
Options.resource_name_aliases_global = resource_name_aliases
204202

0 commit comments

Comments
 (0)