Skip to content

Commit 5bfb1b8

Browse files
authored
fix(sidekick): ignore API version strings when building heuristic vocabulary (#4337)
When `BuildHeuristicVocabulary` dynamically learns collection names from method paths, it parses standard paths and assumes the string literal preceding a variable is a collection name. However, for APIs with flat paths like `/dns/v1/{resource}:setIamPolicy`, it incorrectly identified the API version v1 as a collection name since it immediately precedes a variable. This adds an explicit exclusion string check to aggressively filter out known API version prefixes (e.g. v1, v2, v1beta1, v1p1beta1). Fixes #4336
1 parent 839ce70 commit 5bfb1b8

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

internal/sidekick/api/resource_name_heuristic.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ func BuildHeuristicVocabulary(model *API) map[string]bool {
108108
if seg.Variable != nil {
109109
if i > 0 && tmpl.Segments[i-1].Literal != nil {
110110
token := *tmpl.Segments[i-1].Literal
111+
// Do not add API version strings (e.g., v1, v1beta1) to the vocabulary
112+
if len(token) >= 2 && token[0] == 'v' && token[1] >= '0' && token[1] <= '9' {
113+
continue
114+
}
111115
tokens[token] = true
112116
}
113117
break

internal/sidekick/api/resource_name_heuristic_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ func TestBuildHeuristicVocabulary(t *testing.T) {
213213
"folders": true,
214214
"organizations": true,
215215
"billingAccounts": true,
216-
"v1": true,
217216
},
218217
},
219218
{

0 commit comments

Comments
 (0)