Skip to content

Commit 7d78adf

Browse files
authored
Merge pull request #728 from cordada/develop
Deploy release v0.38.0
2 parents e082f92 + ec4fb98 commit 7d78adf

File tree

7 files changed

+59
-5
lines changed

7 files changed

+59
-5
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.37.0
2+
current_version = 0.38.0
33
commit = True
44
tag = False
55
message = chore: Bump version from {current_version} to {new_version}

HISTORY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# History
22

3+
## 0.38.0 (2024-10-28)
4+
5+
- (PR #725, 2024-10-28) extras: Fix generation of JSON Schema for Pydantic `Rut` type
6+
- (PR #726, 2024-10-28) chore(deps): Update `mypy` from 1.11.2 to 1.13.0
7+
38
## 0.37.0 (2024-10-25)
49

510
- (PR #721, 2024-10-11) rut: Improve type annotation; Add method to validate DV

requirements-dev.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ bumpversion==0.5.3
1010
coverage==7.6.1
1111
flake8==7.1.1
1212
isort==5.13.2
13-
mypy==1.11.2
13+
mypy==1.13.0
1414
pip-tools==7.4.1
1515
tox==4.21.0
1616
twine==5.1.1

requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ mccabe==0.7.0
7878
# via flake8
7979
mdurl==0.1.2
8080
# via markdown-it-py
81-
mypy==1.11.2
81+
mypy==1.13.0
8282
# via -r requirements-dev.in
8383
mypy-extensions==1.0.0
8484
# via

src/cl_sii/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
55
"""
66

7-
__version__ = '0.37.0'
7+
__version__ = '0.38.0'

src/cl_sii/extras/pydantic_types.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

121138
Rut = Annotated[cl_sii.rut.Rut, _RutPydanticAnnotation]
122139
"""

src/tests/test_extras_pydantic_types.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,35 @@ def test_deserialize_invalid(self) -> None:
133133

134134
with self.assertRaises(pydantic.ValidationError):
135135
self.pydantic_type_adapter.validate_json(data)
136+
137+
def test_json_schema_for_validation(self) -> None:
138+
# -----Arrange-----
139+
140+
expected_json_schema = {
141+
'type': 'string',
142+
'pattern': '^(\\d{1,8})-([\\dK])$',
143+
}
144+
145+
# -----Act-----
146+
147+
actual_json_schema = self.pydantic_type_adapter.json_schema(mode='validation')
148+
149+
# -----Assert-----
150+
151+
self.assertEqual(expected_json_schema, actual_json_schema)
152+
153+
def test_json_schema_for_serialization(self) -> None:
154+
# -----Arrange-----
155+
156+
expected_json_schema = {
157+
'type': 'string',
158+
'pattern': '^(\\d{1,8})-([\\dK])$',
159+
}
160+
161+
# -----Act-----
162+
163+
actual_json_schema = self.pydantic_type_adapter.json_schema(mode='serialization')
164+
165+
# -----Assert-----
166+
167+
self.assertEqual(expected_json_schema, actual_json_schema)

0 commit comments

Comments
 (0)