Skip to content

Commit 1411b9d

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
Add pagination extension to user list (#1647)
Co-authored-by: ci.datadog-api-spec <[email protected]>
1 parent 89038f0 commit 1411b9d

File tree

7 files changed

+835
-4
lines changed

7 files changed

+835
-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:22.456754",
8-
"spec_repo_commit": "07ee6775"
7+
"regenerated": "2023-09-06 13:01:03.250653",
8+
"spec_repo_commit": "c0d26405"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.5",
12-
"regenerated": "2023-09-06 12:26:22.469339",
13-
"spec_repo_commit": "07ee6775"
12+
"regenerated": "2023-09-06 13:01:03.265196",
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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
List all users returns "OK" response with pagination
3+
"""
4+
5+
from datadog_api_client import ApiClient, Configuration
6+
from datadog_api_client.v2.api.users_api import UsersApi
7+
8+
configuration = Configuration()
9+
with ApiClient(configuration) as api_client:
10+
api_instance = UsersApi(api_client)
11+
items = api_instance.list_users_with_pagination(
12+
page_size=2,
13+
)
14+
for item in items:
15+
print(item)

src/datadog_api_client/v2/api/users_api.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
# Copyright 2019-Present Datadog, Inc.
44
from __future__ import annotations
55

6+
import collections
67
from typing import Any, Dict, Union
78

89
from datadog_api_client.api_client import ApiClient, Endpoint as _Endpoint
910
from datadog_api_client.configuration import Configuration
1011
from datadog_api_client.model_utils import (
12+
set_attribute_from_path,
13+
get_attribute_from_path,
1114
UnsetType,
1215
unset,
1316
)
@@ -16,6 +19,7 @@
1619
from datadog_api_client.v2.model.user_invitation_response import UserInvitationResponse
1720
from datadog_api_client.v2.model.users_response import UsersResponse
1821
from datadog_api_client.v2.model.query_sort_order import QuerySortOrder
22+
from datadog_api_client.v2.model.user import User
1923
from datadog_api_client.v2.model.user_response import UserResponse
2024
from datadog_api_client.v2.model.user_create_request import UserCreateRequest
2125
from datadog_api_client.v2.model.user_update_request import UserUpdateRequest
@@ -419,6 +423,72 @@ def list_users(
419423

420424
return self._list_users_endpoint.call_with_http_info(**kwargs)
421425

426+
def list_users_with_pagination(
427+
self,
428+
*,
429+
page_size: Union[int, UnsetType] = unset,
430+
page_number: Union[int, UnsetType] = unset,
431+
sort: Union[str, UnsetType] = unset,
432+
sort_dir: Union[QuerySortOrder, UnsetType] = unset,
433+
filter: Union[str, UnsetType] = unset,
434+
filter_status: Union[str, UnsetType] = unset,
435+
) -> collections.abc.Iterable[User]:
436+
"""List all users.
437+
438+
Provide a paginated version of :meth:`list_users`, returning all items.
439+
440+
:param page_size: Size for a given page. The maximum allowed value is 100.
441+
:type page_size: int, optional
442+
:param page_number: Specific page number to return.
443+
:type page_number: int, optional
444+
:param sort: User attribute to order results by. Sort order is ascending by default.
445+
Sort order is descending if the field
446+
is prefixed by a negative sign, for example ``sort=-name``. Options: ``name`` ,
447+
``modified_at`` , ``user_count``.
448+
:type sort: str, optional
449+
:param sort_dir: Direction of sort. Options: ``asc`` , ``desc``.
450+
:type sort_dir: QuerySortOrder, optional
451+
:param filter: Filter all users by the given string. Defaults to no filtering.
452+
:type filter: str, optional
453+
:param filter_status: Filter on status attribute.
454+
Comma separated list, with possible values ``Active`` , ``Pending`` , and ``Disabled``.
455+
Defaults to no filtering.
456+
:type filter_status: str, optional
457+
458+
:return: A generator of paginated results.
459+
:rtype: collections.abc.Iterable[User]
460+
"""
461+
kwargs: Dict[str, Any] = {}
462+
if page_size is not unset:
463+
kwargs["page_size"] = page_size
464+
465+
if page_number is not unset:
466+
kwargs["page_number"] = page_number
467+
468+
if sort is not unset:
469+
kwargs["sort"] = sort
470+
471+
if sort_dir is not unset:
472+
kwargs["sort_dir"] = sort_dir
473+
474+
if filter is not unset:
475+
kwargs["filter"] = filter
476+
477+
if filter_status is not unset:
478+
kwargs["filter_status"] = filter_status
479+
480+
local_page_size = get_attribute_from_path(kwargs, "page_size", 10)
481+
endpoint = self._list_users_endpoint
482+
set_attribute_from_path(kwargs, "page_size", local_page_size, endpoint.params_map)
483+
pagination = {
484+
"limit_value": local_page_size,
485+
"results_path": "data",
486+
"page_param": "page_number",
487+
"endpoint": endpoint,
488+
"kwargs": kwargs,
489+
}
490+
return endpoint.call_with_http_info_paginated(pagination)
491+
422492
def send_invitations(
423493
self,
424494
body: UserInvitationsRequest,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2023-09-05T13:14:24.601Z

0 commit comments

Comments
 (0)