@@ -41,6 +41,9 @@ class _RutPydanticAnnotation:
41
41
- Customizing the core schema and JSON schema:
42
42
https://docs.pydantic.dev/2.9/architecture/#customizing-the-core-schema-and-json-schema
43
43
(https://github.com/pydantic/pydantic/blob/v2.9.2/docs/architecture.md#customizing-the-core-schema-and-json-schema)
44
+ - Implementing __get_pydantic_json_schema__:
45
+ https://docs.pydantic.dev/2.9/concepts/json_schema/#implementing-__get_pydantic_json_schema__
46
+ (https://github.com/pydantic/pydantic/blob/v2.9.2/docs/concepts/json_schema.md#implementing-__get_pydantic_json_schema__-)
44
47
45
48
Examples:
46
49
@@ -73,6 +76,7 @@ class _RutPydanticAnnotation:
73
76
'78773510-K'
74
77
>>> example_type_adapter.dump_json(cl_sii.rut.Rut('78773510-K'))
75
78
b'"78773510-K"'
79
+ >>> example_json_schema = example_type_adapter.json_schema()
76
80
"""
77
81
78
82
RUT_CANONICAL_STRICT_REGEX : ClassVar [Pattern ] = re .compile (
@@ -99,7 +103,7 @@ def validate_from_str(value: str) -> cl_sii.rut.Rut:
99
103
100
104
from_str_schema = pydantic_core .core_schema .chain_schema (
101
105
[
102
- pydantic_core . core_schema . str_schema (pattern = cls . RUT_CANONICAL_STRICT_REGEX ),
106
+ cls . str_schema (),
103
107
pydantic_core .core_schema .no_info_plain_validator_function (validate_from_str ),
104
108
]
105
109
)
@@ -117,6 +121,19 @@ def validate_from_str(value: str) -> cl_sii.rut.Rut:
117
121
),
118
122
)
119
123
124
+ @classmethod
125
+ def __get_pydantic_json_schema__ (
126
+ cls ,
127
+ core_schema : pydantic_core .core_schema .CoreSchema ,
128
+ handler : pydantic .GetJsonSchemaHandler ,
129
+ ) -> pydantic .json_schema .JsonSchemaValue :
130
+ core_schema = cls .str_schema ()
131
+ return handler (core_schema )
132
+
133
+ @classmethod
134
+ def str_schema (cls ) -> pydantic_core .core_schema .CoreSchema :
135
+ return pydantic_core .core_schema .str_schema (pattern = cls .RUT_CANONICAL_STRICT_REGEX )
136
+
120
137
121
138
Rut = Annotated [cl_sii .rut .Rut , _RutPydanticAnnotation ]
122
139
"""
0 commit comments