Skip to content

Commit b080d18

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

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 13:00:56.343923",
8-
"spec_repo_commit": "c0d26405"
7+
"regenerated": "2023-09-06 14:56:05.719677",
8+
"spec_repo_commit": "5896c0ef"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.5",
12-
"regenerated": "2023-09-06 13:00:56.357598",
13-
"spec_repo_commit": "c0d26405"
12+
"regenerated": "2023-09-06 14:56:05.733078",
13+
"spec_repo_commit": "5896c0ef"
1414
}
1515
}
1616
}

.generator/schemas/v2/openapi.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25989,6 +25989,10 @@ paths:
2598925989
summary: Get all teams
2599025990
tags:
2599125991
- Teams
25992+
x-pagination:
25993+
limitParam: page[size]
25994+
pageParam: page[number]
25995+
resultsPath: data
2599225996
post:
2599325997
description: 'Create a new team.
2599425998

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"2023-09-05T14:20:30.333Z"
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
{
2+
"log": {
3+
"_recordingName": "Teams/Get all teams returns \"OK\" response with pagination",
4+
"creator": {
5+
"comment": "persister:fs",
6+
"name": "Polly.JS",
7+
"version": "6.0.5"
8+
},
9+
"entries": [
10+
{
11+
"_id": "98476bb184a8bacc3c4d9d5339912612",
12+
"_order": 0,
13+
"cache": {},
14+
"request": {
15+
"bodySize": 0,
16+
"cookies": [],
17+
"headers": [
18+
{
19+
"_fromType": "array",
20+
"name": "accept",
21+
"value": "application/json"
22+
}
23+
],
24+
"headersSize": 530,
25+
"httpVersion": "HTTP/1.1",
26+
"method": "GET",
27+
"queryString": [
28+
{
29+
"name": "page",
30+
"value": {
31+
"number": "0",
32+
"size": "2"
33+
}
34+
}
35+
],
36+
"url": "https://api.datadoghq.com/api/v2/team?page%5Bsize%5D=2&page%5Bnumber%5D=0"
37+
},
38+
"response": {
39+
"bodySize": 1528,
40+
"content": {
41+
"mimeType": "application/json",
42+
"size": 1528,
43+
"text": "{\"data\":[{\"type\":\"team\",\"attributes\":{\"created_at\":\"2023-03-22T17:12:07.018313+00:00\",\"user_count\":0,\"description\":null,\"link_count\":0,\"modified_at\":\"2023-03-22T17:12:07.018317+00:00\",\"name\":\"Example Team\",\"summary\":null,\"handle\":\"api-spec-test-team\"},\"relationships\":{\"team_links\":{\"links\":{\"related\":\"/api/v2/team/ac73040e-c8d4-11ed-b2ea-da7ad0900002/links\"}},\"user_team_permissions\":{\"links\":{\"related\":\"/api/v2/team/ac73040e-c8d4-11ed-b2ea-da7ad0900002/permission-settings\"}}},\"id\":\"ac73040e-c8d4-11ed-b2ea-da7ad0900002\"},{\"type\":\"team\",\"attributes\":{\"created_at\":\"2023-08-21T19:49:10.718738+00:00\",\"user_count\":1,\"description\":\"\",\"link_count\":0,\"modified_at\":\"2023-08-21T19:49:10.718744+00:00\",\"name\":\"test-name-12938712938\",\"summary\":null,\"handle\":\"test-handle-12938712938\"},\"relationships\":{\"team_links\":{\"links\":{\"related\":\"/api/v2/team/cc338b02-405b-11ee-835e-da7ad0900002/links\"}},\"user_team_permissions\":{\"links\":{\"related\":\"/api/v2/team/cc338b02-405b-11ee-835e-da7ad0900002/permission-settings\"}}},\"id\":\"cc338b02-405b-11ee-835e-da7ad0900002\"}],\"meta\":{\"pagination\":{\"number\":0,\"first_number\":0,\"prev_number\":0,\"next_number\":1,\"last_number\":1,\"size\":2,\"type\":\"number_size\",\"total\":3}},\"links\":{\"self\":\"https://api.datadoghq.com/api/v2/team?page%5Bsize%5D=2&page%5Bnumber%5D=0\",\"last\":\"https://api.datadoghq.com/api/v2/team?page[number]=1&page[size]=2\",\"next\":\"https://api.datadoghq.com/api/v2/team?page[number]=1&page[size]=2\",\"prev\":null,\"first\":\"https://api.datadoghq.com/api/v2/team?page[number]=0&page[size]=2\"}}\n"
44+
},
45+
"cookies": [],
46+
"headers": [
47+
{
48+
"name": "content-type",
49+
"value": "application/json"
50+
}
51+
],
52+
"headersSize": 654,
53+
"httpVersion": "HTTP/1.1",
54+
"redirectURL": "",
55+
"status": 200,
56+
"statusText": "OK"
57+
},
58+
"startedDateTime": "2023-09-05T14:20:30.342Z",
59+
"time": 505
60+
},
61+
{
62+
"_id": "d64aaa571d976ad41f99706c14c7dad7",
63+
"_order": 0,
64+
"cache": {},
65+
"request": {
66+
"bodySize": 0,
67+
"cookies": [],
68+
"headers": [
69+
{
70+
"_fromType": "array",
71+
"name": "accept",
72+
"value": "application/json"
73+
}
74+
],
75+
"headersSize": 530,
76+
"httpVersion": "HTTP/1.1",
77+
"method": "GET",
78+
"queryString": [
79+
{
80+
"name": "page",
81+
"value": {
82+
"number": "1",
83+
"size": "2"
84+
}
85+
}
86+
],
87+
"url": "https://api.datadoghq.com/api/v2/team?page%5Bsize%5D=2&page%5Bnumber%5D=1"
88+
},
89+
"response": {
90+
"bodySize": 1114,
91+
"content": {
92+
"mimeType": "application/json",
93+
"size": 1114,
94+
"text": "{\"data\":[{\"type\":\"team\",\"relationships\":{\"user_team_permissions\":{\"links\":{\"related\":\"/api/v2/team/ecc8affc-27d6-11ee-b33c-da7ad0900002/permission-settings\"}},\"team_links\":{\"links\":{\"related\":\"/api/v2/team/ecc8affc-27d6-11ee-b33c-da7ad0900002/links\"}}},\"attributes\":{\"link_count\":0,\"handle\":\"tf-testaccteamlinkbasic-local-1689951453\",\"modified_at\":\"2023-07-21T14:57:34.412713+00:00\",\"created_at\":\"2023-07-21T14:57:34.412707+00:00\",\"summary\":\"123\",\"name\":\"tf-testaccteamlinkbasic-local-1689951453\",\"user_count\":0,\"description\":\"123\"},\"id\":\"ecc8affc-27d6-11ee-b33c-da7ad0900002\"}],\"meta\":{\"pagination\":{\"number\":1,\"first_number\":0,\"prev_number\":0,\"next_number\":2,\"last_number\":1,\"size\":2,\"type\":\"number_size\",\"total\":3}},\"links\":{\"self\":\"https://api.datadoghq.com/api/v2/team?page%5Bsize%5D=2&page%5Bnumber%5D=1\",\"last\":\"https://api.datadoghq.com/api/v2/team?page[number]=1&page[size]=2\",\"next\":\"https://api.datadoghq.com/api/v2/team?page[number]=2&page[size]=2\",\"prev\":\"https://api.datadoghq.com/api/v2/team?page[number]=0&page[size]=2\",\"first\":\"https://api.datadoghq.com/api/v2/team?page[number]=0&page[size]=2\"}}\n"
95+
},
96+
"cookies": [],
97+
"headers": [
98+
{
99+
"name": "content-type",
100+
"value": "application/json"
101+
}
102+
],
103+
"headersSize": 654,
104+
"httpVersion": "HTTP/1.1",
105+
"redirectURL": "",
106+
"status": 200,
107+
"statusText": "OK"
108+
},
109+
"startedDateTime": "2023-09-05T14:20:30.855Z",
110+
"time": 483
111+
}
112+
],
113+
"pages": [],
114+
"version": "1.2"
115+
}
116+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Get all teams 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.TeamsApi(configuration);
9+
10+
const params: v2.TeamsApiListTeamsRequest = {
11+
pageSize: 2,
12+
};
13+
14+
(async () => {
15+
try {
16+
for await (const item of apiInstance.listTeamsWithPagination(params)) {
17+
console.log(item);
18+
}
19+
} catch (error) {
20+
console.error(error);
21+
}
22+
})();

features/v2/teams.feature

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,14 @@ Feature: Teams
118118
Then the response status is 200 OK
119119
And the response "data" has item with field "id" with value "{{ dd_team.data.id }}"
120120

121+
@replay-only @skip-validation @team:DataDog/core-app @with-pagination
122+
Scenario: Get all teams returns "OK" response with pagination
123+
Given new "ListTeams" request
124+
And request contains "page[size]" parameter with value 2
125+
When the request with pagination is sent
126+
Then the response status is 200 OK
127+
And the response has 3 items
128+
121129
@team:DataDog/core-app
122130
Scenario: Get links for a team returns "API error response." response
123131
Given new "GetTeamLinks" request

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { APIErrorResponse } from "../models/APIErrorResponse";
2020
import { GetTeamMembershipsSort } from "../models/GetTeamMembershipsSort";
2121
import { ListTeamsInclude } from "../models/ListTeamsInclude";
2222
import { ListTeamsSort } from "../models/ListTeamsSort";
23+
import { Team } from "../models/Team";
2324
import { TeamCreateRequest } from "../models/TeamCreateRequest";
2425
import { TeamLinkCreateRequest } from "../models/TeamLinkCreateRequest";
2526
import { TeamLinkResponse } from "../models/TeamLinkResponse";
@@ -2341,6 +2342,49 @@ export class TeamsApi {
23412342
});
23422343
}
23432344

