Skip to content

Commit f36d04f

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add pagination parameters to downtimes listing (DataDog#1960)
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
1 parent de4fd26 commit f36d04f

File tree

7 files changed

+212
-4
lines changed

7 files changed

+212
-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:22.537852",
8-
"spec_repo_commit": "c59cafad"
7+
"regenerated": "2023-09-06 12:26:28.379024",
8+
"spec_repo_commit": "07ee6775"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.5",
12-
"regenerated": "2023-09-06 11:51:22.551228",
13-
"spec_repo_commit": "c59cafad"
12+
"regenerated": "2023-09-06 12:26:28.392536",
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: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Get all downtimes returns "OK" response with pagination
2+
3+
import com.datadog.api.client.ApiClient;
4+
import com.datadog.api.client.PaginationIterable;
5+
import com.datadog.api.client.v2.api.DowntimesApi;
6+
import com.datadog.api.client.v2.api.DowntimesApi.ListDowntimesOptionalParameters;
7+
import com.datadog.api.client.v2.model.DowntimeResponseData;
8+
9+
public class Example {
10+
public static void main(String[] args) {
11+
ApiClient defaultClient = ApiClient.getDefaultApiClient();
12+
defaultClient.setUnstableOperationEnabled("v2.listDowntimes", true);
13+
DowntimesApi apiInstance = new DowntimesApi(defaultClient);
14+
15+
try {
16+
PaginationIterable<DowntimeResponseData> iterable =
17+
apiInstance.listDowntimesWithPagination(
18+
new ListDowntimesOptionalParameters().pageLimit(2L));
19+
20+
for (DowntimeResponseData item : iterable) {
21+
System.out.println(item);
22+
}
23+
} catch (RuntimeException e) {
24+
System.err.println("Exception when calling DowntimesApi#listDowntimesWithPagination");
25+
System.err.println("Reason: " + e.getMessage());
26+
e.printStackTrace();
27+
}
28+
}
29+
}

src/main/java/com/datadog/api/client/v2/api/DowntimesApi.java

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@
33
import com.datadog.api.client.ApiClient;
44
import com.datadog.api.client.ApiException;
55
import com.datadog.api.client.ApiResponse;
6+
import com.datadog.api.client.PaginationIterable;
67
import com.datadog.api.client.Pair;
78
import com.datadog.api.client.v2.model.DowntimeCreateRequest;
89
import com.datadog.api.client.v2.model.DowntimeResponse;
10+
import com.datadog.api.client.v2.model.DowntimeResponseData;
911
import com.datadog.api.client.v2.model.DowntimeUpdateRequest;
1012
import com.datadog.api.client.v2.model.ListDowntimesResponse;
1113
import com.datadog.api.client.v2.model.MonitorDowntimeMatchResponse;
1214
import jakarta.ws.rs.client.Invocation;
1315
import jakarta.ws.rs.core.GenericType;
1416
import java.util.ArrayList;
1517
import java.util.HashMap;
18+
import java.util.LinkedHashMap;
1619
import java.util.List;
1720
import java.util.Map;
1821
import java.util.concurrent.CompletableFuture;
@@ -567,6 +570,8 @@ public CompletableFuture<ApiResponse<DowntimeResponse>> getDowntimeWithHttpInfoA
567570
public static class ListDowntimesOptionalParameters {
568571
private Boolean currentOnly;
569572
private String include;
573+
private Long pageOffset;
574+
private Long pageLimit;
570575

571576
/**
572577
* Set currentOnly.
@@ -591,6 +596,29 @@ public ListDowntimesOptionalParameters include(String include) {
591596
this.include = include;
592597
return this;
593598
}
599+
600+
/**
601+
* Set pageOffset.
602+
*
603+
* @param pageOffset Specific offset to use as the beginning of the returned page. (optional,
604+
* default to 0)
605+
* @return ListDowntimesOptionalParameters
606+
*/
607+
public ListDowntimesOptionalParameters pageOffset(Long pageOffset) {
608+
this.pageOffset = pageOffset;
609+
return this;
610+
}
611+
612+
/**
613+
* Set pageLimit.
614+
*
615+
* @param pageLimit Maximum number of downtimes in the response. (optional, default to 30)
616+
* @return ListDowntimesOptionalParameters
617+
*/
618+
public ListDowntimesOptionalParameters pageLimit(Long pageLimit) {
619+
this.pageLimit = pageLimit;
620+
return this;
621+
}
594622
}
595623

596624
/**
@@ -651,6 +679,58 @@ public CompletableFuture<ListDowntimesResponse> listDowntimesAsync(
651679
});
652680
}
653681

682+
/**
683+
* Get all downtimes.
684+
*
685+
* <p>See {@link #listDowntimesWithHttpInfo}.
686+
*
687+
* @return PaginationIterable&lt;DowntimeResponseData&gt;
688+
*/
689+
public PaginationIterable<DowntimeResponseData> listDowntimesWithPagination() {
690+
ListDowntimesOptionalParameters parameters = new ListDowntimesOptionalParameters();
691+
return listDowntimesWithPagination(parameters);
692+
}
693+
694+
/**
695+
* Get all downtimes.
696+
*
697+
* <p>See {@link #listDowntimesWithHttpInfo}.
698+
*
699+
* @return ListDowntimesResponse
700+
*/
701+
public PaginationIterable<DowntimeResponseData> listDowntimesWithPagination(
702+
ListDowntimesOptionalParameters parameters) {
703+
String resultsPath = "getData";
704+
String valueGetterPath = "";
705+
String valueSetterPath = "pageOffset";
706+
Boolean valueSetterParamOptional = true;
707+
Long limit;
708+
709+
if (parameters.pageLimit == null) {
710+
limit = 30l;
711+
parameters.pageLimit(limit);
712+
} else {
713+
limit = parameters.pageLimit;
714+
}
715+
716+
LinkedHashMap<String, Object> args = new LinkedHashMap<String, Object>();
717+
args.put("optionalParams", parameters);
718+
719+
PaginationIterable iterator =
720+
new PaginationIterable(
721+
this,
722+
"listDowntimes",
723+
resultsPath,
724+
valueGetterPath,
725+
valueSetterPath,
726+
valueSetterParamOptional,
727+
true,
728+
limit,
729+
args);
730+
731+
return iterator;
732+
}
733+
654734
/**
655735
* Get all scheduled downtimes.
656736
*
@@ -678,6 +758,8 @@ public ApiResponse<ListDowntimesResponse> listDowntimesWithHttpInfo(
678758
Object localVarPostBody = null;
679759
Boolean currentOnly = parameters.currentOnly;
680760
String include = parameters.include;
761+
Long pageOffset = parameters.pageOffset;
762+
Long pageLimit = parameters.pageLimit;
681763
// create path and map variables
682764
String localVarPath = "/api/v2/downtime";
683765

@@ -686,6 +768,8 @@ public ApiResponse<ListDowntimesResponse> listDowntimesWithHttpInfo(
686768

687769
localVarQueryParams.addAll(apiClient.parameterToPairs("", "current_only", currentOnly));
688770
localVarQueryParams.addAll(apiClient.parameterToPairs("", "include", include));
771+
localVarQueryParams.addAll(apiClient.parameterToPairs("", "page[offset]", pageOffset));
772+
localVarQueryParams.addAll(apiClient.parameterToPairs("", "page[limit]", pageLimit));
689773

690774
Invocation.Builder builder =
691775
apiClient.createBuilder(
@@ -730,6 +814,8 @@ public CompletableFuture<ApiResponse<ListDowntimesResponse>> listDowntimesWithHt
730814
Object localVarPostBody = null;
731815
Boolean currentOnly = parameters.currentOnly;
732816
String include = parameters.include;
817+
Long pageOffset = parameters.pageOffset;
818+
Long pageLimit = parameters.pageLimit;
733819
// create path and map variables
734820
String localVarPath = "/api/v2/downtime";
735821

@@ -738,6 +824,8 @@ public CompletableFuture<ApiResponse<ListDowntimesResponse>> listDowntimesWithHt
738824

739825
localVarQueryParams.addAll(apiClient.parameterToPairs("", "current_only", currentOnly));
740826
localVarQueryParams.addAll(apiClient.parameterToPairs("", "include", include));
827+
localVarQueryParams.addAll(apiClient.parameterToPairs("", "page[offset]", pageOffset));
828+
localVarQueryParams.addAll(apiClient.parameterToPairs("", "page[limit]", pageLimit));
741829

742830
Invocation.Builder builder;
743831
try {
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: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
[
2+
{
3+
"httpRequest": {
4+
"headers": {},
5+
"method": "GET",
6+
"path": "/api/v2/downtime",
7+
"queryStringParameters": {
8+
"page[limit]": [
9+
"2"
10+
]
11+
},
12+
"keepAlive": false,
13+
"secure": true
14+
},
15+
"httpResponse": {
16+
"body": "{\"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",
17+
"headers": {
18+
"Content-Type": [
19+
"application/json"
20+
]
21+
},
22+
"statusCode": 200,
23+
"reasonPhrase": "OK"
24+
},
25+
"times": {
26+
"remainingTimes": 1
27+
},
28+
"timeToLive": {
29+
"unlimited": true
30+
},
31+
"id": "eab05883-3e2e-3fd9-77ff-fe2fa5d6a767"
32+
},
33+
{
34+
"httpRequest": {
35+
"headers": {},
36+
"method": "GET",
37+
"path": "/api/v2/downtime",
38+
"queryStringParameters": {
39+
"page[limit]": [
40+
"2"
41+
],
42+
"page[offset]": [
43+
"2"
44+
]
45+
},
46+
"keepAlive": false,
47+
"secure": true
48+
},
49+
"httpResponse": {
50+
"body": "{\"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",
51+
"headers": {
52+
"Content-Type": [
53+
"application/json"
54+
]
55+
},
56+
"statusCode": 200,
57+
"reasonPhrase": "OK"
58+
},
59+
"times": {
60+
"remainingTimes": 1
61+
},
62+
"timeToLive": {
63+
"unlimited": true
64+
},
65+
"id": "d373bb44-355f-b07f-5a00-4f9395685267"
66+
}
67+
]

src/test/resources/com/datadog/api/client/v2/api/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

0 commit comments

Comments
 (0)