Skip to content

Commit e5142f1

Browse files
committed
fix: simplify logics to get the start of the binding.
1 parent 3bf58f0 commit e5142f1

File tree

2 files changed

+1
-32
lines changed

2 files changed

+1
-32
lines changed

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -341,20 +341,8 @@ public String getCanonicalResourceName(Set<String> knownResources) {
341341
return "";
342342
}
343343

344-
int firstBindingIndex = -1;
345-
for (int i = 0; i < segments.size(); i++) {
346-
if (segments.get(i).kind() == SegmentKind.BINDING) {
347-
firstBindingIndex = i;
348-
break;
349-
}
350-
}
351-
352-
if (firstBindingIndex == -1) {
353-
return "";
354-
}
355-
356344
int startIndex = 0;
357-
for (int i = firstBindingIndex - 1; i >= 0; i--) {
345+
for (int i = 0; i < segments.size(); i++) {
358346
Segment seg = segments.get(i);
359347
if (seg.kind() == SegmentKind.LITERAL) {
360348
String value = seg.value();

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

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -943,15 +943,6 @@ void testGetResourceLiterals_customVerb() {
943943
Truth.assertThat(template.getResourceLiterals()).containsExactly("projects", "instances");
944944
}
945945

946-
@Test
947-
void testGetResourceLiterals_multipleVersions() {
948-
PathTemplate template =
949-
PathTemplate.create(
950-
"v1/compute/v2/projects/{project}/locations/{location}/widgets/{widget}");
951-
Truth.assertThat(template.getResourceLiterals())
952-
.containsExactly("projects", "locations", "widgets");
953-
}
954-
955946
@Test
956947
void testGetCanonicalResourceName_namedBindingsSimple() {
957948
Set<String> moreKnownResources = ImmutableSet.of("projects", "locations", "bars");
@@ -1004,16 +995,6 @@ void testGetCanonicalResourceName_unknownResource() {
1004995
.isEqualTo("projects/{project}");
1005996
}
1006997

1007-
@Test
1008-
void testGetCanonicalResourceName_ignoreVersions() {
1009-
Set<String> knownResources = ImmutableSet.of("projects", "locations", "instances", "widgets");
1010-
PathTemplate template =
1011-
PathTemplate.create(
1012-
"v1/compute/v2/projects/{project}/locations/{location}/widgets/{widget}");
1013-
Truth.assertThat(template.getCanonicalResourceName(knownResources))
1014-
.isEqualTo("projects/{project}/locations/{location}/widgets/{widget}");
1015-
}
1016-
1017998
@Test
1018999
void testGetCanonicalResourceName_customVerb() {
10191000
Set<String> knownResources = ImmutableSet.of("projects", "locations", "instances", "widgets");

0 commit comments

Comments
 (0)