1
+ import uuid
1
2
from datetime import datetime , timezone
2
3
from typing import Any
3
4
@@ -27,6 +28,9 @@ class Something(BaseModel):
27
28
# Invalid ULID for str format
28
29
('01BTGNYV6HRNK8K8VKZASZCFP' , None , False ), # Invalid ULID (short length)
29
30
('01BTGNYV6HRNK8K8VKZASZCFPEA' , None , False ), # Invalid ULID (long length)
31
+ # Valid ULID for UUID format
32
+ (uuid .UUID ('0196FEB3-9C99-8D8C-B3F3-4301C5E9DCE1' ), '01JVZB774SHP6B7WT3072YKQ71' , True ),
33
+ (uuid .UUID ('0196FEB3-CD14-4B50-0015-C1E09BF7B221' ), '01JVZB7K8M9D8005E1W2DZFCH1' , True ),
30
34
# Valid ULID for _ULID format
31
35
(_ULID .from_str ('01BTGNYV6HRNK8K8VKZASZCFPE' ), '01BTGNYV6HRNK8K8VKZASZCFPE' , True ),
32
36
(_ULID .from_str ('01BTGNYV6HRNK8K8VKZASZCFPF' ), '01BTGNYV6HRNK8K8VKZASZCFPF' , True ),
@@ -62,7 +66,12 @@ def test_json_schema():
62
66
assert Something .model_json_schema (mode = 'validation' ) == {
63
67
'properties' : {
64
68
'ulid' : {
65
- 'anyOf' : [{'type' : 'integer' }, {'format' : 'binary' , 'type' : 'string' }, {'type' : 'string' }],
69
+ 'anyOf' : [
70
+ {'type' : 'integer' },
71
+ {'format' : 'binary' , 'type' : 'string' },
72
+ {'type' : 'string' },
73
+ {'format' : 'uuid' , 'type' : 'string' },
74
+ ],
66
75
'title' : 'Ulid' ,
67
76
}
68
77
},
@@ -73,7 +82,12 @@ def test_json_schema():
73
82
assert Something .model_json_schema (mode = 'serialization' ) == {
74
83
'properties' : {
75
84
'ulid' : {
76
- 'anyOf' : [{'type' : 'integer' }, {'format' : 'binary' , 'type' : 'string' }, {'type' : 'string' }],
85
+ 'anyOf' : [
86
+ {'type' : 'integer' },
87
+ {'format' : 'binary' , 'type' : 'string' },
88
+ {'type' : 'string' },
89
+ {'format' : 'uuid' , 'type' : 'string' },
90
+ ],
77
91
'title' : 'Ulid' ,
78
92
}
79
93
},
0 commit comments