Skip to content
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

Add pagination helper for team memberships #1502

Merged
Merged
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": "2024-01-26 15:59:28.351864",
"spec_repo_commit": "28baf464"
"regenerated": "2024-01-26 20:56:59.043844",
"spec_repo_commit": "a1db94fd"
},
"v2": {
"apigentools_version": "1.6.6",
"regenerated": "2024-01-26 15:59:28.366791",
"spec_repo_commit": "28baf464"
"regenerated": "2024-01-26 20:56:59.077077",
"spec_repo_commit": "a1db94fd"
}
}
}
4 changes: 4 additions & 0 deletions .generator/schemas/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31989,6 +31989,10 @@ paths:
summary: Get team memberships
tags:
- Teams
x-pagination:
limitParam: page[size]
pageParam: page[number]
resultsPath: data
post:
description: Add a user to a team.
operationId: CreateTeamMembership
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"2024-01-26T20:53:20.323Z"
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{
"log": {
"_recordingName": "Teams/Get team memberships returns \"Represents a user's association to a team\" response with pagination",
"creator": {
"comment": "persister:fs",
"name": "Polly.JS",
"version": "6.0.5"
},
"entries": [
{
"_id": "3c8d7929145ffc09b9363558091bd3a3",
"_order": 0,
"cache": {},
"request": {
"bodySize": 0,
"cookies": [],
"headers": [
{
"_fromType": "array",
"name": "accept",
"value": "application/json"
}
],
"headersSize": 588,
"httpVersion": "HTTP/1.1",
"method": "GET",
"queryString": [
{
"name": "page",
"value": {
"number": "0",
"size": "2"
}
}
],
"url": "https://api.datadoghq.com/api/v2/team/2e06bf2c-193b-41d4-b3c2-afccc080458f/memberships?page%5Bsize%5D=2&page%5Bnumber%5D=0"
},
"response": {
"bodySize": 2081,
"content": {
"mimeType": "application/json",
"size": 2081,
"text": "{\"data\":[{\"type\":\"team_memberships\",\"id\":\"TeamMembership-2e06bf2c-193b-41d4-b3c2-afccc080458f-3736692\",\"attributes\":{\"role\":null,\"provisioned_by\":null,\"provisioned_by_id\":\"6018c832-80a7-11ea-93dd-43183212bc7a\"},\"relationships\":{\"user\":{\"data\":{\"type\":\"users\",\"id\":\"03b4bfc0-98b9-11ec-842d-da7ad0900002\"}}}},{\"type\":\"team_memberships\",\"id\":\"TeamMembership-2e06bf2c-193b-41d4-b3c2-afccc080458f-4055096\",\"attributes\":{\"role\":null,\"provisioned_by\":null,\"provisioned_by_id\":\"6018c832-80a7-11ea-93dd-43183212bc7a\"},\"relationships\":{\"user\":{\"data\":{\"type\":\"users\",\"id\":\"170a64a1-d9c6-11ec-af01-da7ad0900002\"}}}}],\"included\":[{\"type\":\"users\",\"id\":\"03b4bfc0-98b9-11ec-842d-da7ad0900002\",\"attributes\":{\"name\":\"Datadog API Client Python\",\"handle\":\"example-create_a_user_returns_ok_response_1646068093@datadoghq.com\",\"email\":\"example-create_a_user_returns_ok_response_1646068093@datadoghq.com\",\"icon\":\"https://secure.gravatar.com/avatar/27fb863ad335246b65fe4989f1686f35?s=48&d=retro\",\"disabled\":false,\"service_account\":false}},{\"type\":\"users\",\"id\":\"170a64a1-d9c6-11ec-af01-da7ad0900002\",\"attributes\":{\"name\":\"Datadog API Client Python\",\"handle\":\"example-create_a_user_returns_ok_response_1653220535@datadoghq.com\",\"email\":\"example-create_a_user_returns_ok_response_1653220535@datadoghq.com\",\"icon\":\"https://secure.gravatar.com/avatar/c5256983bba478dfd35e83bbb73621cc?s=48&d=retro\",\"disabled\":false,\"service_account\":false}}],\"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/2e06bf2c-193b-41d4-b3c2-afccc080458f/memberships?page%5Bsize%5D=2&page%5Bnumber%5D=0\",\"last\":\"https://api.datadoghq.com/api/v2/team/2e06bf2c-193b-41d4-b3c2-afccc080458f/memberships?page[number]=1&page[size]=2\",\"next\":\"https://api.datadoghq.com/api/v2/team/2e06bf2c-193b-41d4-b3c2-afccc080458f/memberships?page[number]=1&page[size]=2\",\"prev\":null,\"first\":\"https://api.datadoghq.com/api/v2/team/2e06bf2c-193b-41d4-b3c2-afccc080458f/memberships?page[number]=0&page[size]=2\"}}\n"
},
"cookies": [],
"headers": [
{
"name": "content-type",
"value": "application/json"
}
],
"headersSize": 654,
"httpVersion": "HTTP/1.1",
"redirectURL": "",
"status": 200,
"statusText": "OK"
},
"startedDateTime": "2024-01-26T20:53:20.334Z",
"time": 152
},
{
"_id": "a72c08baf10659c0e4ff4ce823d38238",
"_order": 0,
"cache": {},
"request": {
"bodySize": 0,
"cookies": [],
"headers": [
{
"_fromType": "array",
"name": "accept",
"value": "application/json"
}
],
"headersSize": 588,
"httpVersion": "HTTP/1.1",
"method": "GET",
"queryString": [
{
"name": "page",
"value": {
"number": "1",
"size": "2"
}
}
],
"url": "https://api.datadoghq.com/api/v2/team/2e06bf2c-193b-41d4-b3c2-afccc080458f/memberships?page%5Bsize%5D=2&page%5Bnumber%5D=1"
},
"response": {
"bodySize": 1379,
"content": {
"mimeType": "application/json",
"size": 1379,
"text": "{\"data\":[{\"type\":\"team_memberships\",\"id\":\"TeamMembership-2e06bf2c-193b-41d4-b3c2-afccc080458f-1445416\",\"attributes\":{\"role\":null,\"provisioned_by\":null,\"provisioned_by_id\":\"6018c832-80a7-11ea-93dd-43183212bc7a\"},\"relationships\":{\"user\":{\"data\":{\"type\":\"users\",\"id\":\"3ad549bf-eba0-11e9-a77a-0705486660d0\"}}}}],\"included\":[{\"type\":\"users\",\"id\":\"3ad549bf-eba0-11e9-a77a-0705486660d0\",\"attributes\":{\"name\":null,\"handle\":\"[email protected]\",\"email\":\"[email protected]\",\"icon\":\"https://secure.gravatar.com/avatar/28a16dfe36e73b60c1d55872cb0f1172?s=48&d=retro\",\"disabled\":false,\"service_account\":false}}],\"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/2e06bf2c-193b-41d4-b3c2-afccc080458f/memberships?page%5Bsize%5D=2&page%5Bnumber%5D=1\",\"last\":\"https://api.datadoghq.com/api/v2/team/2e06bf2c-193b-41d4-b3c2-afccc080458f/memberships?page[number]=1&page[size]=2\",\"next\":\"https://api.datadoghq.com/api/v2/team/2e06bf2c-193b-41d4-b3c2-afccc080458f/memberships?page[number]=2&page[size]=2\",\"prev\":\"https://api.datadoghq.com/api/v2/team/2e06bf2c-193b-41d4-b3c2-afccc080458f/memberships?page[number]=0&page[size]=2\",\"first\":\"https://api.datadoghq.com/api/v2/team/2e06bf2c-193b-41d4-b3c2-afccc080458f/memberships?page[number]=0&page[size]=2\"}}\n"
},
"cookies": [],
"headers": [
{
"name": "content-type",
"value": "application/json"
}
],
"headersSize": 654,
"httpVersion": "HTTP/1.1",
"redirectURL": "",
"status": 200,
"statusText": "OK"
},
"startedDateTime": "2024-01-26T20:53:20.515Z",
"time": 114
}
],
"pages": [],
"version": "1.2"
}
}
25 changes: 25 additions & 0 deletions examples/v2/teams/GetTeamMemberships_3799131168.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Get team memberships returns "Represents a user's association to a team" response with pagination
*/

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

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