2345+
/**
2346+
* Provide a paginated version of listTeams returning a generator with all the items.
2347+
*/
2348+
public async *listTeamsWithPagination(
2349+
param: TeamsApiListTeamsRequest = {},
2350+
options?: Configuration
2351+
): AsyncGenerator<Team> {
2352+
let pageSize = 10;
2353+
if (param.pageSize !== undefined) {
2354+
pageSize = param.pageSize;
2355+
}
2356+
param.pageSize = pageSize;
2357+
param.pageNumber = 0;
2358+
while (true) {
2359+
const requestContext = await this.requestFactory.listTeams(
2360+
param.pageNumber,
2361+
param.pageSize,
2362+
param.sort,
2363+
param.include,
2364+
param.filterKeyword,
2365+
param.filterMe,
2366+
options
2367+
);
2368+
const responseContext = await this.configuration.httpApi.send(
2369+
requestContext
2370+
);
2371+
2372+
const response = await this.responseProcessor.listTeams(responseContext);
2373+
const responseData = response.data;
2374+
if (responseData === undefined) {
2375+
break;
2376+
}
2377+
const results = responseData;
2378+
for (const item of results) {
2379+
yield item;
2380+
}
2381+
if (results.length < pageSize) {
2382+
break;
2383+
}
2384+
param.pageNumber = param.pageNumber + 1;
2385+
}
2386+
}
2387+
23442388
/**
23452389
* Update a team using the team's `id`.
23462390
* If the `team_links` relationship is present, the associated links are updated to be in the order they appear in the array, and any existing team links not present are removed.

0 commit comments

Comments
 (0)