cadwyn 4.0.0__tar.gz → 4.1.0__tar.gz
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.
Potentially problematic release.
This version of cadwyn might be problematic. Click here for more details.
- {cadwyn-4.0.0 → cadwyn-4.1.0}/PKG-INFO +1 -1
- {cadwyn-4.0.0 → cadwyn-4.1.0}/cadwyn/__init__.py +2 -1
- {cadwyn-4.0.0 → cadwyn-4.1.0}/cadwyn/_render.py +2 -2
- {cadwyn-4.0.0 → cadwyn-4.1.0}/cadwyn/route_generation.py +2 -2
- {cadwyn-4.0.0 → cadwyn-4.1.0}/cadwyn/schema_generation.py +8 -8
- {cadwyn-4.0.0 → cadwyn-4.1.0}/pyproject.toml +1 -1
- {cadwyn-4.0.0 → cadwyn-4.1.0}/LICENSE +0 -0
- {cadwyn-4.0.0 → cadwyn-4.1.0}/README.md +0 -0
- {cadwyn-4.0.0 → cadwyn-4.1.0}/cadwyn/__main__.py +0 -0
- {cadwyn-4.0.0 → cadwyn-4.1.0}/cadwyn/_asts.py +0 -0
- {cadwyn-4.0.0 → cadwyn-4.1.0}/cadwyn/_importer.py +0 -0
- {cadwyn-4.0.0 → cadwyn-4.1.0}/cadwyn/_utils.py +0 -0
- {cadwyn-4.0.0 → cadwyn-4.1.0}/cadwyn/applications.py +0 -0
- {cadwyn-4.0.0 → cadwyn-4.1.0}/cadwyn/exceptions.py +0 -0
- {cadwyn-4.0.0 → cadwyn-4.1.0}/cadwyn/middleware.py +0 -0
- {cadwyn-4.0.0 → cadwyn-4.1.0}/cadwyn/py.typed +0 -0
- {cadwyn-4.0.0 → cadwyn-4.1.0}/cadwyn/routing.py +0 -0
- {cadwyn-4.0.0 → cadwyn-4.1.0}/cadwyn/static/__init__.py +0 -0
- {cadwyn-4.0.0 → cadwyn-4.1.0}/cadwyn/static/docs.html +0 -0
- {cadwyn-4.0.0 → cadwyn-4.1.0}/cadwyn/structure/__init__.py +0 -0
- {cadwyn-4.0.0 → cadwyn-4.1.0}/cadwyn/structure/common.py +0 -0
- {cadwyn-4.0.0 → cadwyn-4.1.0}/cadwyn/structure/data.py +0 -0
- {cadwyn-4.0.0 → cadwyn-4.1.0}/cadwyn/structure/endpoints.py +0 -0
- {cadwyn-4.0.0 → cadwyn-4.1.0}/cadwyn/structure/enums.py +0 -0
- {cadwyn-4.0.0 → cadwyn-4.1.0}/cadwyn/structure/schemas.py +0 -0
- {cadwyn-4.0.0 → cadwyn-4.1.0}/cadwyn/structure/versions.py +0 -0
|
@@ -2,7 +2,7 @@ import importlib.metadata
|
|
|
2
2
|
|
|
3
3
|
from .applications import Cadwyn
|
|
4
4
|
from .route_generation import VersionedAPIRouter, generate_versioned_routers
|
|
5
|
-
from .schema_generation import migrate_response_body
|
|
5
|
+
from .schema_generation import generate_versioned_models, migrate_response_body
|
|
6
6
|
from .structure import (
|
|
7
7
|
HeadVersion,
|
|
8
8
|
RequestInfo,
|
|
@@ -36,4 +36,5 @@ __all__ = [
|
|
|
36
36
|
"convert_request_to_next_version_for",
|
|
37
37
|
"RequestInfo",
|
|
38
38
|
"ResponseInfo",
|
|
39
|
+
"generate_versioned_models",
|
|
39
40
|
]
|
|
@@ -13,8 +13,8 @@ from cadwyn.exceptions import CadwynRenderError
|
|
|
13
13
|
from cadwyn.schema_generation import (
|
|
14
14
|
PydanticFieldWrapper,
|
|
15
15
|
_EnumWrapper,
|
|
16
|
-
_generate_versioned_models,
|
|
17
16
|
_PydanticRuntimeModelWrapper,
|
|
17
|
+
generate_versioned_models,
|
|
18
18
|
)
|
|
19
19
|
from cadwyn.structure.versions import VersionBundle, get_cls_pythonpath
|
|
20
20
|
|
|
@@ -73,7 +73,7 @@ def render_model(model: type[BaseModel | Enum], versions: VersionBundle, version
|
|
|
73
73
|
def _render_model_from_ast(
|
|
74
74
|
model_ast: ast.ClassDef, model: type[BaseModel | Enum], versions: VersionBundle, version: str
|
|
75
75
|
):
|
|
76
|
-
versioned_models =
|
|
76
|
+
versioned_models = generate_versioned_models(versions)
|
|
77
77
|
generator = versioned_models[version]
|
|
78
78
|
wrapper = generator._get_wrapper_for_model(model)
|
|
79
79
|
|
|
@@ -34,7 +34,7 @@ from cadwyn.exceptions import (
|
|
|
34
34
|
)
|
|
35
35
|
from cadwyn.schema_generation import (
|
|
36
36
|
_add_request_and_response_params,
|
|
37
|
-
|
|
37
|
+
generate_versioned_models,
|
|
38
38
|
)
|
|
39
39
|
from cadwyn.structure import Version, VersionBundle
|
|
40
40
|
from cadwyn.structure.common import Endpoint, VersionDate
|
|
@@ -85,7 +85,7 @@ class _EndpointTransformer(Generic[_R]):
|
|
|
85
85
|
super().__init__()
|
|
86
86
|
self.parent_router = parent_router
|
|
87
87
|
self.versions = versions
|
|
88
|
-
self.schema_generators =
|
|
88
|
+
self.schema_generators = generate_versioned_models(versions)
|
|
89
89
|
|
|
90
90
|
self.routes_that_never_existed = [
|
|
91
91
|
route for route in parent_router.routes if isinstance(route, APIRoute) and _DELETED_ROUTE_TAG in route.tags
|
|
@@ -115,7 +115,7 @@ class PydanticFieldWrapper:
|
|
|
115
115
|
def delete_attribute(self, *, name: str) -> None:
|
|
116
116
|
self.passed_field_attributes.pop(name)
|
|
117
117
|
|
|
118
|
-
def generate_field_copy(self, generator: "
|
|
118
|
+
def generate_field_copy(self, generator: "SchemaGenerator") -> pydantic.fields.FieldInfo:
|
|
119
119
|
return pydantic.Field(
|
|
120
120
|
**generator.annotation_transformer.change_version_of_annotation(self.passed_field_attributes)
|
|
121
121
|
)
|
|
@@ -173,7 +173,7 @@ def migrate_response_body(
|
|
|
173
173
|
|
|
174
174
|
version = versions._get_closest_lesser_version(version)
|
|
175
175
|
|
|
176
|
-
versioned_response_model: type[pydantic.BaseModel] =
|
|
176
|
+
versioned_response_model: type[pydantic.BaseModel] = generate_versioned_models(versions)[str(version)][
|
|
177
177
|
latest_response_model
|
|
178
178
|
]
|
|
179
179
|
return versioned_response_model.model_validate(migrated_response.body)
|
|
@@ -331,7 +331,7 @@ class _PydanticRuntimeModelWrapper(Generic[_T_PYDANTIC_MODEL]):
|
|
|
331
331
|
|
|
332
332
|
return annotations | self.annotations
|
|
333
333
|
|
|
334
|
-
def generate_model_copy(self, generator: "
|
|
334
|
+
def generate_model_copy(self, generator: "SchemaGenerator") -> type[_T_PYDANTIC_MODEL]:
|
|
335
335
|
per_field_validators = {
|
|
336
336
|
name: validator.decorator(*validator.fields, **validator.kwargs)(validator.func)
|
|
337
337
|
for name, validator in self.validators.items()
|
|
@@ -398,7 +398,7 @@ class _AsyncCallableWrapper(_CallableWrapper):
|
|
|
398
398
|
|
|
399
399
|
@final
|
|
400
400
|
class _AnnotationTransformer:
|
|
401
|
-
def __init__(self, generator: "
|
|
401
|
+
def __init__(self, generator: "SchemaGenerator") -> None:
|
|
402
402
|
# This cache is not here for speeding things up. It's for preventing the creation of copies of the same object
|
|
403
403
|
# because such copies could produce weird behaviors at runtime, especially if you/fastapi do any comparisons.
|
|
404
404
|
# It's defined here and not on the method because of this: https://youtu.be/sVjtp6tGo0g
|
|
@@ -587,7 +587,7 @@ def _add_request_and_response_params(route: APIRoute):
|
|
|
587
587
|
|
|
588
588
|
|
|
589
589
|
@final
|
|
590
|
-
class
|
|
590
|
+
class SchemaGenerator:
|
|
591
591
|
__slots__ = "annotation_transformer", "model_bundle", "concrete_models"
|
|
592
592
|
|
|
593
593
|
def __init__(self, model_bundle: _ModelBundle) -> None:
|
|
@@ -636,7 +636,7 @@ class _SchemaGenerator:
|
|
|
636
636
|
|
|
637
637
|
|
|
638
638
|
@cache
|
|
639
|
-
def
|
|
639
|
+
def generate_versioned_models(versions: "VersionBundle") -> "dict[str, SchemaGenerator]":
|
|
640
640
|
models = _create_model_bundle(versions)
|
|
641
641
|
|
|
642
642
|
version_to_context_map = {}
|
|
@@ -645,7 +645,7 @@ def _generate_versioned_models(versions: "VersionBundle") -> "dict[str, _SchemaG
|
|
|
645
645
|
|
|
646
646
|
for version in versions.versions:
|
|
647
647
|
context = _RuntimeSchemaGenContext(current_version=version, models=models, version_bundle=versions)
|
|
648
|
-
version_to_context_map[str(version.value)] =
|
|
648
|
+
version_to_context_map[str(version.value)] = SchemaGenerator(copy.deepcopy(models))
|
|
649
649
|
# note that the last migration will not contain any version changes so we don't need to save the results
|
|
650
650
|
_migrate_classes(context)
|
|
651
651
|
|
|
@@ -918,7 +918,7 @@ class _EnumWrapper(Generic[_T_ENUM]):
|
|
|
918
918
|
memo[id(self)] = result
|
|
919
919
|
return result
|
|
920
920
|
|
|
921
|
-
def generate_model_copy(self, generator: "
|
|
921
|
+
def generate_model_copy(self, generator: "SchemaGenerator") -> type[_T_ENUM]:
|
|
922
922
|
enum_dict = Enum.__prepare__(self.cls.__name__, self.cls.__bases__)
|
|
923
923
|
|
|
924
924
|
raw_member_map = {k: v.value if isinstance(v, Enum) else v for k, v in self.members.items()}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|