Skip to content

Add pagination method for NDM ListDevices. #2211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .apigentools-info
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"spec_versions": {
"v1": {
"apigentools_version": "1.6.6",
"regenerated": "2025-05-02 04:31:15.271278",
"spec_repo_commit": "272cce39"
"regenerated": "2025-05-02 20:46:11.533483",
"spec_repo_commit": "7e023f1d"
},
"v2": {
"apigentools_version": "1.6.6",
"regenerated": "2025-05-02 04:31:15.291066",
"spec_repo_commit": "272cce39"
"regenerated": "2025-05-02 20:46:11.549212",
"spec_repo_commit": "7e023f1d"
}
}
}
22 changes: 6 additions & 16 deletions .generator/schemas/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50567,22 +50567,8 @@ paths:
description: Get the list of devices.
operationId: ListDevices
parameters:
- description: The page number to fetch.
example: 0
in: query
name: page[number]
required: false
schema:
format: int64
type: integer
- description: The number of devices to return per page.
example: 10
in: query
name: page[size]
required: false
schema:
format: int64
type: integer
- $ref: '#/components/parameters/PageSize'
- $ref: '#/components/parameters/PageNumber'
- description: The field to sort the devices by.
example: status
in: query
Expand Down Expand Up @@ -50613,6 +50599,10 @@ paths:
summary: Get the list of devices
tags:
- Network Device Monitoring
x-pagination:
limitParam: page[size]
pageParam: page[number]
resultsPath: data
/api/v2/ndm/devices/{device_id}:
get:
description: Get the device details.
Expand Down
2 changes: 1 addition & 1 deletion examples/v2/network-device-monitoring/ListDevices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const configuration = client.createConfiguration();
const apiInstance = new v2.NetworkDeviceMonitoringApi(configuration);

const params: v2.NetworkDeviceMonitoringApiListDevicesRequest = {
pageNumber: 0,
pageSize: 1,
pageNumber: 0,
filterTag: "device_namespace:default",
};

Expand Down
18 changes: 18 additions & 0 deletions examples/v2/network-device-monitoring/ListDevices_2712868412.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Get the list of devices returns "OK" response with pagination
*/

import { client, v2 } from "@datadog/datadog-api-client";

const configuration = client.createConfiguration();
const apiInstance = new v2.NetworkDeviceMonitoringApi(configuration);

(async () => {
try {
for await (const item of apiInstance.listDevicesWithPagination()) {
console.log(item);
}
} catch (error) {
console.error(error);
}
})();
4 changes: 2 additions & 2 deletions features/support/scenarios_model_mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5714,11 +5714,11 @@ export const ScenariosModelMappings: {[key: string]: {[key: string]: any}} = {
"operationResponseType": "MonitorConfigPolicyResponse",
},
"v2.ListDevices": {
"pageNumber": {
"pageSize": {
"type": "number",
"format": "int64",
},
"pageSize": {
"pageNumber": {
"type": "number",
"format": "int64",
},
Expand Down
6 changes: 6 additions & 0 deletions features/v2/network_device_monitoring.feature
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ Feature: Network Device Monitoring
And the response "data[0].attributes.interface_statuses.down" is equal to 13
And the response "meta.page.total_filtered_count" is equal to 1

@generated @skip @team:DataDog/network-device-monitoring @with-pagination
Scenario: Get the list of devices returns "OK" response with pagination
Given new "ListDevices" request
When the request with pagination is sent
Then the response status is 200 OK

@replay-only @team:DataDog/network-device-monitoring
Scenario: Get the list of interfaces of the device returns "OK" response
Given new "GetInterfaces" request
Expand Down
68 changes: 56 additions & 12 deletions packages/datadog-api-client-v2/apis/NetworkDeviceMonitoringApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { ObjectSerializer } from "../models/ObjectSerializer";
import { ApiException } from "../../datadog-api-client-common/exception";

import { APIErrorResponse } from "../models/APIErrorResponse";
import { DevicesListData } from "../models/DevicesListData";
import { GetDeviceResponse } from "../models/GetDeviceResponse";
import { GetInterfacesResponse } from "../models/GetInterfacesResponse";
import { ListDevicesResponse } from "../models/ListDevicesResponse";
Expand Down Expand Up @@ -104,8 +105,8 @@ export class NetworkDeviceMonitoringApiRequestFactory extends BaseAPIRequestFact
}

public async listDevices(
pageNumber?: number,
pageSize?: number,
pageNumber?: number,
sort?: string,
filterTag?: string,
_options?: Configuration
Expand All @@ -123,17 +124,17 @@ export class NetworkDeviceMonitoringApiRequestFactory extends BaseAPIRequestFact
requestContext.setHttpConfig(_config.httpConfig);

// Query Params
if (pageNumber !== undefined) {
if (pageSize !== undefined) {
requestContext.setQueryParam(
"page[number]",
ObjectSerializer.serialize(pageNumber, "number", "int64"),
"page[size]",
ObjectSerializer.serialize(pageSize, "number", "int64"),
""
);
}
if (pageSize !== undefined) {
if (pageNumber !== undefined) {
requestContext.setQueryParam(
"page[size]",
ObjectSerializer.serialize(pageSize, "number", "int64"),
"page[number]",
ObjectSerializer.serialize(pageNumber, "number", "int64"),
""
);
}
Expand Down Expand Up @@ -576,15 +577,15 @@ export interface NetworkDeviceMonitoringApiGetInterfacesRequest {

export interface NetworkDeviceMonitoringApiListDevicesRequest {
/**
* The page number to fetch.
* Size for a given page. The maximum allowed value is 100.
* @type number
*/
pageNumber?: number;
pageSize?: number;
/**
* The number of devices to return per page.
* Specific page number to return.
* @type number
*/
pageSize?: number;
pageNumber?: number;
/**
* The field to sort the devices by.
* @type string
Expand Down Expand Up @@ -687,8 +688,8 @@ export class NetworkDeviceMonitoringApi {
options?: Configuration
): Promise<ListDevicesResponse> {
const requestContextPromise = this.requestFactory.listDevices(
param.pageNumber,
param.pageSize,
param.pageNumber,
param.sort,
param.filterTag,
options
Expand All @@ -702,6 +703,49 @@ export class NetworkDeviceMonitoringApi {
});
}

/**
* Provide a paginated version of listDevices returning a generator with all the items.
*/
public async *listDevicesWithPagination(
param: NetworkDeviceMonitoringApiListDevicesRequest = {},
options?: Configuration
): AsyncGenerator<DevicesListData> {
let pageSize = 10;
if (param.pageSize !== undefined) {
pageSize = param.pageSize;
}
param.pageSize = pageSize;
param.pageNumber = 0;
while (true) {
const requestContext = await this.requestFactory.listDevices(
param.pageSize,
param.pageNumber,
param.sort,
param.filterTag,
options
);
const responseContext = await this.configuration.httpApi.send(
requestContext
);

const response = await this.responseProcessor.listDevices(
responseContext
);
const responseData = response.data;
if (responseData === undefined) {
break;
}
const results = responseData;
for (const item of results) {
yield item;
}
if (results.length < pageSize) {
break;
}
param.pageNumber = param.pageNumber + 1;
}
}

/**
* Get the list of tags for a device.
* @param param The request object
Expand Down
Loading