Skip to content

Commit ffa21b7

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add pagination parameters to downtimes listing (#1308)
Co-authored-by: ci.datadog-api-spec <[email protected]>
1 parent 690439f commit ffa21b7

File tree

8 files changed

+247
-4
lines changed

8 files changed

+247
-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-06 11:51:20.362624",
8-
"spec_repo_commit": "c59cafad"
7+
"regenerated": "2023-09-06 12:26:36.154836",
8+
"spec_repo_commit": "07ee6775"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.5",
12-
"regenerated": "2023-09-06 11:51:20.376672",
13-
"spec_repo_commit": "c59cafad"
12+
"regenerated": "2023-09-06 12:26:36.174283",
13+
"spec_repo_commit": "07ee6775"
1414
}
1515
}
1616
}

.generator/schemas/v2/openapi.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18815,6 +18815,16 @@ paths:
1881518815
schema:
1881618816
example: created_by,monitor
1881718817
type: string
18818+
- $ref: '#/components/parameters/PageOffset'
18819+
- description: Maximum number of downtimes in the response.
18820+
example: 100
18821+
in: query
18822+
name: page[limit]
18823+
required: false
18824+
schema:
18825+
default: 30
18826+
format: int64
18827+
type: integer
1881818828
responses:
1881918829
'200':
1882018830
content:
@@ -18838,6 +18848,10 @@ paths:
1883818848
summary: Get all downtimes
1883918849
tags:
1884018850
- Downtimes
18851+
x-pagination:
18852+
limitParam: page[limit]
18853+
pageOffsetParam: page[offset]
18854+
resultsPath: data
1884118855
x-unstable: '**Note**: This endpoint is in private beta.
1884218856

