Skip to content

Commit 1d4b2d1

Browse files
authored
feat(sidekick/parser): correct LRO poller service (#6704)
For discovery-based APIs the LRO pollers are mixins: the poller method is injected into the service with LROs. The parser was trying to set the source service, but it did not work because the `SourceService` pointer is not initialized when the parser runs. We need to initialize the `SourceServiceID`.
1 parent 9a45ab1 commit 1d4b2d1

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

internal/sidekick/parser/discovery/lro.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ func lroAnnotations(model *api.API, discoveryConfig *api.Discovery) error {
5050
if svcMixin == nil {
5151
continue
5252
}
53+
sourceID := ""
54+
if l := strings.LastIndex(svcMixin.ID, "."); l != -1 {
55+
sourceID = svcMixin.ID[0:l]
56+
}
5357
method := &api.Method{
5458
Name: "getOperation",
5559
ID: fmt.Sprintf("%s.getOperation", svc.ID),
@@ -62,8 +66,7 @@ func lroAnnotations(model *api.API, discoveryConfig *api.Discovery) error {
6266
Routing: svcMixin.Routing,
6367
AutoPopulated: svcMixin.AutoPopulated,
6468
Service: svc,
65-
SourceService: svcMixin.Service,
66-
SourceServiceID: svcMixin.SourceServiceID,
69+
SourceServiceID: sourceID,
6770
IsLroPoller: true,
6871
}
6972
svc.Methods = append(svc.Methods, method)

internal/sidekick/parser/discovery/lro_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,12 @@ func TestLroAnnotations(t *testing.T) {
7676

7777
// The parser should have injected a mixin method.
7878
wantMixin := &api.Method{
79-
ID: "..instances.getOperation",
80-
Name: "getOperation",
81-
InputTypeID: "..zoneOperations.getRequest",
82-
OutputTypeID: "..Operation",
83-
IsLroPoller: true,
79+
ID: "..instances.getOperation",
80+
Name: "getOperation",
81+
InputTypeID: "..zoneOperations.getRequest",
82+
OutputTypeID: "..Operation",
83+
SourceServiceID: "..zoneOperations",
84+
IsLroPoller: true,
8485
PathInfo: &api.PathInfo{
8586
Bindings: []*api.PathBinding{
8687
{

0 commit comments

Comments
 (0)