11import logging
2+ from typing import Annotated
23
34from models_library .basic_types import IDStr
45from models_library .folders import FolderID
1112 null_or_none_str_to_none_validator ,
1213)
1314from models_library .workspaces import WorkspaceID
14- from pydantic import BaseModel , Extra , Field , Json , validator
15+ from pydantic import (
16+ BaseModel ,
17+ BeforeValidator ,
18+ ConfigDict ,
19+ Field ,
20+ Json ,
21+ field_validator ,
22+ )
1523from servicelib .aiohttp .requests_validation import RequestParams , StrictRequestParams
1624from servicelib .request_keys import RQT_USERID_KEY
1725
@@ -41,11 +49,11 @@ class FolderListSortParams(BaseModel):
4149 order_by : Json [OrderBy ] = Field (
4250 default = OrderBy (field = IDStr ("modified" ), direction = OrderDirection .DESC ),
4351 description = "Order by field (modified_at|name|description) and direction (asc|desc). The default sorting order is ascending." ,
44- example = '{"field": "name", "direction": "desc"}' ,
52+ examples = [ '{"field": "name", "direction": "desc"}' ] ,
4553 alias = "order_by" ,
4654 )
4755
48- @validator ("order_by" , check_fields = False )
56+ @field_validator ("order_by" , check_fields = False )
4957 @classmethod
5058 def _validate_order_by_field (cls , v ):
5159 if v .field not in {
@@ -59,51 +67,41 @@ def _validate_order_by_field(cls, v):
5967 v .field = "modified"
6068 return v
6169
62- class Config :
63- extra = Extra .forbid
70+ model_config = ConfigDict (extra = "forbid" )
6471
6572
6673class FolderListWithJsonStrQueryParams (
6774 PageQueryParameters , FolderListSortParams , FiltersQueryParameters [FolderFilters ]
6875):
69- folder_id : FolderID | None = Field (
76+ folder_id : Annotated [
77+ FolderID | None , BeforeValidator (null_or_none_str_to_none_validator )
78+ ] = Field (
7079 default = None ,
7180 description = "List the subfolders of this folder. By default, list the subfolders of the root directory (Folder ID is None)." ,
7281 )
73- workspace_id : WorkspaceID | None = Field (
82+ workspace_id : Annotated [
83+ WorkspaceID | None , BeforeValidator (null_or_none_str_to_none_validator )
84+ ] = Field (
7485 default = None ,
7586 description = "List folders in specific workspace. By default, list in the user private workspace" ,
7687 )
7788
78- class Config :
79- extra = Extra .forbid
80-
81- # validators
82- _null_or_none_str_to_none_validator = validator (
83- "folder_id" , allow_reuse = True , pre = True
84- )(null_or_none_str_to_none_validator )
85-
86- _null_or_none_str_to_none_validator2 = validator (
87- "workspace_id" , allow_reuse = True , pre = True
88- )(null_or_none_str_to_none_validator )
89+ model_config = ConfigDict (extra = "forbid" )
8990
9091
9192class FolderListFullSearchWithJsonStrQueryParams (
9293 PageQueryParameters , FolderListSortParams , FiltersQueryParameters [FolderFilters ]
9394):
94- text : str | None = Field (
95+ text : Annotated [
96+ str | None , BeforeValidator (empty_str_to_none_pre_validator )
97+ ] = Field (
9598 default = None ,
9699 description = "Multi column full text search, across all folders and workspaces" ,
97100 max_length = 100 ,
98- example = "My Project" ,
99- )
100-
101- _empty_is_none = validator ("text" , allow_reuse = True , pre = True )(
102- empty_str_to_none_pre_validator
101+ examples = ["My Project" ],
103102 )
104103
105- class Config :
106- extra = Extra .forbid
104+ model_config = ConfigDict (extra = "forbid" )
107105
108106
109107class RemoveQueryParams (BaseModel ):
0 commit comments