1
1
{% include "api_info.j2" %}
2
2
from __future__ import annotations
3
3
4
+ import collections
4
5
from typing import Any, Dict, List, Union
5
6
6
7
from {{ package }}.api_client import ApiClient, Endpoint as _Endpoint
@@ -171,7 +172,7 @@ class {{ classname }}:
171
172
{% - if operation ["x-pagination" ] %}
172
173
{% - set pagination = operation ["x-pagination" ] %}
173
174
174
- def {{ operation.operationId|safe_snake_case }}_with_pagination(self, {% for name , parameter in operation |parameters if parameter .required %} {{name|attribute_name}}, {% endfor %} **kwargs) :
175
+ def {{ operation.operationId|safe_snake_case }}_with_pagination(self, {% for name , parameter in operation |parameters if parameter .required %} {{name|attribute_name}}: {{ get_type_for_parameter(parameter, typing=True) }}, {% endfor %}{% for name , parameter in operation | parameters if not parameter . required %}{% if loop . first %} *, {% endif %} {{name|attribute_name}}: Union[{{ get_type_for_parameter(parameter, typing=True) }}, UnsetType]=unset, {% endfor %} ) -> collections.abc.Iterable[{{ get_type_at_path(operation, pagination.resultsPath) }}] :
175
176
"""{{ operation.summary|indent(8) }}.
176
177
177
178
Provide a paginated version of :meth:`{{ operation.operationId|safe_snake_case }}`, returning all items.
@@ -190,20 +191,26 @@ class {{ classname }}:
190
191
:return: A generator of paginated results.
191
192
:rtype: collections.abc.Iterable[{{ get_type_at_path(operation, pagination.resultsPath) }}]
192
193
"""
193
- {% - for name , parameter in operation |parameters if parameter .required %}
194
+ kwargs: Dict[str, Any] = {}
195
+ {% - for name , parameter in operation |parameters %}
196
+ {% - if not parameter .required %}
197
+ if {{ name|attribute_name }} is not unset:
198
+ kwargs["{{ name|attribute_name }}"] = {{ name|attribute_name }}
199
+ {% - else %}
194
200
kwargs["{{ name|attribute_name }}"] = {{ name|attribute_name }}
201
+ {% - endif %}
195
202
{% endfor %}
196
- page_size = get_attribute_from_path(kwargs, "{{ pagination.limitParam|attribute_path }}", {{ get_default(operation, pagination.limitParam) }})
203
+ local_page_size = get_attribute_from_path(kwargs, "{{ pagination.limitParam|attribute_path }}", {{ get_default(operation, pagination.limitParam) }})
197
204
endpoint = self._{{ operation.operationId|safe_snake_case }}_endpoint
198
- set_attribute_from_path(kwargs, "{{ pagination.limitParam|attribute_path }}", page_size , endpoint.params_map)
205
+ set_attribute_from_path(kwargs, "{{ pagination.limitParam|attribute_path }}", local_page_size , endpoint.params_map)
199
206
while True:
200
207
response = endpoint.call_with_http_info(**kwargs)
201
208
for item in get_attribute_from_path(response, "{{ pagination.resultsPath|attribute_path }}"):
202
209
yield item
203
- if len(get_attribute_from_path(response, "{{ pagination.resultsPath|attribute_path }}")) < page_size :
210
+ if len(get_attribute_from_path(response, "{{ pagination.resultsPath|attribute_path }}")) < local_page_size :
204
211
break
205
212
{% - if pagination .pageOffsetParam %}
206
- set_attribute_from_path(kwargs, "{{ pagination.pageOffsetParam|attribute_path }}", get_attribute_from_path(kwargs, "{{ pagination.pageOffsetParam|attribute_path }}", 0) + page_size , endpoint.params_map)
213
+ set_attribute_from_path(kwargs, "{{ pagination.pageOffsetParam|attribute_path }}", get_attribute_from_path(kwargs, "{{ pagination.pageOffsetParam|attribute_path }}", 0) + local_page_size , endpoint.params_map)
207
214
{% - endif %}
208
215
{% - if pagination .cursorParam %}
209
216
set_attribute_from_path(kwargs, "{{ pagination.cursorParam|attribute_path }}", get_attribute_from_path(response, "{{ pagination.cursorPath }}"), endpoint.params_map)
0 commit comments