|
9 | 9 | from collections.abc import Sequence |
10 | 10 | from typing import Any, ClassVar, Generic, TypeAlias, TypeVar |
11 | 11 |
|
12 | | -from fastapi_pagination.limit_offset import LimitOffsetParams |
13 | | -from fastapi_pagination.links.limit_offset import ( |
14 | | - LimitOffsetPage as _FastApiLimitOffsetPage, |
15 | | -) |
| 12 | +from fastapi import Query |
| 13 | +from fastapi_pagination.customization import CustomizedPage, UseName, UseParamsFields |
| 14 | +from fastapi_pagination.limit_offset import LimitOffsetParams as _LimitOffsetParams |
| 15 | +from fastapi_pagination.links import LimitOffsetPage as _LimitOffsetPage |
16 | 16 | from models_library.rest_pagination import ( |
17 | 17 | DEFAULT_NUMBER_OF_ITEMS_PER_PAGE, |
18 | 18 | MAXIMUM_NUMBER_OF_ITEMS_PER_PAGE, |
19 | 19 | ) |
20 | 20 | from models_library.utils.pydantic_tools_extension import FieldNotRequired |
21 | | -from pydantic import Field, NonNegativeInt, validator |
| 21 | +from pydantic import NonNegativeInt, validator |
22 | 22 | from pydantic.generics import GenericModel |
23 | 23 |
|
24 | 24 | T = TypeVar("T") |
25 | 25 |
|
26 | | -# NOTE: same pagination limits and defaults as web-server |
27 | | -Page = _FastApiLimitOffsetPage.with_custom_options( |
28 | | - limit=Field( |
29 | | - DEFAULT_NUMBER_OF_ITEMS_PER_PAGE, ge=1, le=MAXIMUM_NUMBER_OF_ITEMS_PER_PAGE |
30 | | - ) |
31 | | -) |
32 | | -# NOTE: Renamed to make shorter clients name models |
33 | | -Page.__name__ = "Page" |
34 | | - |
35 | | -PaginationParams: TypeAlias = LimitOffsetParams |
| 26 | +Page = CustomizedPage[ |
| 27 | + _LimitOffsetPage[T], |
| 28 | + # Customizes the default and maximum to fit those of the web-server. It simplifies interconnection |
| 29 | + UseParamsFields( |
| 30 | + limit=Query( |
| 31 | + DEFAULT_NUMBER_OF_ITEMS_PER_PAGE, |
| 32 | + ge=1, |
| 33 | + le=MAXIMUM_NUMBER_OF_ITEMS_PER_PAGE, |
| 34 | + description="Page size limit", |
| 35 | + ) |
| 36 | + ), |
| 37 | + # Renames class for the openapi.json to make the python-client's name models shorter |
| 38 | + UseName(name="Page"), |
| 39 | +] |
| 40 | + |
| 41 | +PaginationParams: TypeAlias = _LimitOffsetParams |
36 | 42 |
|
37 | 43 |
|
38 | 44 | class OnePage(GenericModel, Generic[T]): |
|
0 commit comments