|
1 | 1 | """DID URL Object."""
|
2 | 2 |
|
3 |
| -from typing import TYPE_CHECKING, Any, Dict, Optional |
| 3 | +from typing import TYPE_CHECKING, Any, Callable, Dict, Optional |
4 | 4 | from urllib.parse import parse_qsl, urlencode, urlparse
|
5 | 5 |
|
6 | 6 | from pydantic import GetCoreSchemaHandler, GetJsonSchemaHandler
|
@@ -44,10 +44,19 @@ def __init__(self, url: str):
|
44 | 44 |
|
45 | 45 | @classmethod
|
46 | 46 | def __get_pydantic_core_schema__(
|
47 |
| - cls, source_type: Any, handler: GetCoreSchemaHandler |
48 |
| - ) -> CoreSchema: |
49 |
| - """Update schema fields.""" |
50 |
| - return core_schema.no_info_after_validator_function(cls, handler(str)) |
| 47 | + cls, |
| 48 | + _source_type: Any, |
| 49 | + _handler: Callable[[Any], core_schema.CoreSchema], |
| 50 | + ) -> core_schema.CoreSchema: |
| 51 | + |
| 52 | + return core_schema.union_schema( |
| 53 | + [ |
| 54 | + # check if it's an instance first before doing any further work |
| 55 | + core_schema.is_instance_schema(str), |
| 56 | + core_schema.no_info_plain_validator_function(cls.validate), |
| 57 | + ], |
| 58 | + serialization=core_schema.to_string_ser_schema(), |
| 59 | + ) |
51 | 60 |
|
52 | 61 | @classmethod
|
53 | 62 | def __get_pydantic_json_schema__(
|
|
0 commit comments