Skip to content

Commit 3bf58f0

Browse files
committed
docs: add comments.
1 parent ad9bc73 commit 3bf58f0

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,11 @@ public Set<String> getResourceLiterals() {
313313
continue;
314314
}
315315
if (inBinding) {
316+
// This is for extracting "projects" and "locations" from named binding
317+
// {name=projects/*/locations/*}
316318
canonicalSegments.add(value);
317319
} else if (i + 1 < segments.size() && segments.get(i + 1).kind() == SegmentKind.BINDING) {
320+
// This is for regular cases projects/{project}/locations/{location}
318321
canonicalSegments.add(value);
319322
}
320323
}
@@ -330,6 +333,9 @@ public Set<String> getResourceLiterals() {
330333
*/
331334
// For example, projects/{project} is a literal/binding pair. {bar=projects/*/locations/*/bars/*}
332335
// is a named binding.
336+
// If a template is /compute/v1/projects/{project}/locations/{location}, known resources are
337+
// "projects" and "locations", the canonical resource name is
338+
// projects/{project}/locations/{location}. See unit tests for all cases.
333339
public String getCanonicalResourceName(Set<String> knownResources) {
334340
if (knownResources == null) {
335341
return "";

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,15 @@ void testGetResourceLiterals_simplePath() {
903903
.containsExactly("projects", "locations", "widgets");
904904
}
905905

906+
@Test
907+
void testGetResourceLiterals_multipleLiterals() {
908+
PathTemplate template =
909+
PathTemplate.create(
910+
"/compute/v1/projects/{project}/global/locations/{location}/widgets/{widget}");
911+
Truth.assertThat(template.getResourceLiterals())
912+
.containsExactly("projects", "locations", "widgets");
913+
}
914+
906915
@Test
907916
void testGetResourceLiterals_regexPath() {
908917
PathTemplate template =

0 commit comments

Comments
 (0)