diff --git a/.apigentools-info b/.apigentools-info index e245121c14f..7390beefed6 100644 --- a/.apigentools-info +++ b/.apigentools-info @@ -4,13 +4,13 @@ "spec_versions": { "v1": { "apigentools_version": "1.6.5", - "regenerated": "2023-09-06 11:51:22.537852", - "spec_repo_commit": "c59cafad" + "regenerated": "2023-09-06 12:26:28.379024", + "spec_repo_commit": "07ee6775" }, "v2": { "apigentools_version": "1.6.5", - "regenerated": "2023-09-06 11:51:22.551228", - "spec_repo_commit": "c59cafad" + "regenerated": "2023-09-06 12:26:28.392536", + "spec_repo_commit": "07ee6775" } } } \ No newline at end of file diff --git a/.generator/schemas/v2/openapi.yaml b/.generator/schemas/v2/openapi.yaml index 19fdbd6b3ea..05d2d226b42 100644 --- a/.generator/schemas/v2/openapi.yaml +++ b/.generator/schemas/v2/openapi.yaml @@ -18815,6 +18815,16 @@ paths: schema: example: created_by,monitor type: string + - $ref: '#/components/parameters/PageOffset' + - description: Maximum number of downtimes in the response. + example: 100 + in: query + name: page[limit] + required: false + schema: + default: 30 + format: int64 + type: integer responses: '200': content: @@ -18838,6 +18848,10 @@ paths: summary: Get all downtimes tags: - Downtimes + x-pagination: + limitParam: page[limit] + pageOffsetParam: page[offset] + resultsPath: data x-unstable: '**Note**: This endpoint is in private beta. If you have any feedback, contact [Datadog support](https://docs.datadoghq.com/help/).' diff --git a/examples/v2/downtimes/ListDowntimes_805770330.java b/examples/v2/downtimes/ListDowntimes_805770330.java new file mode 100644 index 00000000000..292e1625f19 --- /dev/null +++ b/examples/v2/downtimes/ListDowntimes_805770330.java @@ -0,0 +1,29 @@ +// Get all downtimes returns "OK" response with pagination + +import com.datadog.api.client.ApiClient; +import com.datadog.api.client.PaginationIterable; +import com.datadog.api.client.v2.api.DowntimesApi; +import com.datadog.api.client.v2.api.DowntimesApi.ListDowntimesOptionalParameters; +import com.datadog.api.client.v2.model.DowntimeResponseData; + +public class Example { + public static void main(String[] args) { + ApiClient defaultClient = ApiClient.getDefaultApiClient(); + defaultClient.setUnstableOperationEnabled("v2.listDowntimes", true); + DowntimesApi apiInstance = new DowntimesApi(defaultClient); + + try { + PaginationIterable iterable = + apiInstance.listDowntimesWithPagination( + new ListDowntimesOptionalParameters().pageLimit(2L)); + + for (DowntimeResponseData item : iterable) { + System.out.println(item); + } + } catch (RuntimeException e) { + System.err.println("Exception when calling DowntimesApi#listDowntimesWithPagination"); + System.err.println("Reason: " + e.getMessage()); + e.printStackTrace(); + } + } +} diff --git a/src/main/java/com/datadog/api/client/v2/api/DowntimesApi.java b/src/main/java/com/datadog/api/client/v2/api/DowntimesApi.java index b6da2d0e207..753560a02b0 100644 --- a/src/main/java/com/datadog/api/client/v2/api/DowntimesApi.java +++ b/src/main/java/com/datadog/api/client/v2/api/DowntimesApi.java @@ -3,9 +3,11 @@ import com.datadog.api.client.ApiClient; import com.datadog.api.client.ApiException; import com.datadog.api.client.ApiResponse; +import com.datadog.api.client.PaginationIterable; import com.datadog.api.client.Pair; import com.datadog.api.client.v2.model.DowntimeCreateRequest; import com.datadog.api.client.v2.model.DowntimeResponse; +import com.datadog.api.client.v2.model.DowntimeResponseData; import com.datadog.api.client.v2.model.DowntimeUpdateRequest; import com.datadog.api.client.v2.model.ListDowntimesResponse; import com.datadog.api.client.v2.model.MonitorDowntimeMatchResponse; @@ -13,6 +15,7 @@ import jakarta.ws.rs.core.GenericType; import java.util.ArrayList; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.concurrent.CompletableFuture; @@ -567,6 +570,8 @@ public CompletableFuture> getDowntimeWithHttpInfoA public static class ListDowntimesOptionalParameters { private Boolean currentOnly; private String include; + private Long pageOffset; + private Long pageLimit; /** * Set currentOnly. @@ -591,6 +596,29 @@ public ListDowntimesOptionalParameters include(String include) { this.include = include; return this; } + + /** + * Set pageOffset. + * + * @param pageOffset Specific offset to use as the beginning of the returned page. (optional, + * default to 0) + * @return ListDowntimesOptionalParameters + */ + public ListDowntimesOptionalParameters pageOffset(Long pageOffset) { + this.pageOffset = pageOffset; + return this; + } + + /** + * Set pageLimit. + * + * @param pageLimit Maximum number of downtimes in the response. (optional, default to 30) + * @return ListDowntimesOptionalParameters + */ + public ListDowntimesOptionalParameters pageLimit(Long pageLimit) { + this.pageLimit = pageLimit; + return this; + } } /** @@ -651,6 +679,58 @@ public CompletableFuture listDowntimesAsync( }); } + /** + * Get all downtimes. + * + *

