From 2fdc9126c3ceb85eb819e8aed550ac5e5e51b24d Mon Sep 17 00:00:00 2001 From: Isaac To Date: Mon, 29 Jul 2024 16:09:07 -0700 Subject: [PATCH] Move pattern specification for `BaseType.identifier` To the annotation for the `str` type. The previous specification is actually incorrect. --- dandischema/models.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/dandischema/models.py b/dandischema/models.py index 2906acc..20af619 100644 --- a/dandischema/models.py +++ b/dandischema/models.py @@ -15,6 +15,7 @@ EmailStr, Field, GetJsonSchemaHandler, + StringConstraints, TypeAdapter, ValidationInfo, field_validator, @@ -652,11 +653,20 @@ def ensure_value(cls, val: Union[Any, List[Any]]) -> Union[Any, List[Any]]: class BaseType(DandiBaseModel): """Base class for enumerated types""" - identifier: Optional[Union[AnyHttpUrl, str]] = Field( + identifier: Optional[ + Annotated[ + Union[ + AnyHttpUrl, + Annotated[ + str, StringConstraints(pattern=r"^[a-zA-Z0-9-]+:[a-zA-Z0-9-/\._]+$") + ], + ], + Field(union_mode="left_to_right"), + ] + ] = Field( None, description="The identifier can be any url or a compact URI, preferably" " supported by identifiers.org.", - pattern=r"^[a-zA-Z0-9-]+:[a-zA-Z0-9-/\._]+$", json_schema_extra={"nskey": "schema"}, ) name: Optional[str] = Field(