Skip to content

Commit 48bfa98

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
and
ci.datadog-api-spec
authored
Add pagination method for NDM ListDevices. (#2211)
Co-authored-by: ci.datadog-api-spec <[email protected]>
1 parent 85eebd5 commit 48bfa98

File tree

7 files changed

+93
-35
lines changed

7 files changed

+93
-35
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.6",
7-
"regenerated": "2025-05-06 19:22:00.159258",
8-
"spec_repo_commit": "1faa96a2"
7+
"regenerated": "2025-05-07 17:07:33.388538",
8+
"spec_repo_commit": "a1235a0d"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.6",
12-
"regenerated": "2025-05-06 19:22:00.175685",
13-
"spec_repo_commit": "1faa96a2"
12+
"regenerated": "2025-05-07 17:07:33.406105",
13+
"spec_repo_commit": "a1235a0d"
1414
}
1515
}
1616
}

.generator/schemas/v2/openapi.yaml

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50925,22 +50925,8 @@ paths:
5092550925
description: Get the list of devices.
5092650926
operationId: ListDevices
5092750927
parameters:
50928-
- description: The page number to fetch.
50929-
example: 0
50930-
in: query
50931-
name: page[number]
50932-
required: false
50933-
schema:
50934-
format: int64
50935-
type: integer
50936-
- description: The number of devices to return per page.
50937-
example: 10
50938-
in: query
50939-
name: page[size]
50940-
required: false
50941-
schema:
50942-
format: int64
50943-
type: integer
50928+
- $ref: '#/components/parameters/PageSize'
50929+
- $ref: '#/components/parameters/PageNumber'
5094450930
- description: The field to sort the devices by.
5094550931
example: status
5094650932
in: query
@@ -50971,6 +50957,10 @@ paths:
5097150957
summary: Get the list of devices
5097250958
tags:
5097350959
- Network Device Monitoring
50960+
x-pagination:
50961+
limitParam: page[size]
50962+
pageParam: page[number]
50963+
resultsPath: data
5097450964
/api/v2/ndm/devices/{device_id}:
5097550965
get:
5097650966
description: Get the device details.

examples/v2/network-device-monitoring/ListDevices.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ const configuration = client.createConfiguration();
88
const apiInstance = new v2.NetworkDeviceMonitoringApi(configuration);
99

1010
const params: v2.NetworkDeviceMonitoringApiListDevicesRequest = {
11-
pageNumber: 0,
1211
pageSize: 1,
12+
pageNumber: 0,
1313
filterTag: "device_namespace:default",
1414
};
1515

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Get the list of devices returns "OK" response with pagination
3+
*/
4+
5+
import { client, v2 } from "@datadog/datadog-api-client";
6+
7+
const configuration = client.createConfiguration();
8+
const apiInstance = new v2.NetworkDeviceMonitoringApi(configuration);
9+
10+
(async () => {
11+
try {
12+
for await (const item of apiInstance.listDevicesWithPagination()) {
13+
console.log(item);
14+
}
15+
} catch (error) {
16+
console.error(error);
17+
}
18+
})();

