Skip to content

Commit

Permalink
Merge pull request #247 from candleindark/pattern_in_annotated
Browse files Browse the repository at this point in the history
Move pattern specification for `BaseType.identifier` to the annotation for the `str` type
  • Loading branch information
yarikoptic authored Aug 12, 2024
2 parents be57e13 + 2fdc912 commit 73e0630
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 73e0630

Please sign in to comment.