Skip to content

Commit 77c159f

Browse files
authored
fix: fix wildcard resource names helper method (#1363)
This fixes googleapis/gapic-generator-python#1358
1 parent 12ee205 commit 77c159f

5 files changed

Lines changed: 41 additions & 14 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,10 @@ def path_regex_str(self) -> str:
596596
) +
597597
"$"
598598
)
599+
# Special case for wildcard resource names
600+
if parsing_regex_str == "^*$":
601+
parsing_regex_str = "^.*$"
602+
599603
return parsing_regex_str
600604

601605
def get_field(self, *field_path: str,

packages/gapic-generator/tests/integration/BUILD.bazel

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,17 @@ py_gapic_library(
9191
],
9292
)
9393

94-
# Uncomment once https://github.com/googleapis/gapic-generator-python/issues/1358 is fixed
95-
#py_test(
96-
# name = "eventarc_py_gapic_test",
97-
# srcs = [
98-
# "eventarc_py_gapic_pytest.py",
99-
# "eventarc_py_gapic_test.py",
100-
# ],
101-
# legacy_create_init = False,
102-
# deps = [
103-
# ":eventarc_py_gapic",
104-
# ],
105-
#)
94+
py_test(
95+
name = "eventarc_py_gapic_test",
96+
srcs = [
97+
"eventarc_py_gapic_pytest.py",
98+
"eventarc_py_gapic_test.py",
99+
],
100+
legacy_create_init = False,
101+
deps = [
102+
":eventarc_py_gapic",
103+
],
104+
)
106105

107106
# Logging.
108107
py_gapic_library(
@@ -154,6 +153,7 @@ test_suite(
154153
name = "googleapis_test_suite",
155154
tests = [
156155
":credentials_py_gapic_test",
156+
":eventarc_py_gapic_test",
157157
":redis_py_gapic_test",
158158
],
159159
)

packages/gapic-generator/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def asset_path() -> str:
171171
@staticmethod
172172
def parse_asset_path(path: str) -> Dict[str,str]:
173173
"""Parses a asset path into its component segments."""
174-
m = re.match(r"^*$", path)
174+
m = re.match(r"^.*$", path)
175175
return m.groupdict() if m else {}
176176

177177
@staticmethod

packages/gapic-generator/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def service_path() -> str:
176176
@staticmethod
177177
def parse_service_path(path: str) -> Dict[str,str]:
178178
"""Parses a service path into its component segments."""
179-
m = re.match(r"^*$", path)
179+
m = re.match(r"^.*$", path)
180180
return m.groupdict() if m else {}
181181

182182
@staticmethod

packages/gapic-generator/tests/unit/schema/wrappers/test_message.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,29 @@ def test_resource_path_with_wildcard():
223223
"kingdoms/my-kingdom/phyla/my-phylum/classes/") is None
224224

225225

226+
def test_resource_path_pure_wildcard():
227+
options = descriptor_pb2.MessageOptions()
228+
resource = options.Extensions[resource_pb2.resource]
229+
resource.pattern.append("*")
230+
resource.type = "taxonomy.biology.com/Class"
231+
message = make_message('Squid', options=options)
232+
233+
# Pure wildcard resource names do not really help construct resources
234+
# but they are a part of the spec so we need to support them, which means at
235+
# least not failing.
236+
assert message.resource_path == "*"
237+
assert message.resource_path_args == []
238+
assert message.resource_type == "Class"
239+
240+
# Pure wildcard resource names match everything...
241+
assert re.match(message.path_regex_str,
242+
"kingdoms/my-kingdom/phyla/my-phylum/classes/my-klass")
243+
assert re.match(message.path_regex_str,
244+
"kingdoms/my-kingdom/phyla/my-phylum/classes/my-klass/additional-segment")
245+
assert re.match(message.path_regex_str,
246+
"kingdoms/my-kingdom/phyla/my-phylum/classes/")
247+
248+
226249
def test_parse_resource_path():
227250
options = descriptor_pb2.MessageOptions()
228251
resource = options.Extensions[resource_pb2.resource]

0 commit comments

Comments
 (0)