Skip to content

Commit

Permalink
Move pattern specification for BaseType.identifier
Browse files Browse the repository at this point in the history
To the annotation for the `str` type. The
previous specification is actually incorrect.
  • Loading branch information
candleindark committed Jul 29, 2024
1 parent be57e13 commit 2fdc912
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions dandischema/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
EmailStr,
Field,
GetJsonSchemaHandler,
StringConstraints,
TypeAdapter,
ValidationInfo,
field_validator,
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 2fdc912

Please sign in to comment.