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