Skip to content

Commit cb21cf1

Browse files
authored
feat(sidekick): discovery-based APIs and pagination (#2350)
1 parent 563e9f3 commit cb21cf1

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

internal/sidekick/internal/parser/disco.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,11 @@ func ParseDisco(source, serviceConfigFile string, options map[string]string) (*a
5151
}
5252
serviceConfig = cfg
5353
}
54-
return discovery.NewAPI(serviceConfig, contents)
54+
result, err := discovery.NewAPI(serviceConfig, contents)
55+
if err != nil {
56+
return nil, err
57+
}
58+
updateMethodPagination(result)
59+
updateAutoPopulatedFields(serviceConfig, result)
60+
return result, nil
5561
}

internal/sidekick/internal/parser/disco_test.go

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818
"testing"
1919

2020
"github.com/google/go-cmp/cmp"
21+
"github.com/google/go-cmp/cmp/cmpopts"
22+
"github.com/googleapis/librarian/internal/sidekick/internal/api"
2123
)
2224

2325
func TestDisco_Parse(t *testing.T) {
@@ -86,12 +88,39 @@ func TestDisco_ParseNoServiceConfig(t *testing.T) {
8688
}
8789
}
8890

91+
func TestDisco_ParsePagination(t *testing.T) {
92+
model, err := ParseDisco(discoSourceFile, "", map[string]string{})
93+
if err != nil {
94+
t.Fatal(err)
95+
}
96+
wantID := "..zones.list"
97+
got, ok := model.State.MethodByID[wantID]
98+
if !ok {
99+
t.Fatalf("expected method %s in the API model", wantID)
100+
}
101+
wantPagination := &api.Field{
102+
Name: "pageToken",
103+
JSONName: "pageToken",
104+
Typez: api.STRING_TYPE,
105+
TypezID: "string",
106+
Optional: true,
107+
Synthetic: true,
108+
}
109+
if diff := cmp.Diff(wantPagination, got.Pagination, cmpopts.IgnoreFields(api.Field{}, "Documentation")); diff != "" {
110+
t.Errorf("mismatch (-want, +got):\n%s", diff)
111+
}
112+
}
113+
89114
func TestDisco_ParseBadFiles(t *testing.T) {
90115
if _, err := ParseDisco("-invalid-file-name-", secretManagerYamlFullPath, map[string]string{}); err == nil {
91-
t.Fatalf("expected error with invalid source file name")
116+
t.Fatalf("expected error with missing source file")
92117
}
93118

94119
if _, err := ParseDisco(discoSourceFile, "-invalid-file-name-", map[string]string{}); err == nil {
95-
t.Fatalf("expected error with invalid service config yaml file name")
120+
t.Fatalf("expected error with missing service config yaml file")
121+
}
122+
123+
if _, err := ParseDisco(secretManagerYamlFullPath, secretManagerYamlFullPath, map[string]string{}); err == nil {
124+
t.Fatalf("expected error with invalid source file contents")
96125
}
97126
}

0 commit comments

Comments
 (0)