diff --git a/datauri/__init__.py b/datauri/__init__.py index 07b3499..efc1869 100644 --- a/datauri/__init__.py +++ b/datauri/__init__.py @@ -160,7 +160,7 @@ def __get_validators__(cls): yield cls.validate @classmethod - def validate(cls, v: str) -> Self: + def validate(cls, v: str, x=None) -> Self: if not isinstance(v, str): raise TypeError("string required") @@ -169,6 +169,15 @@ def validate(cls, v: str) -> Self: raise ValueError("invalid data-uri format") return m + @classmethod + def __get_pydantic_json_schema__(cls, core_schema, handler) -> Dict[str, Any]: + core_schema.update(pattern=DATA_URI_REGEX, + examples=[ + "data:text/plain;charset=utf-8;base64,VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2cu" + ], + ) + return core_schema + @classmethod def __modify_schema__(cls, field_schema: Dict[str, Any]) -> None: # __modify_schema__ should mutate the dict it receives in place,