forked from OpenG2P/rest-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschemas.py
67 lines (53 loc) · 1.74 KB
/
schemas.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Copyright 2022 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import warnings
from enum import Enum
from typing import Annotated, Generic, Optional, TypeVar
from pydantic import AliasChoices, BaseModel, ConfigDict, Field, computed_field
T = TypeVar("T")
class PagedCollection(BaseModel, Generic[T]):
count: Annotated[
int,
Field(
...,
description="Count of items into the system.\n "
"Replaces the total field which is deprecated",
validation_alias=AliasChoices("count", "total"),
),
]
items: list[T]
@computed_field()
@property
def total(self) -> int:
return self.count
@total.setter
def total(self, value: int):
warnings.warn(
"The total field is deprecated, please use count instead",
DeprecationWarning,
stacklevel=2,
)
self.count = value
class Paging(BaseModel):
limit: Optional[int] = None # noqa: UP007
offset: Optional[int] = None # noqa: UP007
#############################################################
# here above you can find models only used for the demo app #
#############################################################
class DemoUserInfo(BaseModel):
name: str
display_name: str
class DemoEndpointAppInfo(BaseModel):
id: int
name: str
app: str
auth_method: str = Field(alias="demo_auth_method")
root_path: str
model_config = ConfigDict(from_attributes=True)
class DemoExceptionType(str, Enum):
user_error = "UserError"
validation_error = "ValidationError"
access_error = "AccessError"
missing_error = "MissingError"
http_exception = "HTTPException"
bare_exception = "BareException"