Skip to content

Commit ec1bd56

Browse files
authored
fix: parse showcase resource patterns (#3271)
Related to #3258 Parsing showcase protos does not work. This is blocking sidekick updates for `google-coud-rust`. Add a temporary workaround.
1 parent 42ca825 commit ec1bd56

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

internal/sidekick/parser/httprule/http_rule_parser.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ func ParseSegments(pathTemplate string) (*api.PathTemplate, error) {
9393
func ParseResourcePattern(pathTemplate string) (*api.PathTemplate, error) {
9494
// TODO(https://github.com/googleapis/librarian/issues/3258): ParseResourcePattern
9595
// should support parsing generic resources more robustly than just checking for a literal `*`.
96+
if strings.Contains(pathTemplate, "}.{") ||
97+
strings.Contains(pathTemplate, "}~{") {
98+
// TODO(https://github.com/googleapis/librarian/issues/3258): support non-standard separators in resource names... somehow.
99+
return api.NewPathTemplate(), nil
100+
}
96101
if pathTemplate == api.SingleSegmentWildcard {
97102
return api.NewPathTemplate(), nil
98103
}

internal/sidekick/parser/httprule/http_rule_parser_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,31 @@ func TestParseResourcePattern(t *testing.T) {
190190
})
191191
}
192192
}
193+
194+
func TestParseResourcePatternWithNonStandardSeparators(t *testing.T) {
195+
// TODO(https://github.com/googleapis/librarian/issues/3258): at this
196+
// moment, we don't care what the exact representation is for this
197+
// input. We just care that parsing does not error.
198+
testCases := []struct {
199+
name string
200+
pattern string
201+
}{
202+
{
203+
name: "tilde separator",
204+
pattern: "users/{user}/profile/blurbs/legacy/{legacy_user}~{blurb}",
205+
},
206+
{
207+
name: "dot separator",
208+
pattern: "rooms/{room}/blurbs/legacy/{legacy_room}.{blurb}",
209+
},
210+
}
211+
212+
for _, tc := range testCases {
213+
t.Run(tc.name, func(t *testing.T) {
214+
_, err := ParseResourcePattern(tc.pattern)
215+
if err != nil {
216+
t.Fatalf("ParseResourcePattern(%q) failed; want no error, got %v", tc.pattern, err)
217+
}
218+
})
219+
}
220+
}

0 commit comments

Comments
 (0)