pydantic-avro 0.9.1__py3-none-any.whl → 0.9.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pydantic_avro/from_avro/types.py +1 -1
- pydantic_avro/to_avro/base.py +19 -3
- {pydantic_avro-0.9.1.dist-info → pydantic_avro-0.9.3.dist-info}/METADATA +1 -1
- {pydantic_avro-0.9.1.dist-info → pydantic_avro-0.9.3.dist-info}/RECORD +7 -7
- {pydantic_avro-0.9.1.dist-info → pydantic_avro-0.9.3.dist-info}/LICENSE +0 -0
- {pydantic_avro-0.9.1.dist-info → pydantic_avro-0.9.3.dist-info}/WHEEL +0 -0
- {pydantic_avro-0.9.1.dist-info → pydantic_avro-0.9.3.dist-info}/entry_points.txt +0 -0
pydantic_avro/from_avro/types.py
CHANGED
|
@@ -132,7 +132,7 @@ def generate_field_string(field: dict) -> str:
|
|
|
132
132
|
|
|
133
133
|
def get_pydantic_type(t: Union[str, dict]) -> str:
|
|
134
134
|
"""Get the Pydantic type for a given Avro type"""
|
|
135
|
-
if isinstance(t, str):
|
|
135
|
+
if isinstance(t, str) or isinstance(t, list):
|
|
136
136
|
t = {"type": t}
|
|
137
137
|
|
|
138
138
|
if isinstance(t.get("type"), str):
|
pydantic_avro/to_avro/base.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import Optional
|
|
1
|
+
from typing import Literal, Optional
|
|
2
2
|
|
|
3
3
|
from pydantic import BaseModel
|
|
4
4
|
|
|
@@ -10,14 +10,30 @@ class AvroBase(BaseModel):
|
|
|
10
10
|
"""This class provides functionality to convert a pydantic model to an Avro schema."""
|
|
11
11
|
|
|
12
12
|
@classmethod
|
|
13
|
-
def avro_schema(
|
|
13
|
+
def avro_schema(
|
|
14
|
+
cls,
|
|
15
|
+
by_alias: bool = True,
|
|
16
|
+
namespace: Optional[str] = None,
|
|
17
|
+
mode: Literal["validation", "serialization"] = "serialization",
|
|
18
|
+
) -> dict:
|
|
14
19
|
"""Returns the avro schema for the pydantic class
|
|
15
20
|
|
|
16
21
|
:param by_alias: generate the schemas using the aliases defined, if any
|
|
17
22
|
:param namespace: Provide an optional namespace string to use in schema generation
|
|
23
|
+
:param mode: The mode for generating the schema. Use 'validation' for input validation
|
|
24
|
+
or 'serialization' for output serialization. Defaults to 'serialization'.
|
|
25
|
+
Only applicable for Pydantic v2.
|
|
18
26
|
:return: dict with the Avro Schema for the model
|
|
19
27
|
"""
|
|
20
|
-
|
|
28
|
+
if PYDANTIC_V2:
|
|
29
|
+
schema = cls.model_json_schema(by_alias=by_alias, mode=mode)
|
|
30
|
+
else:
|
|
31
|
+
if mode != "serialization":
|
|
32
|
+
raise ValueError(
|
|
33
|
+
f"The 'mode' parameter is only supported in Pydantic v2. "
|
|
34
|
+
f"Pydantic v1 does not support different schema modes."
|
|
35
|
+
)
|
|
36
|
+
schema = cls.schema(by_alias=by_alias)
|
|
21
37
|
|
|
22
38
|
if namespace is None:
|
|
23
39
|
# Default namespace will be based on title
|
|
@@ -4,14 +4,14 @@ pydantic_avro/base.py,sha256=i1wco_T6FXFdtlxzbzXt3Jv93TmTzTfJ493KCfZh1dc,78
|
|
|
4
4
|
pydantic_avro/from_avro/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
5
|
pydantic_avro/from_avro/avro_to_pydantic.py,sha256=FOEd_6TqoHSlLALgyveb456B3f7TEPGw2ByRgRcigqc,1356
|
|
6
6
|
pydantic_avro/from_avro/class_registery.py,sha256=n_8yELp-Eux9bAs4CJOV78bQ061VV_-2FuvowOQpWCg,864
|
|
7
|
-
pydantic_avro/from_avro/types.py,sha256
|
|
7
|
+
pydantic_avro/from_avro/types.py,sha256=--aWUMKtR5DUaYXXJ1RrDonLZ7AADcdGGAARopLZexA,5190
|
|
8
8
|
pydantic_avro/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
9
|
pydantic_avro/to_avro/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
|
-
pydantic_avro/to_avro/base.py,sha256=
|
|
10
|
+
pydantic_avro/to_avro/base.py,sha256=QtCgXnqhcQAxgWVihz5idwoY4slmkJ2WDKcGqLld9Ig,2066
|
|
11
11
|
pydantic_avro/to_avro/config.py,sha256=R9HLkWiXs7YZ02te8CQt5Kf2rbsE8Fx-hjqv3tBSFJU,152
|
|
12
12
|
pydantic_avro/to_avro/types.py,sha256=-qemQC_vs-xy7VJDTQ1y1k7K1J6Qv3pTLILqp17MO2A,12731
|
|
13
|
-
pydantic_avro-0.9.
|
|
14
|
-
pydantic_avro-0.9.
|
|
15
|
-
pydantic_avro-0.9.
|
|
16
|
-
pydantic_avro-0.9.
|
|
17
|
-
pydantic_avro-0.9.
|
|
13
|
+
pydantic_avro-0.9.3.dist-info/entry_points.txt,sha256=gwHiQfbGLO8Np2sa1bZ_bpxU7sEufx6IachViBE_Fnw,66
|
|
14
|
+
pydantic_avro-0.9.3.dist-info/LICENSE,sha256=gBlYCG1yxb0vGlsmek0lMPVOK5YDxQope4F54jzeqoY,1069
|
|
15
|
+
pydantic_avro-0.9.3.dist-info/WHEEL,sha256=vxFmldFsRN_Hx10GDvsdv1wroKq8r5Lzvjp6GZ4OO8c,88
|
|
16
|
+
pydantic_avro-0.9.3.dist-info/METADATA,sha256=r_czdRovj5dhYm8sfsLTm16EY7HD5LAGEsOSMJnUZ7g,2945
|
|
17
|
+
pydantic_avro-0.9.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|