const params: v2.TeamsApiGetTeamMembershipsRequest = {
teamId: "2e06bf2c-193b-41d4-b3c2-afccc080458f",
pageSize: 2,
};

(async () => {
try {
for await (const item of apiInstance.getTeamMembershipsWithPagination(
params
)) {
console.log(item);
}
} catch (error) {
console.error(error);
}
})();
9 changes: 9 additions & 0 deletions features/v2/teams.feature
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,15 @@ Feature: Teams
When the request is sent
Then the response status is 200 Represents a user's association to a team

@replay-only @skip-validation @team:DataDog/core-app @with-pagination
Scenario: Get team memberships returns "Represents a user's association to a team" response with pagination
Given new "GetTeamMemberships" request
And request contains "team_id" parameter with value "2e06bf2c-193b-41d4-b3c2-afccc080458f"
And request contains "page[size]" parameter with value 2
When the request with pagination is sent
Then the response status is 200 OK
And the response has 3 items

@generated @skip @team:DataDog/core-app
Scenario: Get user memberships returns "API error response." response
Given new "GetUserMemberships" request
Expand Down
45 changes: 45 additions & 0 deletions packages/datadog-api-client-v2/apis/TeamsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { TeamResponse } from "../models/TeamResponse";
import { TeamsField } from "../models/TeamsField";
import { TeamsResponse } from "../models/TeamsResponse";
import { TeamUpdateRequest } from "../models/TeamUpdateRequest";
import { UserTeam } from "../models/UserTeam";
import { UserTeamRequest } from "../models/UserTeamRequest";
import { UserTeamResponse } from "../models/UserTeamResponse";
import { UserTeamsResponse } from "../models/UserTeamsResponse";
Expand Down Expand Up @@ -2335,6 +2336,50 @@ export class TeamsApi {
});
}

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

const response = await this.responseProcessor.getTeamMemberships(
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 all permission settings for a given team.
* @param param The request object
Expand Down
Loading