Skip to content

Commit 158e1e0

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add pagination extension to user list (#1307)
Co-authored-by: ci.datadog-api-spec <[email protected]>
1 parent ffa21b7 commit 158e1e0

File tree

7 files changed

+199
-4
lines changed

7 files changed

+199
-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 12:26:36.154836",
8-
"spec_repo_commit": "07ee6775"
7+
"regenerated": "2023-09-06 13:00:56.343923",
8+
"spec_repo_commit": "c0d26405"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.5",
12-
"regenerated": "2023-09-06 12:26:36.174283",
13-
"spec_repo_commit": "07ee6775"
12+
"regenerated": "2023-09-06 13:00:56.357598",
13+
"spec_repo_commit": "c0d26405"
1414
}
1515
}
1616
}

.generator/schemas/v2/openapi.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27459,6 +27459,10 @@ paths:
2745927459
tags:
2746027460
- Users
2746127461
x-codegen-request-body-name: body
27462+
x-pagination:
27463+
limitParam: page[size]
27464+
pageParam: page[number]
27465+
resultsPath: data
2746227466
post:
2746327467
description: Create a user for your organization.
2746427468
operationId: CreateUser
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"2023-09-05T13:14:24.601Z"

cassettes/v2/Users_112472755/List-all-users-returns-OK-response-with-pagination_3247448340/recording.har

Lines changed: 116 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* List all users 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.UsersApi(configuration);
9+
10+
const params: v2.UsersApiListUsersRequest = {
11+
pageSize: 2,
12+
};
13+
14+
(async () => {
15+
try {
16+
for await (const item of apiInstance.listUsersWithPagination(params)) {
17+
console.log(item);
18+
}
19+
} catch (error) {
20+
console.error(error);
21+
}
22+
})();

features/v2/users.feature

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,14 @@ Feature: Users
129129
And the response "meta.page.total_filtered_count" is equal to 1
130130
And the response "data[0].attributes.email" has the same value as "user.data.attributes.email"
131131

132+
@replay-only @skip-validation @team:DataDog/team-aaa-identity @with-pagination
133+
Scenario: List all users returns "OK" response with pagination
134+
Given new "ListUsers" request
135+
And request contains "page[size]" parameter with value 2
136+
When the request with pagination is sent
137+
Then the response status is 200 OK
138+
And the response has 3 items
139+
132140
@generated @skip @team:DataDog/team-aaa-identity
133141
Scenario: Send invitation emails returns "Bad Request" response
134142
Given new "SendInvitations" request

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { ApiException } from "../../datadog-api-client-common/exception";
1919
import { APIErrorResponse } from "../models/APIErrorResponse";
2020
import { PermissionsResponse } from "../models/PermissionsResponse";
2121
import { QuerySortOrder } from "../models/QuerySortOrder";
22+
import { User } from "../models/User";
2223
import { UserCreateRequest } from "../models/UserCreateRequest";
2324
import { UserInvitationResponse } from "../models/UserInvitationResponse";
2425
import { UserInvitationsRequest } from "../models/UserInvitationsRequest";
@@ -1229,6 +1230,49 @@ export class UsersApi {
12291230
});
12301231
}
12311232

1233+
/**
1234+
* Provide a paginated version of listUsers returning a generator with all the items.
1235+
*/
1236+
public async *listUsersWithPagination(
1237+
param: UsersApiListUsersRequest = {},
1238+
options?: Configuration
1239+
): AsyncGenerator<User> {
1240+
let pageSize = 10;
1241+
if (param.pageSize !== undefined) {
1242+
pageSize = param.pageSize;
1243+
}
1244+
param.pageSize = pageSize;
1245+
param.pageNumber = 0;
1246+
while (true) {
1247+
const requestContext = await this.requestFactory.listUsers(
1248+
param.pageSize,
1249+
param.pageNumber,
1250+
param.sort,
1251+
param.sortDir,
1252+
param.filter,
1253+
param.filterStatus,
1254+
options
1255+
);
1256+
const responseContext = await this.configuration.httpApi.send(
1257+
requestContext
1258+
);
1259+
1260+
const response = await this.responseProcessor.listUsers(responseContext);
1261+
const responseData = response.data;
1262+
if (responseData === undefined) {
1263+
break;
1264+
}
1265+
const results = responseData;
1266+
for (const item of results) {
1267+
yield item;
1268+
}
1269+
if (results.length < pageSize) {
1270+
break;
1271+
}
1272+
param.pageNumber = param.pageNumber + 1;
1273+
}
1274+
}
1275+
12321276
/**
12331277
* Sends emails to one or more users inviting them to join the organization.
12341278
* @param param The request object

0 commit comments

Comments
 (0)