File tree Expand file tree Collapse file tree 2 files changed +10
-1
lines changed
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 2 files changed +10
-1
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff line change 3333import com .google .common .collect .ImmutableMap ;
3434import com .google .common .collect .ImmutableSet ;
3535import com .google .common .truth .Truth ;
36+ import java .util .HashSet ;
3637import java .util .Map ;
3738import java .util .Set ;
3839import 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 ;
You can’t perform that action at this time.
0 commit comments