File tree Expand file tree Collapse file tree 1 file changed +19
-3
lines changed
packages/models-library/src/models_library/api_schemas_webserver Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Original file line number Diff line number Diff line change 11from pathlib import Path
2- from typing import Annotated
2+ from typing import Annotated , Final
33
4- from pydantic import BaseModel , Field
4+ from pydantic import BaseModel , BeforeValidator , Field
55
66from ..api_schemas_storage .storage_schemas import (
77 DEFAULT_NUMBER_OF_PATHS_PER_PAGE ,
1111from ..rest_pagination import CursorQueryParameters
1212from ._base import InputSchema
1313
14+ MIN_NON_WILDCARD_CHARS : Final [int ] = 3
1415
1516class StorageLocationPathParams (BaseModel ):
1617 location_id : LocationID
@@ -44,5 +45,20 @@ class DataExportPost(InputSchema):
4445 paths : list [PathToExport ]
4546
4647
48+ def validate_pattern_has_enough_characters (v : str ) -> str :
49+ non_wildcard_chars = len ([c for c in v if c not in ("*" , "?" )])
50+
51+ if non_wildcard_chars < MIN_NON_WILDCARD_CHARS :
52+ msg = f"Name pattern must contain at least { MIN_NON_WILDCARD_CHARS } non-wildcard characters (not * or ?), got { non_wildcard_chars } "
53+ raise ValueError (msg )
54+ return v
55+
56+
4757class SearchBodyParams (InputSchema ):
48- name_pattern : str
58+ name_pattern : Annotated [
59+ str ,
60+ BeforeValidator (validate_pattern_has_enough_characters ),
61+ Field (
62+ description = "Name pattern with wildcard support (* and ?). Minimum of {MIN_NON_WILDCARD_CHARS} non-wildcard characters required." ,
63+ )
64+ ]
You can’t perform that action at this time.
0 commit comments