Skip to content

Commit 5dc67eb

Browse files
committed
fix: update docs
1 parent 57dedd3 commit 5dc67eb

File tree

1 file changed

+11
-8
lines changed
  • sdk-platform-java/api-common-java/src/main/java/com/google/api/pathtemplate

1 file changed

+11
-8
lines changed

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,8 @@ public Set<String> getResourceLiterals() {
309309
inBinding = false;
310310
} else if (seg.kind() == SegmentKind.LITERAL) {
311311
String value = seg.value();
312-
if (value.matches("^v\\d+[a-zA-Z0-9]*$")) { // just in case
312+
// Skipping version literals such as v1, v1beta1
313+
if (value.matches("^v\\d+[a-zA-Z0-9]*$")) {
313314
continue;
314315
}
315316
if (inBinding) {
@@ -329,16 +330,17 @@ public Set<String> getResourceLiterals() {
329330
* Returns the canonical resource name string. A canonical resource name is extracted from the
330331
* template by finding the version literal, then finding the last binding that is a
331332
* literal/binding pair or named binding, and then extracting the segments between the version
332-
* literal and the last binding.
333+
* literal and the last binding (inclusive). This is a heuristic method that should only be used
334+
* for allowlisted services. There are also known gaps, such as the fact that it does not work
335+
* properly for singleton resources.
333336
*/
334337
// For example, projects/{project} is a literal/binding pair. {bar=projects/*/locations/*/bars/*}
335338
// 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
339+
// If a template is /compute/v1/projects/{project}/locations/{location}, known resource literals
340+
// are "projects" and "locations", the canonical resource name would be
338341
// projects/{project}/locations/{location}. See unit tests for all cases.
339-
// Canonical resource names may be incorrect if the http template contains singleton resources.
340-
public String getCanonicalResourceName(Set<String> knownResources) {
341-
if (knownResources == null) {
342+
public String getCanonicalResourceName(Set<String> knownResourceLiterals) {
343+
if (knownResourceLiterals == null) {
342344
return "";
343345
}
344346

@@ -390,7 +392,8 @@ public String getCanonicalResourceName(Set<String> knownResources) {
390392
// Instead, we check if the literal segment immediately preceding it (e.g., "projects/")
391393
// is a known resource.
392394
Segment prevSeg = segments.get(bindingStartIndex - 1);
393-
if (prevSeg.kind() == SegmentKind.LITERAL && knownResources.contains(prevSeg.value())) {
395+
if (prevSeg.kind() == SegmentKind.LITERAL
396+
&& knownResourceLiterals.contains(prevSeg.value())) {
394397
isValidPair = true;
395398
}
396399
}

0 commit comments

Comments
 (0)