Skip to content

Commit 85108b5

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
and
ci.datadog-api-spec
authored
Add support for dashboard listing pagination parameters (#1646)
Co-authored-by: ci.datadog-api-spec <[email protected]>
1 parent 5ee6503 commit 85108b5

File tree

7 files changed

+168
-4
lines changed

7 files changed

+168
-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.5",
7-
"regenerated": "2023-09-05 15:12:58.134946",
8-
"spec_repo_commit": "eb534d74"
7+
"regenerated": "2023-09-06 11:51:23.573590",
8+
"spec_repo_commit": "c59cafad"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.5",
12-
"regenerated": "2023-09-05 15:12:58.147487",
13-
"spec_repo_commit": "eb534d74"
12+
"regenerated": "2023-09-06 11:51:23.586262",
13+
"spec_repo_commit": "c59cafad"
1414
}
1515
}
1616
}

.generator/schemas/v1/openapi.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20836,6 +20836,21 @@ paths:
2083620836
required: false
2083720837
schema:
2083820838
type: boolean
20839+
- description: The maximum number of dashboards returned in the list.
20840+
in: query
20841+
name: count
20842+
required: false
20843+
schema:
20844+
default: 100
20845+
format: int64
20846+
type: integer
20847+
- description: The specific offset to use as the beginning of the returned response.
20848+
in: query
20849+
name: start
20850+
required: false
20851+
schema:
20852+
format: int64
20853+
type: integer
2083920854
responses:
2084020855
'200':
2084120856
content:
@@ -20859,6 +20874,10 @@ paths:
2085920874
summary: Get all dashboards
2086020875
tags:
2086120876
- Dashboards
20877+
x-pagination:
20878+
limitParam: count
20879+
pageOffsetParam: start
20880+
resultsPath: dashboards
2086220881
patch:
2086320882
description: Restore dashboards using the specified IDs. If there are any failures,
2086420883
no dashboards will be restored (partial success is not allowed).
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
Get all dashboards returns "OK" response with pagination
3+
"""
4+
5+
from datadog_api_client import ApiClient, Configuration
6+
from datadog_api_client.v1.api.dashboards_api import DashboardsApi
7+
8+
configuration = Configuration()
9+
with ApiClient(configuration) as api_client:
10+
api_instance = DashboardsApi(api_client)
11+
items = api_instance.list_dashboards_with_pagination(
12+
count=2,
13+
)
14+
for item in items:
15+
print(item)

src/datadog_api_client/v1/api/dashboards_api.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@
33
# Copyright 2019-Present Datadog, Inc.
44
from __future__ import annotations
55

6+
import collections
67
from typing import Any, Dict, Union
78

89
from datadog_api_client.api_client import ApiClient, Endpoint as _Endpoint
910
from datadog_api_client.configuration import Configuration
1011
from datadog_api_client.model_utils import (
12+
set_attribute_from_path,
13+
get_attribute_from_path,
1114
UnsetType,
1215
unset,
1316
)
1417
from datadog_api_client.v1.model.dashboard_bulk_delete_request import DashboardBulkDeleteRequest
1518
from datadog_api_client.v1.model.dashboard_summary import DashboardSummary
19+
from datadog_api_client.v1.model.dashboard_summary_definition import DashboardSummaryDefinition
1620
from datadog_api_client.v1.model.dashboard_restore_request import DashboardRestoreRequest
1721
from datadog_api_client.v1.model.dashboard import Dashboard
1822
from datadog_api_client.v1.model.shared_dashboard import SharedDashboard
@@ -264,6 +268,16 @@ def __init__(self, api_client=None):
264268
"attribute": "filter[deleted]",
265269
"location": "query",
266270
},
271+
"count": {
272+
"openapi_types": (int,),
273+
"attribute": "count",
274+
"location": "query",
275+
},
276+
"start": {
277+
"openapi_types": (int,),
278+
"attribute": "start",
279+
"location": "query",
280+
},
267281
},
268282
headers_map={
269283
"accept": ["application/json"],
@@ -546,6 +560,8 @@ def list_dashboards(
546560
*,
547561
filter_shared: Union[bool, UnsetType] = unset,
548562
filter_deleted: Union[bool, UnsetType] = unset,
563+
count: Union[int, UnsetType] = unset,
564+
start: Union[int, UnsetType] = unset,
549565
) -> DashboardSummary:
550566
"""Get all dashboards.
551567
@@ -560,6 +576,10 @@ def list_dashboards(
560576
:param filter_deleted: When ``true`` , this query returns only deleted custom-created
561577
or cloned dashboards. This parameter is incompatible with ``filter[shared]``.
562578
:type filter_deleted: bool, optional
579+
:param count: The maximum number of dashboards returned in the list.
580+
:type count: int, optional
581+
:param start: The specific offset to use as the beginning of the returned response.
582+
:type start: int, optional
563583
:rtype: DashboardSummary
564584
"""
565585
kwargs: Dict[str, Any] = {}
@@ -569,8 +589,65 @@ def list_dashboards(
569589
if filter_deleted is not unset:
570590
kwargs["filter_deleted"] = filter_deleted
571591

592+
if count is not unset:
593+
kwargs["count"] = count
594+
595+
if start is not unset:
596+
kwargs["start"] = start
597+
572598
return self._list_dashboards_endpoint.call_with_http_info(**kwargs)
573599

600+
def list_dashboards_with_pagination(
601+
self,
602+
*,
603+
filter_shared: Union[bool, UnsetType] = unset,
604+
filter_deleted: Union[bool, UnsetType] = unset,
605+
count: Union[int, UnsetType] = unset,
606+
start: Union[int, UnsetType] = unset,
607+
) -> collections.abc.Iterable[DashboardSummaryDefinition]:
608+
"""Get all dashboards.
609+
610+
Provide a paginated version of :meth:`list_dashboards`, returning all items.
611+
612+
:param filter_shared: When ``true`` , this query only returns shared custom created
613+
or cloned dashboards.
614+
:type filter_shared: bool, optional
615+
:param filter_deleted: When ``true`` , this query returns only deleted custom-created
616+
or cloned dashboards. This parameter is incompatible with ``filter[shared]``.
617+
:type filter_deleted: bool, optional
618+
:param count: The maximum number of dashboards returned in the list.
619+
:type count: int, optional
620+
:param start: The specific offset to use as the beginning of the returned response.
621+
:type start: int, optional
622+
623+
:return: A generator of paginated results.
624+
:rtype: collections.abc.Iterable[DashboardSummaryDefinition]
625+
"""
626+
kwargs: Dict[str, Any] = {}
627+
if filter_shared is not unset:
628+
kwargs["filter_shared"] = filter_shared
629+
630+
if filter_deleted is not unset:
631+
kwargs["filter_deleted"] = filter_deleted
632+
633+
if count is not unset:
634+
kwargs["count"] = count
635+
636+
if start is not unset:
637+
kwargs["start"] = start
638+
639+
local_page_size = get_attribute_from_path(kwargs, "count", 100)
640+
endpoint = self._list_dashboards_endpoint
641+
set_attribute_from_path(kwargs, "count", local_page_size, endpoint.params_map)
642+
pagination = {
643+
"limit_value": local_page_size,
644+
"results_path": "dashboards",
645+
"page_offset_param": "start",
646+
"endpoint": endpoint,
647+
"kwargs": kwargs,
648+
}
649+
return endpoint.call_with_http_info_paginated(pagination)
650+
574651
def restore_dashboards(
575652
self,
576653
body: DashboardRestoreRequest,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2023-09-04T12:26:51.389Z
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
interactions:
2+
- request:
3+
body: null
4+
headers:
5+
accept:
6+
- application/json
7+
method: GET
8+
uri: https://api.datadoghq.com/api/v1/dashboard?count=2
9+
response:
10+
body:
11+
string: '{"dashboards":[{"id":"5vp-fxm-s4j","title":"PCF Testing","description":null,"layout_type":"ordered","url":"/dashboard/5vp-fxm-s4j/pcf-testing","is_read_only":false,"created_at":"2022-06-08T10:40:29.941695+00:00","modified_at":"2023-07-27T12:26:28.359080+00:00","author_handle":"[email protected]","deleted_at":null},{"id":"ubf-m9i-gms","title":"OpenStack
12+
Controller Overview","description":"## OpenStack Controller - Overview\n\nPreset
13+
dashboard for the OpenStack Controller integration. Used for OpenStack deployments
14+
v13 and higher. \n\n[See integration docs for more details](https://docs.datadoghq.com/integrations/openstack_controller/)","layout_type":"ordered","url":"/dashboard/ubf-m9i-gms/openstack-controller-overview","is_read_only":false,"created_at":"2023-04-28T19:16:35.964720+00:00","modified_at":"2023-08-07T13:53:31.924789+00:00","author_handle":"[email protected]","deleted_at":null}]}
15+
16+
'
17+
headers:
18+
content-type:
19+
- application/json
20+
status:
21+
code: 200
22+
message: OK
23+
- request:
24+
body: null
25+
headers:
26+
accept:
27+
- application/json
28+
method: GET
29+
uri: https://api.datadoghq.com/api/v1/dashboard?count=2&start=2
30+
response:
31+
body:
32+
string: '{"dashboards":[{"id":"ja7-nhx-7zs","title":"OpenStack Controller Overview
33+
[Default Microversion]","description":"## OpenStack Controller - Overview\n\nPreset
34+
dashboard for the OpenStack Controller integration. Used for OpenStack deployments
35+
v13 and higher. \n\n[See integration docs for more details](https://docs.datadoghq.com/integrations/openstack_controller/)","layout_type":"ordered","url":"/dashboard/ja7-nhx-7zs/openstack-controller-overview-default-microversion","is_read_only":false,"created_at":"2023-08-29T19:56:15.999851+00:00","modified_at":"2023-08-29T20:12:33.385536+00:00","author_handle":"[email protected]","deleted_at":null}]}
36+
37+
'
38+
headers:
39+
content-type:
40+
- application/json
41+
status:
42+
code: 200
43+
message: OK
44+
version: 1

tests/v1/features/dashboards.feature

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,14 @@ Feature: Dashboards
874874
And the response "dashboards[0].title" has the same value as "dashboard.title"
875875
And the response "dashboards[0].id" has the same value as "dashboard.id"
876876

877+
@replay-only @skip-validation @team:DataDog/dashboards-backend @with-pagination
878+
Scenario: Get all dashboards returns "OK" response with pagination
879+
Given new "ListDashboards" request
880+
And request contains "count" parameter with value 2
881+
When the request with pagination is sent
882+
Then the response status is 200 OK
883+
And the response has 3 items
884+
877885
@generated @skip @team:DataDog/dashboards-backend
878886
Scenario: Get all invitations for a shared dashboard returns "Not Found" response
879887
Given new "GetPublicDashboardInvitations" request

0 commit comments

Comments
 (0)