Skip to content

Commit 68f137d

Browse files
authored
fix(sidekick): missing Debug for discovery requests (#2319)
We want to generate the `Debug` implementation for children of the discovery request.
1 parent dd8fbfb commit 68f137d

File tree

7 files changed

+30
-29
lines changed

7 files changed

+30
-29
lines changed

internal/sidekick/internal/api/model.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -569,18 +569,19 @@ type Message struct {
569569
// OpenAPI specifications. The query and request parameters for each method
570570
// are grouped into a synthetic message.
571571
SyntheticRequest bool
572-
// If true, this message is only intended as a namespace to group child
573-
// messages.
572+
// If true, this message is a placeholder / doppelganger for a `api.Service`.
574573
//
575574
// These messages are created by sidekick when parsing Discovery docs and
576575
// OpenAPI specifications. All the synthetic messages for a service need to
577576
// be grouped under a unique namespace to avoid clashes with similar
578-
// synthetic messages in other service.
577+
// synthetic messages in other service. Sidekick creates a placeholder
578+
// message that represents "the service".
579579
//
580580
// That is, `service1` and `service2` may both have a synthetic `getRequest`
581581
// message, with different attributes. We need these to be different
582-
// messages, with different names.
583-
ChildrenOnly bool
582+
// messages, with different names. So we create a different parent message
583+
// for each.
584+
ServicePlaceholder bool
584585
// Enums associated with the Message.
585586
Enums []*Enum
586587
// Messages associated with the Message. In protobuf these are referred to as

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ func makeServiceMethods(model *api.API, service *api.Service, doc *document, res
2525
// It is Okay to reuse the ID, sidekick uses different the namespaces
2626
// for messages vs. services.
2727
parent := &api.Message{
28-
Name: service.Name,
29-
ID: service.ID,
30-
Package: service.Package,
31-
Documentation: fmt.Sprintf("Synthetic messages for the [%s][%s] service", service.Name, service.ID[1:]),
32-
ChildrenOnly: true,
28+
Name: service.Name,
29+
ID: service.ID,
30+
Package: service.Package,
31+
Documentation: fmt.Sprintf("Synthetic messages for the [%s][%s] service", service.Name, service.ID[1:]),
32+
ServicePlaceholder: true,
3333
}
3434
model.State.MessageByID[parent.ID] = parent
3535
model.Messages = append(model.Messages, parent)

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,12 @@ func TestServiceMessages(t *testing.T) {
111111
}
112112

113113
want := &api.Message{
114-
Name: "zones",
115-
ID: "..zones",
116-
Package: "",
117-
Documentation: "Synthetic messages for the [zones][.zones] service",
118-
ChildrenOnly: true,
119-
Messages: []*api.Message{getMessage, listMessage},
114+
Name: "zones",
115+
ID: "..zones",
116+
Package: "",
117+
Documentation: "Synthetic messages for the [zones][.zones] service",
118+
ServicePlaceholder: true,
119+
Messages: []*api.Message{getMessage, listMessage},
120120
}
121121

122122
got, ok := model.State.MessageByID[want.ID]

internal/sidekick/internal/rust/templates/common/message.mustache

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
}}
1616
{{^IsMap}}
17-
{{^ChildrenOnly}}
17+
{{^ServicePlaceholder}}
1818

1919
{{#Codec.DocLines}}
2020
{{{.}}}
@@ -250,17 +250,17 @@ impl gax::paginator::internal::PageableResponse for {{Codec.Name}} {
250250
{{/NextPageToken}}
251251
}
252252
{{/Pagination}}
253-
{{/ChildrenOnly}}
253+
{{/ServicePlaceholder}}
254254
{{#Codec.HasNestedTypes}}
255255
256-
{{#ChildrenOnly}}
256+
{{#ServicePlaceholder}}
257257
{{#Codec.DocLines}}
258258
{{{.}}}
259259
{{/Codec.DocLines}}
260-
{{/ChildrenOnly}}
261-
{{^ChildrenOnly}}
260+
{{/ServicePlaceholder}}
261+
{{^ServicePlaceholder}}
262262
/// Defines additional types related to [{{Codec.Name}}].
263-
{{/ChildrenOnly}}
263+
{{/ServicePlaceholder}}
264264
{{> /templates/common/feature_gate}}
265265
pub mod {{Codec.ModuleName}} {
266266
{{! Very rarely, this is unused. It is easier to always disable the warning. }}

internal/sidekick/internal/rust/templates/common/model/debug/message.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ limitations under the License.
1515
}}
1616

1717
{{^IsMap}}
18-
{{^ChildrenOnly}}
18+
{{^ServicePlaceholder}}
1919
{{> /templates/common/feature_gate}}
2020
impl std::fmt::Debug for super::{{Codec.RelativeName}} {
2121
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
@@ -32,10 +32,10 @@ impl std::fmt::Debug for super::{{Codec.RelativeName}} {
3232
debug_struct.finish()
3333
}
3434
}
35+
{{/ServicePlaceholder}}
36+
{{/IsMap}}
3537
{{#Codec.HasNestedTypes}}
3638
{{#Messages}}
3739
{{> /templates/common/model/debug/message}}
3840
{{/Messages}}
3941
{{/Codec.HasNestedTypes}}
40-
{{/ChildrenOnly}}
41-
{{/IsMap}}

internal/sidekick/internal/rust/templates/common/model/deserialize/message.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ limitations under the License.
1515
}}
1616

1717
{{^IsMap}}
18-
{{^ChildrenOnly}}
18+
{{^ServicePlaceholder}}
1919
{{> /templates/common/feature_gate}}
2020
#[doc(hidden)]
2121
impl<'de> serde::de::Deserialize<'de> for super::{{Codec.RelativeName}} {
@@ -75,5 +75,5 @@ impl<'de> serde::de::Deserialize<'de> for super::{{Codec.RelativeName}} {
7575
{{> /templates/common/model/deserialize/message}}
7676
{{/Messages}}
7777
{{/Codec.HasNestedTypes}}
78-
{{/ChildrenOnly}}
78+
{{/ServicePlaceholder}}
7979
{{/IsMap}}

internal/sidekick/internal/rust/templates/common/model/serialize/message.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ limitations under the License.
1515
}}
1616

1717
{{^IsMap}}
18-
{{^ChildrenOnly}}
18+
{{^ServicePlaceholder}}
1919
{{> /templates/common/feature_gate}}
2020
#[doc(hidden)]
2121
impl serde::ser::Serialize for super::{{Codec.RelativeName}} {
@@ -50,5 +50,5 @@ impl serde::ser::Serialize for super::{{Codec.RelativeName}} {
5050
{{> /templates/common/model/serialize/message}}
5151
{{/Messages}}
5252
{{/Codec.HasNestedTypes}}
53-
{{/ChildrenOnly}}
53+
{{/ServicePlaceholder}}
5454
{{/IsMap}}

0 commit comments

Comments
 (0)