Skip to content

Commit 74564ab

Browse files
authored
Merge pull request #72 from dlt-hub/fix/fix_paginator_rendering
correct behavior for paginators with unknown total_path
2 parents 6535f9e + b72daa0 commit 74564ab

File tree

10 files changed

+15
-3
lines changed

10 files changed

+15
-3
lines changed

dlt_openapi/detector/default/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,9 @@ def detect_pagination(self, endpoint: Endpoint) -> Optional[Pagination]:
400400
# 20 should be safe for most APIs
401401
limit_initial = to_int(limit_param.maximum) if limit_param.maximum else to_int(limit_param.default)
402402
total_prop = (
403-
response_schema.nested_properties.find_property(RE_TOTAL_PROPERTY, require_type="integer")
403+
response_schema.nested_properties.find_property(
404+
RE_TOTAL_PROPERTY, require_type="integer", allow_unknown_types=True
405+
)
404406
if response_schema
405407
else None
406408
)
@@ -415,6 +417,7 @@ def detect_pagination(self, endpoint: Endpoint) -> Optional[Pagination]:
415417
if total_prop:
416418
pagination_config["total_path"] = total_prop.json_path
417419
else:
420+
pagination_config["total_path"] = ""
418421
pagination_config["maximum_offset"] = DEFAULT_MAXIMUM_PAGINATOR_OFFSET
419422

420423
return Pagination(
@@ -440,6 +443,7 @@ def detect_pagination(self, endpoint: Endpoint) -> Optional[Pagination]:
440443
if total_prop:
441444
pagination_config["total_path"] = total_prop.json_path
442445
else:
446+
pagination_config["total_path"] = ""
443447
pagination_config["maximum_page"] = DEFAULT_MAXIMUM_PAGINATOR_OFFSET
444448

445449
return Pagination(

dlt_openapi/detector/default/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
RE_TOTAL_PAGE_PROPERTY = re.compile(r"(?i)(total|count)", re.IGNORECASE)
1919
RE_OFFSET_PARAM = re.compile(r"(?i)(start|offset|skip)", re.IGNORECASE)
2020
RE_LIMIT_PARAM = re.compile(r"(?i)(limit|per_page|page_size|size)", re.IGNORECASE)
21-
RE_TOTAL_PROPERTY = re.compile(r"(?i)(total|count)", re.IGNORECASE)
21+
RE_TOTAL_PROPERTY = re.compile(r"(?i)(total|count|total_count)", re.IGNORECASE)
2222
RE_CURSOR_PARAM = re.compile(r"(?i)(cursor|after|since)", re.IGNORECASE)
2323
RE_CURSOR_PROP = re.compile(r"(?i)(cursor|next_cursor)", re.IGNORECASE)
2424
RE_NEXT_PROPERTY = re.compile(r"(?i)(next|next_url|more)", re.IGNORECASE)

tests/integration/basics/test_paginator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def test_offset_limit_pagination_no_count_1(paginators: Dict[str, Any]) -> None:
3030
"offset_param": "offset",
3131
"type": "offset",
3232
"maximum_offset": 20,
33+
"total_path": "",
3334
}
3435

3536

@@ -49,6 +50,7 @@ def test_page_number_paginator_no_count(paginators: Dict[str, Any]) -> None:
4950
"type": "page_number",
5051
"page_param": "page",
5152
"maximum_page": 20,
53+
"total_path": "",
5254
}
5355

5456

tests/integration/basics/test_transformer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def test_simple_transformer_with_deselected_parent() -> None:
3939
config=Config(name_resources_by_operation=True, endpoint_filter=lambda _c: {"single_collection"}),
4040
)
4141

42-
print(resources.keys())
4342
assert len(resources) == 2
4443

4544
assert resources["collections"] == {

tests/integration/extracted/test_dotastats_cases.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def test_simple_dotastats_load() -> None:
1212
"maximum_page": 20,
1313
"page_param": "page",
1414
"type": "page_number",
15+
"total_path": "",
1516
}
1617

1718
# use page query parameter

tests/integration/extracted/test_museums_cases.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def test_simple_museums_load() -> None:
1212
"maximum_page": 20,
1313
"page_param": "page",
1414
"type": "page_number",
15+
"total_path": "",
1516
}
1617

1718
assert source["resources"][0] == {
@@ -34,6 +35,7 @@ def test_simple_museums_pagination() -> None:
3435
"maximum_page": 20,
3536
"page_param": "page",
3637
"type": "page_number",
38+
"total_path": "",
3739
}
3840

3941
assert source["resources"][0] == {

tests/integration/extracted/test_newspilot_cases.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def test_newspilot_load() -> None:
1313
"maximum_page": 20,
1414
"page_param": "page",
1515
"type": "page_number",
16+
"total_path": "",
1617
}
1718

1819
# FIXME: they use page and articles_per_page query parameters

tests/integration/extracted/test_openartnft_cases.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def test_simple_openartnft_load() -> None:
1414
"maximum_offset": 20,
1515
"offset_param": "skip",
1616
"type": "offset",
17+
"total_path": "",
1718
}
1819

1920
assert source["resources"][0] == {

tests/integration/extracted/test_quotesapi_cases.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def test_simple_quotesapi_load() -> None:
1616
"maximum_offset": 20,
1717
"offset_param": "start",
1818
"type": "offset",
19+
"total_path": "",
1920
}
2021

2122
assert source["resources"][0] == {

tests/integration/extracted/test_teamgpt_cases.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def test_teamgpt_load() -> None:
1212
"maximum_page": 20,
1313
"page_param": "page",
1414
"type": "page_number",
15+
"total_path": "",
1516
}
1617

1718
# FIXME: they use page and page_size parameters

0 commit comments

Comments
 (0)