1+ import uuid
12from datetime import datetime , timezone
23from typing import Any
34
@@ -27,6 +28,9 @@ class Something(BaseModel):
2728 # Invalid ULID for str format
2829 ('01BTGNYV6HRNK8K8VKZASZCFP' , None , False ), # Invalid ULID (short length)
2930 ('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 ),
3034 # Valid ULID for _ULID format
3135 (_ULID .from_str ('01BTGNYV6HRNK8K8VKZASZCFPE' ), '01BTGNYV6HRNK8K8VKZASZCFPE' , True ),
3236 (_ULID .from_str ('01BTGNYV6HRNK8K8VKZASZCFPF' ), '01BTGNYV6HRNK8K8VKZASZCFPF' , True ),
@@ -62,7 +66,12 @@ def test_json_schema():
6266 assert Something .model_json_schema (mode = 'validation' ) == {
6367 'properties' : {
6468 '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+ ],
6675 'title' : 'Ulid' ,
6776 }
6877 },
@@ -73,7 +82,12 @@ def test_json_schema():
7382 assert Something .model_json_schema (mode = 'serialization' ) == {
7483 'properties' : {
7584 '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+ ],
7791 'title' : 'Ulid' ,
7892 }
7993 },
0 commit comments