See {@link #listDowntimesWithHttpInfo}. + * + * @return PaginationIterable<DowntimeResponseData> + */ + public PaginationIterable listDowntimesWithPagination() { + ListDowntimesOptionalParameters parameters = new ListDowntimesOptionalParameters(); + return listDowntimesWithPagination(parameters); + } + + /** + * Get all downtimes. + * + *

See {@link #listDowntimesWithHttpInfo}. + * + * @return ListDowntimesResponse + */ + public PaginationIterable listDowntimesWithPagination( + ListDowntimesOptionalParameters parameters) { + String resultsPath = "getData"; + String valueGetterPath = ""; + String valueSetterPath = "pageOffset"; + Boolean valueSetterParamOptional = true; + Long limit; + + if (parameters.pageLimit == null) { + limit = 30l; + parameters.pageLimit(limit); + } else { + limit = parameters.pageLimit; + } + + LinkedHashMap args = new LinkedHashMap(); + args.put("optionalParams", parameters); + + PaginationIterable iterator = + new PaginationIterable( + this, + "listDowntimes", + resultsPath, + valueGetterPath, + valueSetterPath, + valueSetterParamOptional, + true, + limit, + args); + + return iterator; + } + /** * Get all scheduled downtimes. * @@ -678,6 +758,8 @@ public ApiResponse listDowntimesWithHttpInfo( Object localVarPostBody = null; Boolean currentOnly = parameters.currentOnly; String include = parameters.include; + Long pageOffset = parameters.pageOffset; + Long pageLimit = parameters.pageLimit; // create path and map variables String localVarPath = "/api/v2/downtime"; @@ -686,6 +768,8 @@ public ApiResponse listDowntimesWithHttpInfo( localVarQueryParams.addAll(apiClient.parameterToPairs("", "current_only", currentOnly)); localVarQueryParams.addAll(apiClient.parameterToPairs("", "include", include)); + localVarQueryParams.addAll(apiClient.parameterToPairs("", "page[offset]", pageOffset)); + localVarQueryParams.addAll(apiClient.parameterToPairs("", "page[limit]", pageLimit)); Invocation.Builder builder = apiClient.createBuilder( @@ -730,6 +814,8 @@ public CompletableFuture> listDowntimesWithHt Object localVarPostBody = null; Boolean currentOnly = parameters.currentOnly; String include = parameters.include; + Long pageOffset = parameters.pageOffset; + Long pageLimit = parameters.pageLimit; // create path and map variables String localVarPath = "/api/v2/downtime"; @@ -738,6 +824,8 @@ public CompletableFuture> listDowntimesWithHt localVarQueryParams.addAll(apiClient.parameterToPairs("", "current_only", currentOnly)); localVarQueryParams.addAll(apiClient.parameterToPairs("", "include", include)); + localVarQueryParams.addAll(apiClient.parameterToPairs("", "page[offset]", pageOffset)); + localVarQueryParams.addAll(apiClient.parameterToPairs("", "page[limit]", pageLimit)); Invocation.Builder builder; try { diff --git a/src/test/resources/cassettes/features/v2/Get_all_downtimes_returns_OK_response_with_pagination.freeze b/src/test/resources/cassettes/features/v2/Get_all_downtimes_returns_OK_response_with_pagination.freeze new file mode 100644 index 00000000000..d76ab527dee --- /dev/null +++ b/src/test/resources/cassettes/features/v2/Get_all_downtimes_returns_OK_response_with_pagination.freeze @@ -0,0 +1 @@ +2023-09-05T12:32:39.085Z \ No newline at end of file diff --git a/src/test/resources/cassettes/features/v2/Get_all_downtimes_returns_OK_response_with_pagination.json b/src/test/resources/cassettes/features/v2/Get_all_downtimes_returns_OK_response_with_pagination.json new file mode 100644 index 00000000000..7d7c1d81e61 --- /dev/null +++ b/src/test/resources/cassettes/features/v2/Get_all_downtimes_returns_OK_response_with_pagination.json @@ -0,0 +1,67 @@ +[ + { + "httpRequest": { + "headers": {}, + "method": "GET", + "path": "/api/v2/downtime", + "queryStringParameters": { + "page[limit]": [ + "2" + ] + }, + "keepAlive": false, + "secure": true + }, + "httpResponse": { + "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", + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "statusCode": 200, + "reasonPhrase": "OK" + }, + "times": { + "remainingTimes": 1 + }, + "timeToLive": { + "unlimited": true + }, + "id": "eab05883-3e2e-3fd9-77ff-fe2fa5d6a767" + }, + { + "httpRequest": { + "headers": {}, + "method": "GET", + "path": "/api/v2/downtime", + "queryStringParameters": { + "page[limit]": [ + "2" + ], + "page[offset]": [ + "2" + ] + }, + "keepAlive": false, + "secure": true + }, + "httpResponse": { + "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", + "headers": { + "Content-Type": [ + "application/json" + ] + }, + "statusCode": 200, + "reasonPhrase": "OK" + }, + "times": { + "remainingTimes": 1 + }, + "timeToLive": { + "unlimited": true + }, + "id": "d373bb44-355f-b07f-5a00-4f9395685267" + } +] \ No newline at end of file diff --git a/src/test/resources/com/datadog/api/client/v2/api/downtimes.feature b/src/test/resources/com/datadog/api/client/v2/api/downtimes.feature index 7f8a5bcdbd6..35c4a65f020 100644 --- a/src/test/resources/com/datadog/api/client/v2/api/downtimes.feature +++ b/src/test/resources/com/datadog/api/client/v2/api/downtimes.feature @@ -98,6 +98,15 @@ Feature: Downtimes Then the response status is 200 OK And the response "data" has item with field "id" with value "1dcb33f8-b23a-11ed-ae77-da7ad0900002" + @replay-only @skip-validation @team:DataDog/monitor-app @with-pagination + Scenario: Get all downtimes returns "OK" response with pagination + Given operation "ListDowntimes" enabled + And new "ListDowntimes" request + And request contains "page[limit]" parameter with value 2 + When the request with pagination is sent + Then the response status is 200 OK + And the response has 3 items + @skip-validation @team:DataDog/monitor-app Scenario: Schedule a downtime returns "Bad Request" response Given new "CreateDowntime" request