Skip to content

Commit 57dedd3

Browse files
committed
fix: Add support for path wildcard.
1 parent d49e0f1 commit 57dedd3

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

sdk-platform-java/api-common-java/src/main/java/com/google/api/pathtemplate/PathTemplate.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ public Set<String> getResourceLiterals() {
336336
// If a template is /compute/v1/projects/{project}/locations/{location}, known resources are
337337
// "projects" and "locations", the canonical resource name is
338338
// projects/{project}/locations/{location}. See unit tests for all cases.
339+
// Canonical resource names may be incorrect if the http template contains singleton resources.
339340
public String getCanonicalResourceName(Set<String> knownResources) {
340341
if (knownResources == null) {
341342
return "";
@@ -372,7 +373,8 @@ public String getCanonicalResourceName(Set<String> knownResources) {
372373
if (innerSeg.kind() == SegmentKind.BINDING) {
373374
bindingStartIndex = j;
374375
break;
375-
} else if (innerSeg.kind() == SegmentKind.LITERAL) {
376+
} else if (innerSeg.kind() == SegmentKind.LITERAL
377+
|| innerSeg.kind() == SegmentKind.PATH_WILDCARD) {
376378
literalCountInBinding++;
377379
}
378380
}

sdk-platform-java/api-common-java/src/test/java/com/google/api/pathtemplate/PathTemplateTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.google.common.collect.ImmutableMap;
3434
import com.google.common.collect.ImmutableSet;
3535
import com.google.common.truth.Truth;
36+
import java.util.HashSet;
3637
import java.util.Map;
3738
import java.util.Set;
3839
import java.util.stream.Stream;
@@ -1053,6 +1054,12 @@ void testGetCanonicalResourceName_nullKnownResources() {
10531054
Truth.assertThat(template.getCanonicalResourceName(null)).isEmpty();
10541055
}
10551056

1057+
@Test
1058+
void testGetCanonicalResourceName_pathWildCard() {
1059+
PathTemplate template = PathTemplate.create("/v1/{resource=**}:setIamPolicy");
1060+
Truth.assertThat(template.getCanonicalResourceName(new HashSet<>())).isEqualTo("{resource=**}");
1061+
}
1062+
10561063
private static void assertPositionalMatch(Map<String, String> match, String... expected) {
10571064
Truth.assertThat(match).isNotNull();
10581065
int i = 0;

0 commit comments

Comments
 (0)