diff --git a/.apigentools-info b/.apigentools-info index 40741c129a9..391cdc8fffa 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:20.362624", - "spec_repo_commit": "c59cafad" + "regenerated": "2023-09-06 12:26:36.154836", + "spec_repo_commit": "07ee6775" }, "v2": { "apigentools_version": "1.6.5", - "regenerated": "2023-09-06 11:51:20.376672", - "spec_repo_commit": "c59cafad" + "regenerated": "2023-09-06 12:26:36.174283", + "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/cassettes/v2/Downtimes_1733580485/Get-all-downtimes-returns-OK-response-with-pagination_3916578648/frozen.json b/cassettes/v2/Downtimes_1733580485/Get-all-downtimes-returns-OK-response-with-pagination_3916578648/frozen.json new file mode 100644 index 00000000000..25b828b775f --- /dev/null +++ b/cassettes/v2/Downtimes_1733580485/Get-all-downtimes-returns-OK-response-with-pagination_3916578648/frozen.json @@ -0,0 +1 @@ +"2023-09-05T12:32:39.085Z" diff --git a/cassettes/v2/Downtimes_1733580485/Get-all-downtimes-returns-OK-response-with-pagination_3916578648/recording.har b/cassettes/v2/Downtimes_1733580485/Get-all-downtimes-returns-OK-response-with-pagination_3916578648/recording.har new file mode 100644 index 00000000000..20c3269a2cf --- /dev/null +++ b/cassettes/v2/Downtimes_1733580485/Get-all-downtimes-returns-OK-response-with-pagination_3916578648/recording.har @@ -0,0 +1,115 @@ +{ + "log": { + "_recordingName": "Downtimes/Get all downtimes returns \"OK\" response with pagination", + "creator": { + "comment": "persister:fs", + "name": "Polly.JS", + "version": "6.0.5" + }, + "entries": [ + { + "_id": "eab058833e2e3fd977fffe2fa5d6a767", + "_order": 0, + "cache": {}, + "request": { + "bodySize": 0, + "cookies": [], + "headers": [ + { + "_fromType": "array", + "name": "accept", + "value": "application/json" + } + ], + "headersSize": 520, + "httpVersion": "HTTP/1.1", + "method": "GET", + "queryString": [ + { + "name": "page", + "value": { + "limit": "2" + } + } + ], + "url": "https://api.datadoghq.com/api/v2/downtime?page%5Blimit%5D=2" + }, + "response": { + "bodySize": 1126, + "content": { + "mimeType": "application/json", + "size": 1126, + "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" + }, + "cookies": [], + "headers": [ + { + "name": "content-type", + "value": "application/json" + } + ], + "headersSize": 696, + "httpVersion": "HTTP/1.1", + "redirectURL": "", + "status": 200, + "statusText": "OK" + }, + "startedDateTime": "2023-09-05T12:32:39.094Z", + "time": 491 + }, + { + "_id": "d373bb44355fb07f5a004f9395685267", + "_order": 0, + "cache": {}, + "request": { + "bodySize": 0, + "cookies": [], + "headers": [ + { + "_fromType": "array", + "name": "accept", + "value": "application/json" + } + ], + "headersSize": 539, + "httpVersion": "HTTP/1.1", + "method": "GET", + "queryString": [ + { + "name": "page", + "value": { + "limit": "2", + "offset": "2" + } + } + ], + "url": "https://api.datadoghq.com/api/v2/downtime?page%5Blimit%5D=2&page%5Boffset%5D=2" + }, + "response": { + "bodySize": 1126, + "content": { + "mimeType": "application/json", + "size": 1126, + "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" + }, + "cookies": [], + "headers": [ + { + "name": "content-type", + "value": "application/json" + } + ], + "headersSize": 696, + "httpVersion": "HTTP/1.1", + "redirectURL": "", + "status": 200, + "statusText": "OK" + }, + "startedDateTime": "2023-09-05T12:32:39.593Z", + "time": 452 + } + ], + "pages": [], + "version": "1.2" + } +} diff --git a/examples/v2/downtimes/ListDowntimes_805770330.ts b/examples/v2/downtimes/ListDowntimes_805770330.ts new file mode 100644 index 00000000000..d82fd0fc9fa --- /dev/null +++ b/examples/v2/downtimes/ListDowntimes_805770330.ts @@ -0,0 +1,23 @@ +/** + * Get all downtimes returns "OK" response with pagination + */ + +import { client, v2 } from "@datadog/datadog-api-client"; + +const configuration = client.createConfiguration(); +configuration.unstableOperations["v2.listDowntimes"] = true; +const apiInstance = new v2.DowntimesApi(configuration); + +const params: v2.DowntimesApiListDowntimesRequest = { + pageLimit: 2, +}; + +(async () => { + try { + for await (const item of apiInstance.listDowntimesWithPagination(params)) { + console.log(item); + } + } catch (error) { + console.error(error); + } +})(); diff --git a/features/support/scenarios_model_mapping.ts b/features/support/scenarios_model_mapping.ts index b0916974768..8eb20b66892 100644 --- a/features/support/scenarios_model_mapping.ts +++ b/features/support/scenarios_model_mapping.ts @@ -2721,6 +2721,14 @@ export const ScenariosModelMappings: {[key: string]: {[key: string]: any}} = { "type": "string", "format": "", }, + "pageOffset": { + "type": "number", + "format": "int64", + }, + "pageLimit": { + "type": "number", + "format": "int64", + }, "operationResponseType": "ListDowntimesResponse", }, "v2.CreateDowntime": { diff --git a/features/v2/downtimes.feature b/features/v2/downtimes.feature index 7f8a5bcdbd6..35c4a65f020 100644 --- a/features/v2/downtimes.feature +++ b/features/v2/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 diff --git a/packages/datadog-api-client-v2/apis/DowntimesApi.ts b/packages/datadog-api-client-v2/apis/DowntimesApi.ts index 26f0e44255e..4aea7e6ba30 100644 --- a/packages/datadog-api-client-v2/apis/DowntimesApi.ts +++ b/packages/datadog-api-client-v2/apis/DowntimesApi.ts @@ -19,6 +19,7 @@ import { ApiException } from "../../datadog-api-client-common/exception"; import { APIErrorResponse } from "../models/APIErrorResponse"; import { DowntimeCreateRequest } from "../models/DowntimeCreateRequest"; import { DowntimeResponse } from "../models/DowntimeResponse"; +import { DowntimeResponseData } from "../models/DowntimeResponseData"; import { DowntimeUpdateRequest } from "../models/DowntimeUpdateRequest"; import { ListDowntimesResponse } from "../models/ListDowntimesResponse"; import { MonitorDowntimeMatchResponse } from "../models/MonitorDowntimeMatchResponse"; @@ -161,6 +162,8 @@ export class DowntimesApiRequestFactory extends BaseAPIRequestFactory { public async listDowntimes( currentOnly?: boolean, include?: string, + pageOffset?: number, + pageLimit?: number, _options?: Configuration ): Promise { const _config = _options || this.configuration; @@ -193,6 +196,18 @@ export class DowntimesApiRequestFactory extends BaseAPIRequestFactory { ObjectSerializer.serialize(include, "string", "") ); } + if (pageOffset !== undefined) { + requestContext.setQueryParam( + "page[offset]", + ObjectSerializer.serialize(pageOffset, "number", "int64") + ); + } + if (pageLimit !== undefined) { + requestContext.setQueryParam( + "page[limit]", + ObjectSerializer.serialize(pageLimit, "number", "int64") + ); + } // Apply auth methods applySecurityAuthentication(_config, requestContext, [ @@ -705,6 +720,16 @@ export interface DowntimesApiListDowntimesRequest { * @type string */ include?: string; + /** + * Specific offset to use as the beginning of the returned page. + * @type number + */ + pageOffset?: number; + /** + * Maximum number of downtimes in the response. + * @type number + */ + pageLimit?: number; } export interface DowntimesApiListMonitorDowntimesRequest { @@ -820,6 +845,8 @@ export class DowntimesApi { const requestContextPromise = this.requestFactory.listDowntimes( param.currentOnly, param.include, + param.pageOffset, + param.pageLimit, options ); return requestContextPromise.then((requestContext) => { @@ -831,6 +858,52 @@ export class DowntimesApi { }); } + /** + * Provide a paginated version of listDowntimes returning a generator with all the items. + */ + public async *listDowntimesWithPagination( + param: DowntimesApiListDowntimesRequest = {}, + options?: Configuration + ): AsyncGenerator { + let pageSize = 30; + if (param.pageLimit !== undefined) { + pageSize = param.pageLimit; + } + param.pageLimit = pageSize; + while (true) { + const requestContext = await this.requestFactory.listDowntimes( + param.currentOnly, + param.include, + param.pageOffset, + param.pageLimit, + options + ); + const responseContext = await this.configuration.httpApi.send( + requestContext + ); + + const response = await this.responseProcessor.listDowntimes( + responseContext + ); + const responseData = response.data; + if (responseData === undefined) { + break; + } + const results = responseData; + for (const item of results) { + yield item; + } + if (results.length < pageSize) { + break; + } + if (param.pageOffset === undefined) { + param.pageOffset = pageSize; + } else { + param.pageOffset = param.pageOffset + pageSize; + } + } + } + /** * Get all active downtimes for the specified monitor. * @param param The request object