Skip to content

Commit 14a1483

Browse files
authored
feat(sidekick): capture discovery revision (#2605)
Discovery docs include a revision, this is useful to include in the documentation, and may help with IBV.
1 parent 3cc63b2 commit 14a1483

File tree

5 files changed

+37
-24
lines changed

5 files changed

+37
-24
lines changed

internal/sidekick/internal/api/model.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,11 @@ type API struct {
138138
PackageName string
139139
// The API Title (e.g. "Secret Manager API" or "Cloud Spanner API").
140140
Title string
141-
// The API Description
141+
// The API Description.
142142
Description string
143+
// The API Revision. In discovery-based services this is the "revision"
144+
// attribute.
145+
Revision string
143146
// Services are a collection of services that make up the API.
144147
Services []*Service
145148
// Messages are a collection of messages used to process request and

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func NewAPI(serviceConfig *serviceconfig.Service, contents []byte, cfg *config.C
3838
Name: doc.Name,
3939
Title: doc.Title,
4040
Description: doc.Description,
41+
Revision: doc.Revision,
4142
Messages: make([]*api.Message, 0),
4243
State: &api.APIState{
4344
ServiceByID: make(map[string]*api.Service),
@@ -111,6 +112,7 @@ type document struct {
111112
Version string `json:"version"`
112113
Title string `json:"title"`
113114
Description string `json:"description"`
115+
Revision string `json:"revision"`
114116
RootURL string `json:"rootUrl"`
115117
MTLSRootURL string `json:"mtlsRootUrl"`
116118
ServicePath string `json:"servicePath"`

internal/sidekick/internal/parser/discovery/discovery_test.go

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,14 @@ func TestInfo(t *testing.T) {
4949
if err != nil {
5050
t.Fatal(err)
5151
}
52-
wantName := "compute"
53-
wantTitle := "Compute Engine API"
54-
wantDescription := "Creates and runs virtual machines on Google Cloud Platform. "
55-
if got.Name != wantName {
56-
t.Errorf("want = %q; got = %q", wantName, got.Name)
52+
want := &api.API{
53+
Name: "compute",
54+
Title: "Compute Engine API",
55+
Description: "Creates and runs virtual machines on Google Cloud Platform. ",
56+
Revision: "20250810",
5757
}
58-
if got.Title != wantTitle {
59-
t.Errorf("want = %q; got = %q", wantTitle, got.Title)
60-
}
61-
if diff := cmp.Diff(wantDescription, got.Description); diff != "" {
62-
t.Errorf("mismatch (-want +got):\n%s", diff)
63-
}
64-
if got.PackageName != "" {
65-
t.Errorf("expected empty package name")
58+
if diff := cmp.Diff(want, got, cmpopts.IgnoreFields(api.API{}, "State", "Services", "Messages", "Enums")); diff != "" {
59+
t.Errorf("mismatch (-want, +got):\n%s", diff)
6660
}
6761
}
6862

@@ -76,21 +70,19 @@ func TestServiceConfigOverridesInfo(t *testing.T) {
7670
if err != nil {
7771
t.Fatal(err)
7872
}
79-
if got.Name != sc.Name {
80-
t.Errorf("want = %q; got = %q", sc.Title, got.Title)
73+
want := &api.API{
74+
Name: sc.Name,
75+
Title: sc.Title,
76+
Description: sc.Documentation.Summary,
77+
Revision: "20250810",
78+
PackageName: "google.cloud.secretmanager.v1",
8179
}
82-
if got.Title != sc.Title {
83-
t.Errorf("want = %q; got = %q", sc.Title, got.Title)
84-
}
85-
if diff := cmp.Diff(sc.Documentation.Summary, got.Description); diff != "" {
86-
t.Errorf("mismatch (-want +got):\n%s", diff)
80+
if diff := cmp.Diff(want, got, cmpopts.IgnoreFields(api.API{}, "State", "Services", "Messages", "Enums")); diff != "" {
81+
t.Errorf("mismatch (-want, +got):\n%s", diff)
8782
}
8883
if len(sc.Apis) != 2 {
8984
t.Fatalf("expected 2 APIs in service config")
9085
}
91-
if got.PackageName == "" {
92-
t.Errorf("got empty package name")
93-
}
9486
if !strings.HasPrefix(sc.Apis[1].Name, got.PackageName) {
9587
t.Errorf("mismatched package name want = %q, got = %q", sc.Apis[1].Name, got.PackageName)
9688
}

internal/sidekick/internal/rust/templates/common/README.md.mustache

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ GitHub repository.
3939

4040
{{{.}}}
4141
{{/Description}}
42+
{{!
43+
Discovery-doc based APIs include a revision.
44+
Publishing the information is useful for troubleshooting.
45+
}}
46+
{{#Revision}}
47+
48+
This client library was generated from the "{{Revision}}" revision of the API.
49+
{{/Revision}}
4250
{{#Codec.ReleaseLevelIsGA}}
4351

4452
The client library types and functions are stable and not expected to change.

internal/sidekick/internal/rust/templates/crate/src/lib.rs.mustache

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ limitations under the License.
1919
{{/Codec.BoilerPlate}}
2020

2121
//! Google Cloud Client Libraries for Rust - {{{Title}}}
22+
{{!
23+
Discovery-doc based APIs include a revision.
24+
Publishing the information is useful for troubleshooting.
25+
}}
26+
{{#Revision}}
27+
//!
28+
//! This client library was generated from the "{{Revision}}" revision of the API.
29+
{{/Revision}}
2230
//! {{^Codec.ReleaseLevelIsGA}}
2331
//!
2432
//! **FEEDBACK WANTED:** We believe the APIs in this crate are stable, and

0 commit comments

Comments
 (0)