1884318857
If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"2023-09-05T12:32:39.085Z"
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
{
2+
"log": {
3+
"_recordingName": "Downtimes/Get all downtimes returns \"OK\" response with pagination",
4+
"creator": {
5+
"comment": "persister:fs",
6+
"name": "Polly.JS",
7+
"version": "6.0.5"
8+
},
9+
"entries": [
10+
{
11+
"_id": "eab058833e2e3fd977fffe2fa5d6a767",
12+
"_order": 0,
13+
"cache": {},
14+
"request": {
15+
"bodySize": 0,
16+
"cookies": [],
17+
"headers": [
18+
{
19+
"_fromType": "array",
20+
"name": "accept",
21+
"value": "application/json"
22+
}
23+
],
24+
"headersSize": 520,
25+
"httpVersion": "HTTP/1.1",
26+
"method": "GET",
27+
"queryString": [
28+
{
29+
"name": "page",
30+
"value": {
31+
"limit": "2"
32+
}
33+
}
34+
],
35+
"url": "https://api.datadoghq.com/api/v2/downtime?page%5Blimit%5D=2"
36+
},
37+
"response": {
38+
"bodySize": 1126,
39+
"content": {
40+
"mimeType": "application/json",
41+
"size": 1126,
42+
"text": "{\"data\":[{\"type\":\"downtime\",\"attributes\":{\"mute_first_recovery_notification\":false,\"canceled\":null,\"monitor_identifier\":{\"monitor_tags\":[\"*\"]},\"schedule\":{\"start\":\"2023-05-22T03:06:54.072998+00:00\",\"end\":null},\"notify_end_types\":[\"expired\"],\"notify_end_states\":[\"no data\",\"warn\",\"alert\"],\"status\":\"active\",\"scope\":\"host:\\\"java-hostsMuteErrorsTest-local-1684724813\\\"\",\"created\":\"2023-05-22T03:06:54.079122+00:00\",\"display_timezone\":\"UTC\",\"message\":null,\"modified\":\"2023-05-22T03:06:54.079122+00:00\"},\"id\":\"b4613732-f84d-11ed-a766-da7ad0900002\"},{\"type\":\"downtime\",\"attributes\":{\"mute_first_recovery_notification\":false,\"canceled\":null,\"monitor_identifier\":{\"monitor_tags\":[\"*\"]},\"schedule\":{\"start\":\"2023-05-23T03:21:54.687109+00:00\",\"end\":null},\"notify_end_types\":[\"expired\"],\"notify_end_states\":[\"no data\",\"warn\",\"alert\"],\"status\":\"active\",\"scope\":\"host:\\\"java-hostsMuteErrorsTest-local-1684812114\\\"\",\"created\":\"2023-05-23T03:21:54.690618+00:00\",\"display_timezone\":\"UTC\",\"message\":null,\"modified\":\"2023-05-23T03:21:54.690618+00:00\"},\"id\":\"f799770a-f918-11ed-8b48-da7ad0900002\"}],\"meta\":{\"page\":{\"total_filtered_count\":3}}}\n"
43+
},
44+
"cookies": [],
45+
"headers": [
46+
{
47+
"name": "content-type",
48+
"value": "application/json"
49+
}
50+
],
51+
"headersSize": 696,
52+
"httpVersion": "HTTP/1.1",
53+
"redirectURL": "",
54+
"status": 200,
55+
"statusText": "OK"
56+
},
57+
"startedDateTime": "2023-09-05T12:32:39.094Z",
58+
"time": 491
59+
},
60+
{
61+
"_id": "d373bb44355fb07f5a004f9395685267",
62+
"_order": 0,
63+
"cache": {},
64+
"request": {
65+
"bodySize": 0,
66+
"cookies": [],
67+
"headers": [
68+
{
69+
"_fromType": "array",
70+
"name": "accept",
71+
"value": "application/json"
72+
}
73+
],
74+
"headersSize": 539,
75+
"httpVersion": "HTTP/1.1",
76+
"method": "GET",
77+
"queryString": [
78+
{
79+
"name": "page",
80+
"value": {
81+
"limit": "2",
82+
"offset": "2"
83+
}
84+
}
85+
],
86+
"url": "https://api.datadoghq.com/api/v2/downtime?page%5Blimit%5D=2&page%5Boffset%5D=2"
87+
},
88+
"response": {
89+
"bodySize": 1126,
90+
"content": {
91+
"mimeType": "application/json",
92+
"size": 1126,
93+
"text": "{\"data\":[{\"type\":\"downtime\",\"attributes\":{\"modified\":\"2023-05-24T03:29:35.343207+00:00\",\"created\":\"2023-05-24T03:29:35.343207+00:00\",\"canceled\":null,\"status\":\"active\",\"scope\":\"host:\\\"java-hostsMuteErrorsTest-local-1684898975\\\"\",\"display_timezone\":\"UTC\",\"schedule\":{\"end\":null,\"start\":\"2023-05-24T03:29:35.340446+00:00\"},\"message\":null,\"mute_first_recovery_notification\":false,\"notify_end_types\":[\"expired\"],\"notify_end_states\":[\"warn\",\"no data\",\"alert\"],\"monitor_identifier\":{\"monitor_tags\":[\"*\"]}},\"id\":\"34953930-f9e3-11ed-85d4-da7ad0900002\"}],\"meta\":{\"page\":{\"total_filtered_count\":3}}}\n"
94+
},
95+
"cookies": [],
96+
"headers": [
97+
{
98+
"name": "content-type",
99+
"value": "application/json"
100+
}
101+
],
102+
"headersSize": 696,
103+
"httpVersion": "HTTP/1.1",
104+
"redirectURL": "",
105+
"status": 200,
106+
"statusText": "OK"
107+
},
108+
"startedDateTime": "2023-09-05T12:32:39.593Z",
109+
"time": 452
110+
}
111+
],
112+
"pages": [],
113+
"version": "1.2"
114+
}
115+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Get all downtimes returns "OK" response with pagination
3+
*/
4+
5+
import { client, v2 } from "@datadog/datadog-api-client";
6+
7+
const configuration = client.createConfiguration();
8+
configuration.unstableOperations["v2.listDowntimes"] = true;
9+
const apiInstance = new v2.DowntimesApi(configuration);
10+
11+
const params: v2.DowntimesApiListDowntimesRequest = {
12+
pageLimit: 2,
13+
};
14+
15+
(async () => {
16+
try {
17+
for await (const item of apiInstance.listDowntimesWithPagination(params)) {
18+
console.log(item);
19+
}
20+
} catch (error) {
21+
console.error(error);
22+
}
23+
})();

features/support/scenarios_model_mapping.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2721,6 +2721,14 @@ export const ScenariosModelMappings: {[key: string]: {[key: string]: any}} = {
27212721
"type": "string",
27222722
"format": "",
27232723
},
2724+
"pageOffset": {
2725+
"type": "number",
2726+
"format": "int64",
2727+
},
2728+
"pageLimit": {
2729+
"type": "number",
2730+
"format": "int64",
2731+
},
27242732
"operationResponseType": "ListDowntimesResponse",
27252733
},
27262734
"v2.CreateDowntime": {

features/v2/downtimes.feature

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ Feature: Downtimes
9898
Then the response status is 200 OK
9999
And the response "data" has item with field "id" with value "1dcb33f8-b23a-11ed-ae77-da7ad0900002"
100100

101+
@replay-only @skip-validation @team:DataDog/monitor-app @with-pagination
102+
Scenario: Get all downtimes returns "OK" response with pagination
103+
Given operation "ListDowntimes" enabled
104+
And new "ListDowntimes" request
105+
And request contains "page[limit]" parameter with value 2
106+
When the request with pagination is sent
107+
Then the response status is 200 OK
108+
And the response has 3 items
109+
101110
@skip-validation @team:DataDog/monitor-app
102111
Scenario: Schedule a downtime returns "Bad Request" response
103112
Given new "CreateDowntime" request

packages/datadog-api-client-v2/apis/DowntimesApi.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { ApiException } from "../../datadog-api-client-common/exception";
1919
import { APIErrorResponse } from "../models/APIErrorResponse";
2020
import { DowntimeCreateRequest } from "../models/DowntimeCreateRequest";
2121
import { DowntimeResponse } from "../models/DowntimeResponse";
22+
import { DowntimeResponseData } from "../models/DowntimeResponseData";
2223
import { DowntimeUpdateRequest } from "../models/DowntimeUpdateRequest";
2324
import { ListDowntimesResponse } from "../models/ListDowntimesResponse";
2425
import { MonitorDowntimeMatchResponse } from "../models/MonitorDowntimeMatchResponse";
@@ -161,6 +162,8 @@ export class DowntimesApiRequestFactory extends BaseAPIRequestFactory {
161162
public async listDowntimes(
162163
currentOnly?: boolean,
163164
include?: string,
165+
pageOffset?: number,
166+
pageLimit?: number,
164167
_options?: Configuration
165168
): Promise<RequestContext> {
166169
const _config = _options || this.configuration;
@@ -193,6 +196,18 @@ export class DowntimesApiRequestFactory extends BaseAPIRequestFactory {
193196
ObjectSerializer.serialize(include, "string", "")
194197
);
195198
}
199+
if (pageOffset !== undefined) {
200+
requestContext.setQueryParam(
201+
"page[offset]",
202+
ObjectSerializer.serialize(pageOffset, "number", "int64")
203+
);
204+
}
205+
if (pageLimit !== undefined) {
206+
requestContext.setQueryParam(
207+
"page[limit]",
208+
ObjectSerializer.serialize(pageLimit, "number", "int64")
209+
);
210+
}
196211

197212
// Apply auth methods
198213
applySecurityAuthentication(_config, requestContext, [
@@ -705,6 +720,16 @@ export interface DowntimesApiListDowntimesRequest {
705720
* @type string
706721
*/
707722
include?: string;
723+
/**
724+
* Specific offset to use as the beginning of the returned page.
725+
* @type number
726+
*/
727+
pageOffset?: number;
728+
/**
729+
* Maximum number of downtimes in the response.
730+
* @type number
731+
*/
732+
pageLimit?: number;
708733
}
709734

710735
export interface DowntimesApiListMonitorDowntimesRequest {
@@ -820,6 +845,8 @@ export class DowntimesApi {
820845
const requestContextPromise = this.requestFactory.listDowntimes(
821846
param.currentOnly,
822847
param.include,
848+
param.pageOffset,
849+
param.pageLimit,
823850
options
824851
);
825852
return requestContextPromise.then((requestContext) => {
@@ -831,6 +858,52 @@ export class DowntimesApi {
831858
});
832859
}
833860

861+
/**
862+
* Provide a paginated version of listDowntimes returning a generator with all the items.
863+
*/
864+
public async *listDowntimesWithPagination(
865+
param: DowntimesApiListDowntimesRequest = {},
866+
options?: Configuration
867+
): AsyncGenerator<DowntimeResponseData> {
868+
let pageSize = 30;
869+
if (param.pageLimit !== undefined) {
870+
pageSize = param.pageLimit;
871+
}
872+
param.pageLimit = pageSize;
873+
while (true) {
874+
const requestContext = await this.requestFactory.listDowntimes(
875+
param.currentOnly,
876+
param.include,
877+
param.pageOffset,
878+
param.pageLimit,
879+
options
880+
);
881+
const responseContext = await this.configuration.httpApi.send(
882+
requestContext
883+
);
884+
885+
const response = await this.responseProcessor.listDowntimes(
886+
responseContext
887+
);
888+
const responseData = response.data;
889+
if (responseData === undefined) {
890+
break;
891+
}
892+
const results = responseData;
893+
for (const item of results) {
894+
yield item;
895+
}
896+
if (results.length < pageSize) {
897+
break;
898+
}
899+
if (param.pageOffset === undefined) {
900+
param.pageOffset = pageSize;
901+
} else {
902+
param.pageOffset = param.pageOffset + pageSize;
903+
}
904+
}
905+
}
906+
834907
/**
835908
* Get all active downtimes for the specified monitor.
836909
* @param param The request object

0 commit comments

Comments
 (0)