Skip to content

Commit 2835eda

Browse files
authored
fix(sidekick): URI templates need matchers too (#2261)
1 parent fa1c18f commit 2835eda

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

internal/sidekick/internal/parser/discovery/uritemplate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func parseExpression(input string) (*api.PathSegment, int, error) {
9191
if tail == "" || tail[0] != endExpression {
9292
return nil, 0, fmt.Errorf("missing `}` character at the end of the expression %q", input)
9393
}
94-
return &api.PathSegment{Variable: api.NewPathVariable(id)}, match[1] + 2, nil
94+
return &api.PathSegment{Variable: api.NewPathVariable(id).WithMatch()}, match[1] + 2, nil
9595
}
9696

9797
// parseLiteral() extracts a literal value from `input`.

internal/sidekick/internal/parser/discovery/uritemplate_test.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,22 @@ func TestParseUriTemplateSuccess(t *testing.T) {
2727
input string
2828
want *api.PathTemplate
2929
}{
30-
{"locations/global/firewallPolicies", api.NewPathTemplate().WithLiteral("locations").WithLiteral("global").WithLiteral("firewallPolicies")},
31-
{"locations/global/operations/{operation}", api.NewPathTemplate().WithLiteral("locations").WithLiteral("global").WithLiteral("operations").WithVariable(api.NewPathVariable("operation"))},
32-
{"projects/{project}/zones/{zone}/{parentName}/reservationSubBlocks", api.NewPathTemplate().WithLiteral("projects").WithVariable(api.NewPathVariable("project")).WithLiteral("zones").WithVariable(api.NewPathVariable("zone")).WithVariable(api.NewPathVariable("parentName")).WithLiteral("reservationSubBlocks")},
30+
{"locations/global/firewallPolicies", api.NewPathTemplate().
31+
WithLiteral("locations").
32+
WithLiteral("global").
33+
WithLiteral("firewallPolicies")},
34+
{"locations/global/operations/{operation}", api.NewPathTemplate().
35+
WithLiteral("locations").
36+
WithLiteral("global").
37+
WithLiteral("operations").
38+
WithVariableNamed("operation")},
39+
{"projects/{project}/zones/{zone}/{parentName}/reservationSubBlocks", api.NewPathTemplate().
40+
WithLiteral("projects").
41+
WithVariableNamed("project").
42+
WithLiteral("zones").
43+
WithVariableNamed("zone").
44+
WithVariableNamed("parentName").
45+
WithLiteral("reservationSubBlocks")},
3346
} {
3447
got, err := ParseUriTemplate(test.input)
3548
if err != nil {
@@ -77,7 +90,7 @@ func TestParseExpression(t *testing.T) {
7790
t.Errorf("expected a successful parse with input=%s, err=%v", test.input, err)
7891
continue
7992
}
80-
if diff := cmp.Diff(&api.PathSegment{Variable: api.NewPathVariable(test.want)}, gotSegment); diff != "" {
93+
if diff := cmp.Diff(&api.PathSegment{Variable: api.NewPathVariable(test.want).WithMatch()}, gotSegment); diff != "" {
8194
t.Errorf("mismatch [%s] (-want, +got):\n%s", test.input, diff)
8295
}
8396
if len(test.want)+2 != gotWidth {

0 commit comments

Comments
 (0)