From 4b03d81d02b2b66143ce908f2490567abb5c0bc6 Mon Sep 17 00:00:00 2001 From: ohmayr Date: Wed, 6 May 2026 16:33:47 +0000 Subject: [PATCH 1/2] chore: test CommonResource resource name alias --- .../tests/unit/schema/test_api.py | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/packages/gapic-generator/tests/unit/schema/test_api.py b/packages/gapic-generator/tests/unit/schema/test_api.py index 9d94e8251523..5cefe5ce7bad 100644 --- a/packages/gapic-generator/tests/unit/schema/test_api.py +++ b/packages/gapic-generator/tests/unit/schema/test_api.py @@ -4499,3 +4499,33 @@ def test_method_settings_invalid_multiple_issues(): assert re.match(".*squid.*not.*uuid4.*", error_yaml[method_example1][1].lower()) assert re.match(".*octopus.*not.*uuid4.*", error_yaml[method_example1][2].lower()) assert re.match(".*method.*not found.*", error_yaml[method_example2][0].lower()) + + +def test_file_level_resources_with_aliases(): + """Proves that CLI aliases are passed down to file-level CommonResources.""" + fdp = make_file_pb2( + name="nomenclature.proto", + package="nomenclature.linneaen.v1", + messages=( + make_message_pb2( + name="CreateSpeciesRequest", + fields=(make_field_pb2(name="species", number=1, type=9),), + ), + ), + ) + res_pb2 = fdp.options.Extensions[resource_pb2.resource_definition] + resource_definition = res_pb2.add() + resource_definition.type = "nomenclature.linnaen.com/Species" + resource_definition.pattern.append("families/{family}/genera/{genus}/species/{species}") + + # Pass down the resource-name-alias cli option + opts = Options.build("resource-name-alias=nomenclature.linnaen.com/Species:CustomSpecies") + + api_schema = api.API.build([fdp], package="nomenclature.linneaen.v1", opts=opts) + + # Trigger the property that evaluates the CommonResource + resource_msgs = api_schema.protos["nomenclature.proto"].resource_messages + + # Verify that the resource exists with the overriden type + assert "nomenclature.linnaen.com/Species" in resource_msgs + assert resource_msgs["nomenclature.linnaen.com/Species"].resource_type == "CustomSpecies" \ No newline at end of file From da3c19071e44f8c06072cd18f525ff1cfb1248fc Mon Sep 17 00:00:00 2001 From: ohmayr Date: Wed, 6 May 2026 16:35:12 +0000 Subject: [PATCH 2/2] add newline --- packages/gapic-generator/tests/unit/schema/test_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gapic-generator/tests/unit/schema/test_api.py b/packages/gapic-generator/tests/unit/schema/test_api.py index 5cefe5ce7bad..cb3661ee580a 100644 --- a/packages/gapic-generator/tests/unit/schema/test_api.py +++ b/packages/gapic-generator/tests/unit/schema/test_api.py @@ -4528,4 +4528,4 @@ def test_file_level_resources_with_aliases(): # Verify that the resource exists with the overriden type assert "nomenclature.linnaen.com/Species" in resource_msgs - assert resource_msgs["nomenclature.linnaen.com/Species"].resource_type == "CustomSpecies" \ No newline at end of file + assert resource_msgs["nomenclature.linnaen.com/Species"].resource_type == "CustomSpecies"