Skip to content

Commit b078555

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add pagination support for the GET service_definitions endpoint (#1403)
Co-authored-by: ci.datadog-api-spec <[email protected]>
1 parent b90fa36 commit b078555

File tree

7 files changed

+159
-6
lines changed

7 files changed

+159
-6
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.4",
7-
"regenerated": "2023-04-06 14:03:50.942790",
8-
"spec_repo_commit": "9572acd2"
7+
"regenerated": "2023-04-06 15:04:06.579964",
8+
"spec_repo_commit": "b180cceb"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.4",
12-
"regenerated": "2023-04-06 14:03:50.955323",
13-
"spec_repo_commit": "9572acd2"
12+
"regenerated": "2023-04-06 15:04:06.599309",
13+
"spec_repo_commit": "b180cceb"
1414
}
1515
}
1616
}

.generator/schemas/v2/openapi.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21758,6 +21758,9 @@ paths:
2175821758
description: Get a list of all service definitions from the Datadog Service
2175921759
Catalog.
2176021760
operationId: ListServiceDefinitions
21761+
parameters:
21762+
- $ref: '#/components/parameters/PageSize'
21763+
- $ref: '#/components/parameters/PageNumber'
2176121764
responses:
2176221765
'200':
2176321766
content:
@@ -21772,6 +21775,10 @@ paths:
2177221775
summary: Get all service definitions
2177321776
tags:
2177421777
- Service Definition
21778+
x-pagination:
21779+
limitParam: page[size]
21780+
pageOffsetParam: page[number]
21781+
resultsPath: data
2177521782
post:
2177621783
description: Create or update service definition in the Datadog Service Catalog.
2177721784
operationId: CreateOrUpdateServiceDefinitions
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
Get all service definitions returns "OK" response with pagination
3+
"""
4+
5+
from datadog_api_client import ApiClient, Configuration
6+
from datadog_api_client.v2.api.service_definition_api import ServiceDefinitionApi
7+
8+
configuration = Configuration()
9+
with ApiClient(configuration) as api_client:
10+
api_instance = ServiceDefinitionApi(api_client)
11+
items = api_instance.list_service_definitions_with_pagination(
12+
page_size=2,
13+
)
14+
for item in items:
15+
print(item)

src/datadog_api_client/v2/api/service_definition_api.py

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,19 @@
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
11+
from datadog_api_client.model_utils import (
12+
set_attribute_from_path,
13+
get_attribute_from_path,
14+
UnsetType,
15+
unset,
16+
)
1017
from datadog_api_client.v2.model.service_definitions_list_response import ServiceDefinitionsListResponse
18+
from datadog_api_client.v2.model.service_definition_data import ServiceDefinitionData
1119
from datadog_api_client.v2.model.service_definition_create_response import ServiceDefinitionCreateResponse
1220
from datadog_api_client.v2.model.service_definitions_create_request import ServiceDefinitionsCreateRequest
1321
from datadog_api_client.v2.model.service_definition_v2_dot1 import ServiceDefinitionV2Dot1
@@ -106,7 +114,18 @@ def __init__(self, api_client=None):
106114
"version": "v2",
107115
"servers": None,
108116
},
109-
params_map={},
117+
params_map={
118+
"page_size": {
119+
"openapi_types": (int,),
120+
"attribute": "page[size]",
121+
"location": "query",
122+
},
123+
"page_number": {
124+
"openapi_types": (int,),
125+
"attribute": "page[number]",
126+
"location": "query",
127+
},
128+
},
110129
headers_map={
111130
"accept": ["application/json"],
112131
"content_type": [],
@@ -167,12 +186,66 @@ def get_service_definition(
167186

168187
def list_service_definitions(
169188
self,
189+
*,
190+
page_size: Union[int, UnsetType] = unset,
191+
page_number: Union[int, UnsetType] = unset,
170192
) -> ServiceDefinitionsListResponse:
171193
"""Get all service definitions.
172194
173195
Get a list of all service definitions from the Datadog Service Catalog.
174196
197+
:param page_size: Size for a given page. The maximum allowed value is 5000.
198+
:type page_size: int, optional
199+
:param page_number: Specific page number to return.
200+
:type page_number: int, optional
175201
:rtype: ServiceDefinitionsListResponse
176202
"""
177203
kwargs: Dict[str, Any] = {}
204+
if page_size is not unset:
205+
kwargs["page_size"] = page_size
206+
207+
if page_number is not unset:
208+
kwargs["page_number"] = page_number
209+
178210
return self._list_service_definitions_endpoint.call_with_http_info(**kwargs)
211+
212+
def list_service_definitions_with_pagination(
213+
self,
214+
*,
215+
page_size: Union[int, UnsetType] = unset,
216+
page_number: Union[int, UnsetType] = unset,
217+
) -> collections.abc.Iterable[ServiceDefinitionData]:
218+
"""Get all service definitions.
219+
220+
Provide a paginated version of :meth:`list_service_definitions`, returning all items.
221+
222+
:param page_size: Size for a given page. The maximum allowed value is 5000.
223+
:type page_size: int, optional
224+
:param page_number: Specific page number to return.
225+
:type page_number: int, optional
226+
227+
:return: A generator of paginated results.
228+
:rtype: collections.abc.Iterable[ServiceDefinitionData]
229+
"""
230+
kwargs: Dict[str, Any] = {}
231+
if page_size is not unset:
232+
kwargs["page_size"] = page_size
233+
234+
if page_number is not unset:
235+
kwargs["page_number"] = page_number
236+
237+
local_page_size = get_attribute_from_path(kwargs, "page_size", 10)
238+
endpoint = self._list_service_definitions_endpoint
239+
set_attribute_from_path(kwargs, "page_size", local_page_size, endpoint.params_map)
240+
while True:
241+
response = endpoint.call_with_http_info(**kwargs)
242+
for item in get_attribute_from_path(response, "data"):
243+
yield item
244+
if len(get_attribute_from_path(response, "data")) < local_page_size:
245+
break
246+
set_attribute_from_path(
247+
kwargs,
248+
"page_number",
249+
get_attribute_from_path(kwargs, "page_number", 0) + local_page_size,
250+
endpoint.params_map,
251+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2023-04-05T09:45:34.876Z
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
interactions:
2+
- request:
3+
body: null
4+
headers:
5+
accept:
6+
- application/json
7+
method: GET
8+
uri: https://api.datadoghq.com/api/v2/services/definitions?page%5Bsize%5D=2
9+
response:
10+
body:
11+
string: '{"data":[{"type":"service-definition","id":"000c4db9ae43787066748b39ad1c3059","attributes":{"meta":{"last-modified-time":"2023-04-03T20:23:00Z","github-html-url":"","ingestion-source":"api","origin":"unknown","origin-detail":"","warnings":[],"ingested-schema-version":"v2.1"},"schema":{"schema-version":"v2.1","dd-service":"service-examplecreateorupdateservicedefinitionusingschemav21returnscreatedresponse1680553380","team":"my-team","contacts":[{"name":"Team
12+
Email","type":"email","contact":"[email protected]"}],"links":[{"name":"Architecture","type":"doc","provider":"Gigoogle
13+
drivetHub","url":"https://my-runbook"},{"name":"Runbook","type":"runbook","url":"https://my-runbook"},{"name":"Source
14+
Code","type":"repo","provider":"GitHub","url":"https://github.com/DataDog/schema"}],"tags":["my:tag","service:tag"],"integrations":{"pagerduty":{"service-url":"https://my-org.pagerduty.com/service-directory/PMyService"},"opsgenie":{"service-url":"https://my-org.opsgenie.com/service/123e4567-e89b-12d3-a456-426614174000","region":"US"}},"extensions":{"myorgextension":"extensionvalue"}}}},{"type":"service-definition","id":"000c83c634df871f80ecbb47fa6b8bcc","attributes":{"meta":{"last-modified-time":"2022-11-17T02:44:15Z","github-html-url":"","ingestion-source":"api","origin":"","origin-detail":"","warnings":[],"ingested-schema-version":"v2"},"schema":{"schema-version":"v2","dd-service":"service-test-ruby-create_or_update_service_definition_returns_created_response-1668653055","dd-team":"my-team","team":"my-team","contacts":[{"name":"Team
15+
Email","type":"email","contact":"[email protected]"}],"links":[{"name":"Runbook","type":"runbook","url":"https://my-runbook"}],"repos":[{"name":"Source
16+
Code","provider":"GitHub","url":"https://github.com/DataDog/schema"}],"docs":[{"name":"Architecture","provider":"google
17+
drive","url":"https://gdrive/mydoc"}],"tags":["my:tag","service:tag"],"integrations":{"pagerduty":"https://my-org.pagerduty.com/service-directory/PMyService","opsgenie":{"service-url":"https://my-org.opsgenie.com/service/123e4567-e89b-12d3-a456-426614174000","region":"US"}},"extensions":{"myorgextension":"extensionvalue"}}}}]}
18+
19+
'
20+
headers:
21+
content-type:
22+
- application/json
23+
status:
24+
code: 200
25+
message: OK
26+
- request:
27+
body: null
28+
headers:
29+
accept:
30+
- application/json
31+
method: GET
32+
uri: https://api.datadoghq.com/api/v2/services/definitions?page%5Bsize%5D=2&page%5Bnumber%5D=2
33+
response:
34+
body:
35+
string: '{"data":[{"type":"service-definition","id":"0059bcab67b74e99cc832ca503019574","attributes":{"meta":{"last-modified-time":"2023-03-02T12:21:20Z","github-html-url":"","ingestion-source":"api","origin":"dd_terraform","origin-detail":"","warnings":[{"keyword-location":"/properties/contacts/items/$ref/allOf/1/then/properties/contact/pattern","instance-location":"/contacts/0/contact","message":"does
36+
not match pattern ''https://[a-zA-Z0-9_\\\\-]+.slack\\\\.com/archives/[a-zA-Z0-9_\\\\-]+''"},{"keyword-location":"/properties/contacts/items/$ref/allOf/0/then/properties/contact/format","instance-location":"/contacts/1/contact","message":"''BBB''
37+
is not valid ''email''"},{"keyword-location":"/properties/contacts/items/$ref/allOf/0/then/properties/contact/format","instance-location":"/contacts/2/contact","message":"''AAA''
38+
is not valid ''email''"},{"keyword-location":"/properties/contacts/items/$ref/allOf/0/then/properties/contact/format","instance-location":"/contacts/3/contact","message":"''AAA''
39+
is not valid ''email''"},{"keyword-location":"/properties/contacts/items/$ref/allOf/0/then/properties/contact/format","instance-location":"/contacts/4/contact","message":"''BBB''
40+
is not valid ''email''"}],"ingested-schema-version":"v2"},"schema":{"schema-version":"v2","dd-service":"tf-testaccdatadogservicedefinition_order-local-1677759678","team":"","contacts":[{"name":"AA","type":"email","contact":"AAA"},{"name":"AA","type":"slack","contact":"AAA"},{"name":"BB","type":"email","contact":"AAA"},{"name":"AA","type":"email","contact":"BBB"},{"name":"BB","type":"email","contact":"BBB"}],"links":[],"repos":[],"docs":[],"tags":["aaa","bbb"],"integrations":{},"extensions":{}}}}]}
41+
42+
'
43+
headers:
44+
content-type:
45+
- application/json
46+
status:
47+
code: 200
48+
message: OK
49+
version: 1

tests/v2/features/service_definition.feature

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,12 @@ Feature: Service Definition
104104
Given new "ListServiceDefinitions" request
105105
When the request is sent
106106
Then the response status is 200 OK
107-
And the response "data[0].attributes.meta.ingested-schema-version" is equal to "v2"
107+
And the response "data[0].attributes.meta.ingestion-source" is equal to "api"
108+
109+
@replay-only @team:DataDog/service-catalog @with-pagination
110+
Scenario: Get all service definitions returns "OK" response with pagination
111+
Given new "ListServiceDefinitions" request
112+
And request contains "page[size]" parameter with value 2
113+
When the request with pagination is sent
114+
Then the response status is 200 OK
115+
And the response has 3 items

0 commit comments

Comments
 (0)