Skip to content

Commit 44153c7

Browse files
api-clients-generation-pipeline[bot]murarustefaanci.datadog-api-spec
authored
Allow cursor base pagination to query extra page until collection is empty in Ruby and Golang (#3769)
* fix: Update client generation template * Regenerate client from commit 64b7d7f of spec repo --------- Co-authored-by: Muraru Ștefan <muraru.stefaan@gmail.com> Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
1 parent df25348 commit 44153c7

30 files changed

Lines changed: 320 additions & 24 deletions

File tree

.generator/src/generator/templates/api.j2

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,15 @@ func (a *{{ classname }}) {{ operation.operationId }}WithPagination(ctx _context
423423
return
424424
}
425425
}
426+
{%- if pagination.cursorParam %}
427+
if len(results) == 0 {
428+
break
429+
}
430+
{%- else %}
426431
if len(results) < int(pageSize_) {
427432
break
428433
}
434+
{%- endif %}
429435
{%- if pagination.pageOffsetParam %}
430436
if {{ get_container(operation, pagination.pageOffsetParam) }} == nil {
431437
{{ get_container(operation, pagination.pageOffsetParam) }} = &pageSize_

api/datadogV2/api_audit.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ func (a *AuditApi) ListAuditLogsWithPagination(ctx _context.Context, o ...ListAu
211211
return
212212
}
213213
}
214-
if len(results) < int(pageSize_) {
214+
if len(results) == 0 {
215215
break
216216
}
217217
cursorMeta, ok := resp.GetMetaOk()
@@ -387,7 +387,7 @@ func (a *AuditApi) SearchAuditLogsWithPagination(ctx _context.Context, o ...Sear
387387
return
388388
}
389389
}
390-
if len(results) < int(pageSize_) {
390+
if len(results) == 0 {
391391
break
392392
}
393393
cursorMeta, ok := resp.GetMetaOk()

api/datadogV2/api_ci_visibility_pipelines.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ func (a *CIVisibilityPipelinesApi) ListCIAppPipelineEventsWithPagination(ctx _co
367367
return
368368
}
369369
}
370-
if len(results) < int(pageSize_) {
370+
if len(results) == 0 {
371371
break
372372
}
373373
cursorMeta, ok := resp.GetMetaOk()
@@ -541,7 +541,7 @@ func (a *CIVisibilityPipelinesApi) SearchCIAppPipelineEventsWithPagination(ctx _
541541
return
542542
}
543543
}
544-
if len(results) < int(pageSize_) {
544+
if len(results) == 0 {
545545
break
546546
}
547547
cursorMeta, ok := resp.GetMetaOk()

api/datadogV2/api_ci_visibility_tests.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ func (a *CIVisibilityTestsApi) ListCIAppTestEventsWithPagination(ctx _context.Co
289289
return
290290
}
291291
}
292-
if len(results) < int(pageSize_) {
292+
if len(results) == 0 {
293293
break
294294
}
295295
cursorMeta, ok := resp.GetMetaOk()
@@ -463,7 +463,7 @@ func (a *CIVisibilityTestsApi) SearchCIAppTestEventsWithPagination(ctx _context.
463463
return
464464
}
465465
}
466-
if len(results) < int(pageSize_) {
466+
if len(results) == 0 {
467467
break
468468
}
469469
cursorMeta, ok := resp.GetMetaOk()

api/datadogV2/api_container_images.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func (a *ContainerImagesApi) ListContainerImagesWithPagination(ctx _context.Cont
196196
return
197197
}
198198
}
199-
if len(results) < int(pageSize_) {
199+
if len(results) == 0 {
200200
break
201201
}
202202
cursorMeta, ok := resp.GetMetaOk()

api/datadogV2/api_containers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func (a *ContainersApi) ListContainersWithPagination(ctx _context.Context, o ...
195195
return
196196
}
197197
}
198-
if len(results) < int(pageSize_) {
198+
if len(results) == 0 {
199199
break
200200
}
201201
cursorMeta, ok := resp.GetMetaOk()

api/datadogV2/api_events.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ func (a *EventsApi) ListEventsWithPagination(ctx _context.Context, o ...ListEven
383383
return
384384
}
385385
}
386-
if len(results) < int(pageSize_) {
386+
if len(results) == 0 {
387387
break
388388
}
389389
cursorMeta, ok := resp.GetMetaOk()
@@ -557,7 +557,7 @@ func (a *EventsApi) SearchEventsWithPagination(ctx _context.Context, o ...Search
557557
return
558558
}
559559
}
560-
if len(results) < int(pageSize_) {
560+
if len(results) == 0 {
561561
break
562562
}
563563
cursorMeta, ok := resp.GetMetaOk()

api/datadogV2/api_logs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ func (a *LogsApi) ListLogsWithPagination(ctx _context.Context, o ...ListLogsOpti
254254
return
255255
}
256256
}
257-
if len(results) < int(pageSize_) {
257+
if len(results) == 0 {
258258
break
259259
}
260260
cursorMeta, ok := resp.GetMetaOk()
@@ -497,7 +497,7 @@ func (a *LogsApi) ListLogsGetWithPagination(ctx _context.Context, o ...ListLogsG
497497
return
498498
}
499499
}
500-
if len(results) < int(pageSize_) {
500+
if len(results) == 0 {
501501
break
502502
}
503503
cursorMeta, ok := resp.GetMetaOk()

api/datadogV2/api_metrics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,7 @@ func (a *MetricsApi) ListTagConfigurationsWithPagination(ctx _context.Context, o
10671067
return
10681068
}
10691069
}
1070-
if len(results) < int(pageSize_) {
1070+
if len(results) == 0 {
10711071
break
10721072
}
10731073
cursorMeta, ok := resp.GetMetaOk()

api/datadogV2/api_processes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ func (a *ProcessesApi) ListProcessesWithPagination(ctx _context.Context, o ...Li
205205
return
206206
}
207207
}
208-
if len(results) < int(pageSize_) {
208+
if len(results) == 0 {
209209
break
210210
}
211211
cursorMeta, ok := resp.GetMetaOk()

0 commit comments

Comments
 (0)