features/support/scenarios_model_mapping.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5714,11 +5714,11 @@ export const ScenariosModelMappings: {[key: string]: {[key: string]: any}} = {
57145714
"operationResponseType": "MonitorConfigPolicyResponse",
57155715
},
57165716
"v2.ListDevices": {
5717-
"pageNumber": {
5717+
"pageSize": {
57185718
"type": "number",
57195719
"format": "int64",
57205720
},
5721-
"pageSize": {
5721+
"pageNumber": {
57225722
"type": "number",
57235723
"format": "int64",
57245724
},

features/v2/network_device_monitoring.feature

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ Feature: Network Device Monitoring
7575
And the response "data[0].attributes.interface_statuses.down" is equal to 13
7676
And the response "meta.page.total_filtered_count" is equal to 1
7777

78+
@generated @skip @team:DataDog/network-device-monitoring @with-pagination
79+
Scenario: Get the list of devices returns "OK" response with pagination
80+
Given new "ListDevices" request
81+
When the request with pagination is sent
82+
Then the response status is 200 OK
83+
7884
@replay-only @team:DataDog/network-device-monitoring
7985
Scenario: Get the list of interfaces of the device returns "OK" response
8086
Given new "GetInterfaces" request

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

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { ObjectSerializer } from "../models/ObjectSerializer";
1717
import { ApiException } from "../../datadog-api-client-common/exception";
1818

1919
import { APIErrorResponse } from "../models/APIErrorResponse";
20+
import { DevicesListData } from "../models/DevicesListData";
2021
import { GetDeviceResponse } from "../models/GetDeviceResponse";
2122
import { GetInterfacesResponse } from "../models/GetInterfacesResponse";
2223
import { ListDevicesResponse } from "../models/ListDevicesResponse";
@@ -104,8 +105,8 @@ export class NetworkDeviceMonitoringApiRequestFactory extends BaseAPIRequestFact
104105
}
105106

106107
public async listDevices(
107-
pageNumber?: number,
108108
pageSize?: number,
109+
pageNumber?: number,
109110
sort?: string,
110111
filterTag?: string,
111112
_options?: Configuration
@@ -123,17 +124,17 @@ export class NetworkDeviceMonitoringApiRequestFactory extends BaseAPIRequestFact
123124
requestContext.setHttpConfig(_config.httpConfig);
124125

125126
// Query Params
126-
if (pageNumber !== undefined) {
127+
if (pageSize !== undefined) {
127128
requestContext.setQueryParam(
128-
"page[number]",
129-
ObjectSerializer.serialize(pageNumber, "number", "int64"),
129+
"page[size]",
130+
ObjectSerializer.serialize(pageSize, "number", "int64"),
130131
""
131132
);
132133
}
133-
if (pageSize !== undefined) {
134+
if (pageNumber !== undefined) {
134135
requestContext.setQueryParam(
135-
"page[size]",
136-
ObjectSerializer.serialize(pageSize, "number", "int64"),
136+
"page[number]",
137+
ObjectSerializer.serialize(pageNumber, "number", "int64"),
137138
""
138139
);
139140
}
@@ -576,15 +577,15 @@ export interface NetworkDeviceMonitoringApiGetInterfacesRequest {
576577

577578
export interface NetworkDeviceMonitoringApiListDevicesRequest {
578579
/**
579-
* The page number to fetch.
580+
* Size for a given page. The maximum allowed value is 100.
580581
* @type number
581582
*/
582-
pageNumber?: number;
583+
pageSize?: number;
583584
/**
584-
* The number of devices to return per page.
585+
* Specific page number to return.
585586
* @type number
586587
*/
587-
pageSize?: number;
588+
pageNumber?: number;
588589
/**
589590
* The field to sort the devices by.
590591
* @type string
@@ -687,8 +688,8 @@ export class NetworkDeviceMonitoringApi {
687688
options?: Configuration
688689
): Promise<ListDevicesResponse> {
689690
const requestContextPromise = this.requestFactory.listDevices(
690-
param.pageNumber,
691691
param.pageSize,
692+
param.pageNumber,
692693
param.sort,
693694
param.filterTag,
694695
options
@@ -702,6 +703,49 @@ export class NetworkDeviceMonitoringApi {
702703
});
703704
}
704705

706+
/**
707+
* Provide a paginated version of listDevices returning a generator with all the items.
708+
*/
709+
public async *listDevicesWithPagination(
710+
param: NetworkDeviceMonitoringApiListDevicesRequest = {},
711+
options?: Configuration
712+
): AsyncGenerator<DevicesListData> {
713+
let pageSize = 10;
714+
if (param.pageSize !== undefined) {
715+
pageSize = param.pageSize;
716+
}
717+
param.pageSize = pageSize;
718+
param.pageNumber = 0;
719+
while (true) {
720+
const requestContext = await this.requestFactory.listDevices(
721+
param.pageSize,
722+
param.pageNumber,
723+
param.sort,
724+
param.filterTag,
725+
options
726+
);
727+
const responseContext = await this.configuration.httpApi.send(
728+
requestContext
729+
);
730+
731+
const response = await this.responseProcessor.listDevices(
732+
responseContext
733+
);
734+
const responseData = response.data;
735+
if (responseData === undefined) {
736+
break;
737+
}
738+
const results = responseData;
739+
for (const item of results) {
740+
yield item;
741+
}
742+
if (results.length < pageSize) {
743+
break;
744+
}
745+
param.pageNumber = param.pageNumber + 1;
746+
}
747+
}
748+
705749
/**
706750
* Get the list of tags for a device.
707751
* @param param The request object

0 commit comments

Comments
 (0)