Skip to content

Commit 671a3c2

Browse files
authored
fix(sidekick): ReturnsEmpty on disco methods (#3226)
Sets the `ReturnsEmpty` field on the `api.Method` struct for discovery doc APIs.
1 parent 016bdf9 commit 671a3c2

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

internal/sidekick/parser/discovery/methods.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ func makeMethod(model *api.API, parent *api.Message, doc *document, input *metho
133133
Deprecated: input.Deprecated,
134134
InputTypeID: requestMessage.ID,
135135
OutputTypeID: outputID,
136+
ReturnsEmpty: outputID == ".google.protobuf.Empty",
136137
PathInfo: &api.PathInfo{
137138
Bindings: []*api.PathBinding{binding},
138139
BodyFieldPath: bodyPathField,

internal/sidekick/parser/discovery/methods_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,46 @@ func TestMakeServiceMethods(t *testing.T) {
5959
t.Errorf("mismatch (-want, +got):\n%s", diff)
6060
}
6161
}
62+
func TestMakeServiceMethodsReturnsEmpty(t *testing.T) {
63+
model, err := ComputeDisco(t, nil)
64+
if err != nil {
65+
t.Fatal(err)
66+
}
67+
id := "..zoneOperations.delete"
68+
got, ok := model.State.MethodByID[id]
69+
if !ok {
70+
t.Fatalf("expected method %s in the API model", id)
71+
}
72+
want := &api.Method{
73+
ID: "..zoneOperations.delete",
74+
Name: "delete",
75+
Documentation: "Deletes the specified zone-specific Operations resource.",
76+
InputTypeID: "..zoneOperations.deleteRequest",
77+
OutputTypeID: ".google.protobuf.Empty",
78+
ReturnsEmpty: true,
79+
PathInfo: &api.PathInfo{
80+
Bindings: []*api.PathBinding{
81+
{
82+
Verb: "DELETE",
83+
PathTemplate: api.NewPathTemplate().
84+
WithLiteral("compute").
85+
WithLiteral("v1").
86+
WithLiteral("projects").
87+
WithVariableNamed("project").
88+
WithLiteral("zones").
89+
WithVariableNamed("zone").
90+
WithLiteral("operations").
91+
WithVariableNamed("operation"),
92+
QueryParameters: map[string]bool{},
93+
},
94+
},
95+
BodyFieldPath: "",
96+
},
97+
}
98+
if diff := cmp.Diff(want, got); diff != "" {
99+
t.Errorf("mismatch (-want, +got):\n%s", diff)
100+
}
101+
}
62102

63103
func TestMakeServiceMethodsDeprecated(t *testing.T) {
64104
model, err := ComputeDisco(t, nil)

0 commit comments

Comments
 (0)