File tree Expand file tree Collapse file tree
sdk-platform-java/api-common-java/src
main/java/com/google/api/pathtemplate
test/java/com/google/api/pathtemplate Expand file tree Collapse file tree Original file line number Diff line number Diff 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 "" ;
Original file line number Diff line number Diff 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 =
You can’t perform that action at this time.
0 commit comments