Skip to content

Commit 4b9e584

Browse files
Add pageStart extension to case management pagination (DataDog#3157)
1 parent fc99b4f commit 4b9e584

7 files changed

Lines changed: 59 additions & 6 deletions

File tree

.generator/schemas/v2/openapi.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75976,6 +75976,7 @@ paths:
7597675976
x-pagination:
7597775977
limitParam: page[size]
7597875978
pageParam: page[number]
75979+
pageStart: 1
7597975980
resultsPath: data
7598075981
post:
7598175982
description: Create a Case

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ module {{ module_name }}::{{ version|upper }}
233233
page_size = @api_client.get_attribute_from_path({{ get_container(operation, pagination.limitParam) }}, {{ get_default(operation, pagination.limitParam) }})
234234
@api_client.set_attribute_from_path(api_version, {{ get_container(operation, pagination.limitParam, True) }}, page_size)
235235
{%- if pagination.pageParam %}
236-
@api_client.set_attribute_from_path(api_version, {{ get_container(operation, pagination.pageParam, True) }}, 0)
236+
@api_client.set_attribute_from_path(api_version, {{ get_container(operation, pagination.pageParam, True) }}, {{ pagination.pageStart | default(0) }})
237237
{%- endif %}
238238
while true do
239239
response = {{ operation.operationId|snake_case }}({% for name, parameter in operation|parameters if parameter.required %}{{ name|attribute_name }}, {% endfor %}opts)
@@ -254,7 +254,7 @@ module {{ module_name }}::{{ version|upper }}
254254
@api_client.set_attribute_from_path(api_version, {{ get_container(operation, pagination.cursorParam, True) }}, @api_client.get_attribute_from_path(response, "{{ pagination.cursorPath }}"))
255255
{%- endif %}
256256
{%- if pagination.pageParam %}
257-
@api_client.set_attribute_from_path(api_version, {{ get_container(operation, pagination.pageParam, True) }}, @api_client.get_attribute_from_path({{ get_container(operation, pagination.pageParam) }}, 0) + 1)
257+
@api_client.set_attribute_from_path(api_version, {{ get_container(operation, pagination.pageParam, True) }}, @api_client.get_attribute_from_path({{ get_container(operation, pagination.pageParam) }}, {{ pagination.pageStart | default(0) }}) + 1)
258258
{%- endif %}
259259
end
260260
end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2026-03-25T10:29:24.893Z

cassettes/features/v2/case_management/Search-cases-returns-OK-response-with-pagination.yml

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/v2/case-management/SearchCases_3433960044.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22

33
require "datadog_api_client"
44
api_instance = DatadogAPIClient::V2::CaseManagementAPI.new
5-
api_instance.search_cases_with_pagination() { |item| puts item }
5+
opts = {
6+
page_size: 2,
7+
filter: "status:closed",
8+
}
9+
api_instance.search_cases_with_pagination(opts) { |item| puts item }

features/v2/case_management.feature

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,11 +508,14 @@ Feature: Case Management
508508
When the request is sent
509509
Then the response status is 200 OK
510510

511-
@generated @skip @team:DataDog/case-management @with-pagination
511+
@replay-only @skip-validation @team:DataDog/case-management @with-pagination
512512
Scenario: Search cases returns "OK" response with pagination
513513
Given new "SearchCases" request
514+
And request contains "page[size]" parameter with value 2
515+
And request contains "filter" parameter with value "status:closed"
514516
When the request with pagination is sent
515517
Then the response status is 200 OK
518+
And the response has 3 items
516519

517520
@team:DataDog/case-management
518521
Scenario: Unarchive case returns "Bad Request" response

lib/datadog_api_client/v2/api/case_management_api.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,14 +1528,14 @@ def search_cases_with_pagination(opts = {})
15281528
api_version = "V2"
15291529
page_size = @api_client.get_attribute_from_path(opts, "page_size", 10)
15301530
@api_client.set_attribute_from_path(api_version, opts, "page_size", Integer, page_size)
1531-
@api_client.set_attribute_from_path(api_version, opts, "page_number", Integer, 0)
1531+
@api_client.set_attribute_from_path(api_version, opts, "page_number", Integer, 1)
15321532
while true do
15331533
response = search_cases(opts)
15341534
@api_client.get_attribute_from_path(response, "data").each { |item| yield(item) }
15351535
if @api_client.get_attribute_from_path(response, "data").length < page_size
15361536
break
15371537
end
1538-
@api_client.set_attribute_from_path(api_version, opts, "page_number", Integer, @api_client.get_attribute_from_path(opts, "page_number", 0) + 1)
1538+
@api_client.set_attribute_from_path(api_version, opts, "page_number", Integer, @api_client.get_attribute_from_path(opts, "page_number", 1) + 1)
15391539
end
15401540
end
15411541

0 commit comments

Comments
 (0)