@@ -28,8 +28,9 @@ from {{ package }}.model_utils import (
28
28
deserialize_file,
29
29
file_type,
30
30
model_to_dict,
31
- none_type,
32
31
validate_and_convert_types,
32
+ get_attribute_from_path,
33
+ set_attribute_from_path,
33
34
)
34
35
35
36
@@ -335,6 +336,61 @@ class ApiClient:
335
336
check_type,
336
337
)
337
338
339
+ def call_api_paginated(
340
+ self,
341
+ resource_path: str,
342
+ method: str,
343
+ pagination: dict,
344
+ response_type: Optional[Tuple[Any]] = None,
345
+ request_timeout: Optional[Union[int, float, Tuple[Union[int, float], Union[int, float]]]] = None,
346
+ host: Optional[str] = None,
347
+ check_type: Optional[bool] = None,
348
+ ):
349
+ params = pagination["endpoint"].gather_params(pagination["kwargs"])
350
+ while True:
351
+ response = self.call_api(
352
+ resource_path,
353
+ method,
354
+ params["path"],
355
+ params["query"],
356
+ params["header"],
357
+ body=params["body"],
358
+ post_params=params["form"],
359
+ files=params["file"],
360
+ response_type=response_type,
361
+ check_type=check_type,
362
+ return_http_data_only=True,
363
+ preload_content=True,
364
+ request_timeout=request_timeout,
365
+ host=host,
366
+ collection_formats=params["collection_format"],
367
+ )
368
+ for item in get_attribute_from_path(response, pagination["results_path"]):
369
+ yield item
370
+ if len(get_attribute_from_path(response, pagination["results_path"])) < pagination["limit_value"]:
371
+ break
372
+
373
+ params = self._update_paginated_params(pagination, response)
374
+
375
+ def _update_paginated_params(self, pagination, response):
376
+ if "page_offset_param" in pagination:
377
+ set_attribute_from_path(
378
+ pagination["kwargs"],
379
+ pagination["page_offset_param"],
380
+ get_attribute_from_path(pagination["kwargs"], pagination["page_offset_param"], 0)
381
+ + pagination["limit_value"],
382
+ pagination["endpoint"].params_map,
383
+ )
384
+ else:
385
+ set_attribute_from_path(
386
+ pagination["kwargs"],
387
+ pagination["cursor_param"],
388
+ get_attribute_from_path(response, pagination["cursor_path"]),
389
+ pagination["endpoint"].params_map,
390
+ )
391
+
392
+ return pagination["endpoint"].gather_params(pagination["kwargs"])
393
+
338
394
def parameters_to_tuples(self, params, collection_formats) -> List[Tuple[str, Any]]:
339
395
"""Get parameters as list of tuples, formatting collections.
340
396
@@ -550,6 +606,42 @@ class AsyncApiClient(ApiClient):
550
606
return return_data
551
607
return (return_data, response.status_code, response.headers)
552
608
609
+ async def call_api_paginated(
610
+ self,
611
+ resource_path: str,
612
+ method: str,
613
+ pagination: dict,
614
+ response_type: Optional[Tuple[Any]] = None,
615
+ request_timeout: Optional[Union[int, float, Tuple[Union[int, float], Union[int, float]]]] = None,
616
+ host: Optional[str] = None,
617
+ check_type: Optional[bool] = None,
618
+ ):
619
+ params = pagination["endpoint"].get_pagination_params(pagination["kwargs"])
620
+ while True:
621
+ response = await self.call_api(
622
+ resource_path,
623
+ method,
624
+ params["path"],
625
+ params["query"],
626
+ params["header"],
627
+ body=params["body"],
628
+ post_params=params["form"],
629
+ files=params["file"],
630
+ response_type=response_type,
631
+ check_type=check_type,
632
+ return_http_data_only=True,
633
+ preload_content=True,
634
+ request_timeout=request_timeout,
635
+ host=host,
636
+ collection_formats=params["collection_format"],
637
+ )
638
+ for item in get_attribute_from_path(response, pagination["results_path"]):
639
+ yield item
640
+ if len(get_attribute_from_path(response, pagination["results_path"])) < pagination["limit_value"]:
641
+ break
642
+
643
+ params = self._update_paginated_params(pagination, response)
644
+
553
645
554
646
class Endpoint:
555
647
def __init__(
@@ -617,7 +709,7 @@ class Endpoint:
617
709
)
618
710
kwargs[key] = fixed_val
619
711
620
- def _gather_params (self, kwargs):
712
+ def gather_params (self, kwargs):
621
713
params = {"body": None, "collection_format": {}, "file": {}, "form": [], "header": {}, "path": {}, "query": []}
622
714
623
715
for param_name, param_value in kwargs.items():
@@ -645,10 +737,20 @@ class Endpoint:
645
737
if collection_format:
646
738
params["collection_format"][base_name] = collection_format
647
739
648
- return params
740
+ accept_headers_list = self.headers_map["accept"]
741
+ if accept_headers_list:
742
+ params["header"]["Accept"] = self.api_client.select_header_accept(accept_headers_list)
649
743
650
- def call_with_http_info(self, **kwargs):
744
+ content_type_headers_list = self.headers_map.get("content_type")
745
+ if content_type_headers_list:
746
+ header_list = self.api_client.select_header_content_type(content_type_headers_list)
747
+ params["header"]["Content-Type"] = header_list
748
+
749
+ self.update_params_for_auth(params["header"], params["query"])
651
750
751
+ return params
752
+
753
+ def _validate_and_get_host(self, kwargs):
652
754
is_unstable = self.api_client.configuration.unstable_operations.get(
653
755
"{}.{}".format(self.settings["version"], self.settings["operation_id"])
654
756
)
@@ -699,18 +801,12 @@ class Endpoint:
699
801
700
802
self._validate_inputs(kwargs)
701
803
702
- params = self._gather_params(kwargs)
804
+ return host
703
805
704
- accept_headers_list = self.headers_map["accept"]
705
- if accept_headers_list:
706
- params["header"]["Accept"] = self.api_client.select_header_accept(accept_headers_list)
707
-
708
- content_type_headers_list = self.headers_map.get("content_type")
709
- if content_type_headers_list:
710
- header_list = self.api_client.select_header_content_type(content_type_headers_list)
711
- params["header"]["Content-Type"] = header_list
806
+ def call_with_http_info(self, **kwargs):
807
+ host = self._validate_and_get_host(kwargs)
712
808
713
- self.update_params_for_auth(params["header"], params["query"] )
809
+ params = self.gather_params(kwargs )
714
810
715
811
return self.api_client.call_api(
716
812
self.settings["endpoint_path"],
@@ -730,6 +826,19 @@ class Endpoint:
730
826
collection_formats=params["collection_format"],
731
827
)
732
828
829
+ def call_with_http_info_paginated(self, pagination):
830
+ host = self._validate_and_get_host(pagination["kwargs"])
831
+
832
+ return self.api_client.call_api_paginated(
833
+ self.settings["endpoint_path"],
834
+ self.settings["http_method"],
835
+ response_type=self.settings["response_type"],
836
+ check_type=self.api_client.configuration.check_return_type,
837
+ request_timeout=self.api_client.configuration.request_timeout,
838
+ host=host,
839
+ pagination=pagination
840
+ )
841
+
733
842
def update_params_for_auth(self, headers, queries) -> None:
734
843
"""Updates header and query params based on authentication setting.
735
844
0 commit comments