@@ -41,6 +41,9 @@ class _RutPydanticAnnotation:
4141 - Customizing the core schema and JSON schema:
4242 https://docs.pydantic.dev/2.9/architecture/#customizing-the-core-schema-and-json-schema
4343 (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__-)
4447
4548 Examples:
4649
@@ -73,6 +76,7 @@ class _RutPydanticAnnotation:
7376 '78773510-K'
7477 >>> example_type_adapter.dump_json(cl_sii.rut.Rut('78773510-K'))
7578 b'"78773510-K"'
79+ >>> example_json_schema = example_type_adapter.json_schema()
7680 """
7781
7882 RUT_CANONICAL_STRICT_REGEX : ClassVar [Pattern ] = re .compile (
@@ -99,7 +103,7 @@ def validate_from_str(value: str) -> cl_sii.rut.Rut:
99103
100104 from_str_schema = pydantic_core .core_schema .chain_schema (
101105 [
102- pydantic_core . core_schema . str_schema (pattern = cls . RUT_CANONICAL_STRICT_REGEX ),
106+ cls . str_schema (),
103107 pydantic_core .core_schema .no_info_plain_validator_function (validate_from_str ),
104108 ]
105109 )
@@ -117,6 +121,19 @@ def validate_from_str(value: str) -> cl_sii.rut.Rut:
117121 ),
118122 )
119123
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+
120137
121138Rut = Annotated [cl_sii .rut .Rut , _RutPydanticAnnotation ]
122139"""
0 commit comments