FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
FastAPI-JSONAPI/fastapi_jsonapi/validation_utils.py at main · srepmub/FastAPI-JSONAPI · GitHub
srepmub
/
FastAPI-JSONAPI
Public
forked from
mts-ai/FastAPI-JSONAPI
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
FastAPI-JSONAPI
/
fastapi_jsonapi
/
validation_utils.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
51 lines (37 loc) · 1.87 KB
Breadcrumbs
FastAPI-JSONAPI
/
fastapi_jsonapi
/
validation_utils.py
Copy path
File metadata and controls
51 lines (37 loc) · 1.87 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
from
__future__
import
annotations
from
typing
import
TYPE_CHECKING
,
Callable
,
Optional
,
Type
from
pydantic
import
BaseModel
,
field_validator
,
model_validator
from
pydantic
.
_internal
.
_decorators
import
PydanticDescriptorProxy
if
TYPE_CHECKING
:
# noinspection PyProtectedMember
from
pydantic
.
_internal
.
_decorators
import
DecoratorInfos
def
extract_validators
(
model
:
Type
[
BaseModel
],
include_for_field_names
:
Optional
[
set
[
str
]]
=
None
,
exclude_for_field_names
:
Optional
[
set
[
str
]]
=
None
,
)
->
tuple
[
dict
[
str
,
Callable
],
dict
[
str
,
PydanticDescriptorProxy
]]:
validators
:
DecoratorInfos
=
model
.
__pydantic_decorators__
exclude_for_field_names
=
exclude_for_field_names
or
set
()
if
include_for_field_names
and
exclude_for_field_names
:
include_for_field_names
=
include_for_field_names
.
difference
(
exclude_for_field_names
,
)
field_validators
,
model_validators
=
{}, {}
# field validators
for
name
,
validator
in
validators
.
field_validators
.
items
():
for
field_name
in
validator
.
info
.
fields
:
# exclude
if
field_name
in
exclude_for_field_names
:
continue
# or include
if
include_for_field_names
and
field_name
not
in
include_for_field_names
:
continue
validator_config
=
field_validator
(
field_name
,
mode
=
validator
.
info
.
mode
)
func
=
validator
.
func
.
__func__
if
hasattr
(
validator
.
func
,
"__func__"
)
else
validator
.
func
field_validators
[
name
]
=
validator_config
(
func
)
# model validators
for
name
,
validator
in
validators
.
model_validators
.
items
():
validator_config
=
model_validator
(
mode
=
validator
.
info
.
mode
)
func
=
validator
.
func
.
__func__
if
hasattr
(
validator
.
func
,
"__func__"
)
else
validator
.
func
model_validators
[
name
]
=
validator_config
(
func
)
return
field_validators
,
model_validators
Back
|
FazBrowse Home
|
New Git URL