Skip to content

Commit ba5e453

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add page[size] and page[number] parameters to Downtime docs (#1817)
Co-authored-by: ci.datadog-api-spec <[email protected]> Co-authored-by: api-clients-generation-pipeline[bot] <54105614+api-clients-generation-pipeline[bot]@users.noreply.github.com>
1 parent 9a8c635 commit ba5e453

File tree

5 files changed

+106
-4
lines changed

5 files changed

+106
-4
lines changed

.apigentools-info

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"spec_versions": {
55
"v1": {
66
"apigentools_version": "1.6.6",
7-
"regenerated": "2024-01-02 15:20:21.730883",
8-
"spec_repo_commit": "415bb394"
7+
"regenerated": "2024-01-02 15:59:33.181176",
8+
"spec_repo_commit": "d5ac2418"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.6",
12-
"regenerated": "2024-01-02 15:20:21.744971",
13-
"spec_repo_commit": "415bb394"
12+
"regenerated": "2024-01-02 15:59:33.201071",
13+
"spec_repo_commit": "d5ac2418"
1414
}
1515
}
1616
}

.generator/schemas/v2/openapi.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26896,6 +26896,16 @@ paths:
2689626896
schema:
2689726897
format: int64
2689826898
type: integer
26899+
- $ref: '#/components/parameters/PageOffset'
26900+
- description: Maximum number of downtimes in the response.
26901+
example: 100
26902+
in: query
26903+
name: page[limit]
26904+
required: false
26905+
schema:
26906+
default: 30
26907+
format: int64
26908+
type: integer
2689926909
responses:
2690026910
'200':
2690126911
content:
@@ -26920,6 +26930,10 @@ paths:
2692026930
tags:
2692126931
- Downtimes
2692226932
x-codegen-request-body-name: body
26933+
x-pagination:
26934+
limitParam: page[limit]
26935+
pageOffsetParam: page[offset]
26936+
resultsPath: data
2692326937
/api/v2/permissions:
2692426938
get:
2692526939
description: Returns a list of all permissions, including name, description,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
Get active downtimes for a monitor returns "OK" response with pagination
3+
"""
4+
5+
from datadog_api_client import ApiClient, Configuration
6+
from datadog_api_client.v2.api.downtimes_api import DowntimesApi
7+
8+
configuration = Configuration()
9+
with ApiClient(configuration) as api_client:
10+
api_instance = DowntimesApi(api_client)
11+
items = api_instance.list_monitor_downtimes_with_pagination(
12+
monitor_id=9223372036854775807,
13+
)
14+
for item in items:
15+
print(item)

src/datadog_api_client/v2/api/downtimes_api.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from datadog_api_client.v2.model.downtime_create_request import DowntimeCreateRequest
2121
from datadog_api_client.v2.model.downtime_update_request import DowntimeUpdateRequest
2222
from datadog_api_client.v2.model.monitor_downtime_match_response import MonitorDowntimeMatchResponse
23+
from datadog_api_client.v2.model.monitor_downtime_match_response_data import MonitorDowntimeMatchResponseData
2324

2425

2526
class DowntimesApi:
@@ -161,6 +162,16 @@ def __init__(self, api_client=None):
161162
"attribute": "monitor_id",
162163
"location": "path",
163164
},
165+
"page_offset": {
166+
"openapi_types": (int,),
167+
"attribute": "page[offset]",
168+
"location": "query",
169+
},
170+
"page_limit": {
171+
"openapi_types": (int,),
172+
"attribute": "page[limit]",
173+
"location": "query",
174+
},
164175
},
165176
headers_map={
166177
"accept": ["application/json"],
@@ -344,20 +355,75 @@ def list_downtimes_with_pagination(
344355
def list_monitor_downtimes(
345356
self,
346357
monitor_id: int,
358+
*,
359+
page_offset: Union[int, UnsetType] = unset,
360+
page_limit: Union[int, UnsetType] = unset,
347361
) -> MonitorDowntimeMatchResponse:
348362
"""Get active downtimes for a monitor.
349363
350364
Get all active downtimes for the specified monitor.
351365
352366
:param monitor_id: The id of the monitor.
353367
:type monitor_id: int
368+
:param page_offset: Specific offset to use as the beginning of the returned page.
369+
:type page_offset: int, optional
370+
:param page_limit: Maximum number of downtimes in the response.
371+
:type page_limit: int, optional
354372
:rtype: MonitorDowntimeMatchResponse
355373
"""
356374
kwargs: Dict[str, Any] = {}
357375
kwargs["monitor_id"] = monitor_id
358376

377+
if page_offset is not unset:
378+
kwargs["page_offset"] = page_offset
379+
380+
if page_limit is not unset:
381+
kwargs["page_limit"] = page_limit
382+
359383
return self._list_monitor_downtimes_endpoint.call_with_http_info(**kwargs)
360384

385+
def list_monitor_downtimes_with_pagination(
386+
self,
387+
monitor_id: int,
388+
*,
389+
page_offset: Union[int, UnsetType] = unset,
390+
page_limit: Union[int, UnsetType] = unset,
391+
) -> collections.abc.Iterable[MonitorDowntimeMatchResponseData]:
392+
"""Get active downtimes for a monitor.
393+
394+
Provide a paginated version of :meth:`list_monitor_downtimes`, returning all items.
395+
396+
:param monitor_id: The id of the monitor.
397+
:type monitor_id: int
398+
:param page_offset: Specific offset to use as the beginning of the returned page.
399+
:type page_offset: int, optional
400+
:param page_limit: Maximum number of downtimes in the response.
401+
:type page_limit: int, optional
402+
403+
:return: A generator of paginated results.
404+
:rtype: collections.abc.Iterable[MonitorDowntimeMatchResponseData]
405+
"""
406+
kwargs: Dict[str, Any] = {}
407+
kwargs["monitor_id"] = monitor_id
408+
409+
if page_offset is not unset:
410+
kwargs["page_offset"] = page_offset
411+
412+
if page_limit is not unset:
413+
kwargs["page_limit"] = page_limit
414+
415+
local_page_size = get_attribute_from_path(kwargs, "page_limit", 30)
416+
endpoint = self._list_monitor_downtimes_endpoint
417+
set_attribute_from_path(kwargs, "page_limit", local_page_size, endpoint.params_map)
418+
pagination = {
419+
"limit_value": local_page_size,
420+
"results_path": "data",
421+
"page_offset_param": "page_offset",
422+
"endpoint": endpoint,
423+
"kwargs": kwargs,
424+
}
425+
return endpoint.call_with_http_info_paginated(pagination)
426+
361427
def update_downtime(
362428
self,
363429
downtime_id: str,

tests/v2/features/downtimes.feature

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ Feature: Downtimes
6767
And the response "data" has length 1
6868
And the response "data" has item with field "id" with value "aeefc6a8-15d8-11ee-a8ef-da7ad0900002"
6969

70+
@generated @skip @team:DataDog/monitor-app @with-pagination
71+
Scenario: Get active downtimes for a monitor returns "OK" response with pagination
72+
Given new "ListMonitorDowntimes" request
73+
And request contains "monitor_id" parameter from "REPLACE.ME"
74+
When the request with pagination is sent
75+
Then the response status is 200 OK
76+
7077
@team:DataDog/monitor-app
7178
Scenario: Get all downtimes for a monitor returns "Monitor Not Found error" response
7279
Given new "ListMonitorDowntimes" request

0 commit comments

Comments
 (0)