cadwyn 3.10.0__tar.gz → 3.11.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-3.10.0 → cadwyn-3.11.0}/PKG-INFO +1 -1
- {cadwyn-3.10.0 → cadwyn-3.11.0}/cadwyn/applications.py +1 -1
- {cadwyn-3.10.0 → cadwyn-3.11.0}/cadwyn/route_generation.py +29 -1
- {cadwyn-3.10.0 → cadwyn-3.11.0}/cadwyn/routing.py +10 -5
- {cadwyn-3.10.0 → cadwyn-3.11.0}/cadwyn/structure/versions.py +1 -2
- {cadwyn-3.10.0 → cadwyn-3.11.0}/pyproject.toml +1 -1
- {cadwyn-3.10.0 → cadwyn-3.11.0}/LICENSE +0 -0
- {cadwyn-3.10.0 → cadwyn-3.11.0}/README.md +0 -0
- {cadwyn-3.10.0 → cadwyn-3.11.0}/cadwyn/__init__.py +0 -0
- {cadwyn-3.10.0 → cadwyn-3.11.0}/cadwyn/__main__.py +0 -0
- {cadwyn-3.10.0 → cadwyn-3.11.0}/cadwyn/_asts.py +0 -0
- {cadwyn-3.10.0 → cadwyn-3.11.0}/cadwyn/_compat.py +0 -0
- {cadwyn-3.10.0 → cadwyn-3.11.0}/cadwyn/_package_utils.py +0 -0
- {cadwyn-3.10.0 → cadwyn-3.11.0}/cadwyn/_utils.py +0 -0
- {cadwyn-3.10.0 → cadwyn-3.11.0}/cadwyn/codegen/README.md +0 -0
- {cadwyn-3.10.0 → cadwyn-3.11.0}/cadwyn/codegen/__init__.py +0 -0
- {cadwyn-3.10.0 → cadwyn-3.11.0}/cadwyn/codegen/_common.py +0 -0
- {cadwyn-3.10.0 → cadwyn-3.11.0}/cadwyn/codegen/_main.py +0 -0
- {cadwyn-3.10.0 → cadwyn-3.11.0}/cadwyn/codegen/_plugins/__init__.py +0 -0
- {cadwyn-3.10.0 → cadwyn-3.11.0}/cadwyn/codegen/_plugins/class_migrations.py +0 -0
- {cadwyn-3.10.0 → cadwyn-3.11.0}/cadwyn/codegen/_plugins/class_rebuilding.py +0 -0
- {cadwyn-3.10.0 → cadwyn-3.11.0}/cadwyn/codegen/_plugins/class_renaming.py +0 -0
- {cadwyn-3.10.0 → cadwyn-3.11.0}/cadwyn/codegen/_plugins/import_auto_adding.py +0 -0
- {cadwyn-3.10.0 → cadwyn-3.11.0}/cadwyn/codegen/_plugins/module_migrations.py +0 -0
- {cadwyn-3.10.0 → cadwyn-3.11.0}/cadwyn/exceptions.py +0 -0
- {cadwyn-3.10.0 → cadwyn-3.11.0}/cadwyn/main.py +0 -0
- {cadwyn-3.10.0 → cadwyn-3.11.0}/cadwyn/middleware.py +0 -0
- {cadwyn-3.10.0 → cadwyn-3.11.0}/cadwyn/py.typed +0 -0
- {cadwyn-3.10.0 → cadwyn-3.11.0}/cadwyn/static/__init__.py +0 -0
- {cadwyn-3.10.0 → cadwyn-3.11.0}/cadwyn/static/docs.html +0 -0
- {cadwyn-3.10.0 → cadwyn-3.11.0}/cadwyn/structure/__init__.py +0 -0
- {cadwyn-3.10.0 → cadwyn-3.11.0}/cadwyn/structure/common.py +0 -0
- {cadwyn-3.10.0 → cadwyn-3.11.0}/cadwyn/structure/data.py +0 -0
- {cadwyn-3.10.0 → cadwyn-3.11.0}/cadwyn/structure/endpoints.py +0 -0
- {cadwyn-3.10.0 → cadwyn-3.11.0}/cadwyn/structure/enums.py +0 -0
- {cadwyn-3.10.0 → cadwyn-3.11.0}/cadwyn/structure/modules.py +0 -0
- {cadwyn-3.10.0 → cadwyn-3.11.0}/cadwyn/structure/schemas.py +0 -0
|
@@ -127,6 +127,7 @@ class Cadwyn(FastAPI):
|
|
|
127
127
|
deprecated=deprecated,
|
|
128
128
|
responses=responses,
|
|
129
129
|
api_version_header_name=api_version_header_name,
|
|
130
|
+
api_version_var=self.versions.api_version_var,
|
|
130
131
|
lifespan=lifespan,
|
|
131
132
|
)
|
|
132
133
|
self.docs_url = docs_url
|
|
@@ -182,7 +183,6 @@ class Cadwyn(FastAPI):
|
|
|
182
183
|
router_versions = generate_versioned_routers(
|
|
183
184
|
root_router,
|
|
184
185
|
versions=self.versions,
|
|
185
|
-
head_schemas_package=self.versions.head_schemas_package, # pyright: ignore[reportArgumentType],
|
|
186
186
|
)
|
|
187
187
|
for version, router in router_versions.items():
|
|
188
188
|
self.add_header_versioned_routers(router, header_value=version.isoformat())
|
|
@@ -22,6 +22,7 @@ from typing import (
|
|
|
22
22
|
final,
|
|
23
23
|
get_args,
|
|
24
24
|
get_origin,
|
|
25
|
+
overload,
|
|
25
26
|
)
|
|
26
27
|
|
|
27
28
|
import fastapi.params
|
|
@@ -90,11 +91,38 @@ class InternalRepresentationOf:
|
|
|
90
91
|
return cast(Any, type("InternalRepresentationOf", (cls, original_schema), {}))
|
|
91
92
|
|
|
92
93
|
|
|
94
|
+
@overload
|
|
93
95
|
def generate_versioned_routers(
|
|
94
96
|
router: _R,
|
|
95
97
|
versions: VersionBundle,
|
|
96
|
-
head_schemas_package: ModuleType,
|
|
97
98
|
) -> dict[VersionDate, _R]:
|
|
99
|
+
...
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
@overload
|
|
103
|
+
@deprecated("Do not use the latest_schemas_package argument. Put head_schemas_package into your VersionBundle instead")
|
|
104
|
+
def generate_versioned_routers(
|
|
105
|
+
router: _R,
|
|
106
|
+
versions: VersionBundle,
|
|
107
|
+
latest_schemas_package: ModuleType | None,
|
|
108
|
+
) -> dict[VersionDate, _R]:
|
|
109
|
+
...
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def generate_versioned_routers(
|
|
113
|
+
router: _R,
|
|
114
|
+
versions: VersionBundle,
|
|
115
|
+
latest_schemas_package: ModuleType | None = None,
|
|
116
|
+
) -> dict[VersionDate, _R]:
|
|
117
|
+
if versions.head_schemas_package is not None:
|
|
118
|
+
head_schemas_package = versions.head_schemas_package
|
|
119
|
+
elif latest_schemas_package is not None: # pragma: no cover
|
|
120
|
+
head_schemas_package = latest_schemas_package
|
|
121
|
+
else: # pragma: no cover
|
|
122
|
+
raise TypeError(
|
|
123
|
+
"TypeError: generate_versioned_routers() must be called with a VersionBundle "
|
|
124
|
+
"that contains a non-null head_schemas_package."
|
|
125
|
+
)
|
|
98
126
|
versions.head_schemas_package = head_schemas_package
|
|
99
127
|
versions._validate_head_schemas_package_structure()
|
|
100
128
|
return _EndpointTransformer(router, versions, head_schemas_package).transform()
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import bisect
|
|
2
2
|
from collections import OrderedDict
|
|
3
3
|
from collections.abc import Sequence
|
|
4
|
+
from contextvars import ContextVar
|
|
4
5
|
from datetime import date
|
|
5
6
|
from functools import cached_property
|
|
6
7
|
from logging import getLogger
|
|
@@ -35,11 +36,18 @@ class _RootHeaderAPIRouter(APIRouter):
|
|
|
35
36
|
matched to the higher versioned route
|
|
36
37
|
"""
|
|
37
38
|
|
|
38
|
-
def __init__(
|
|
39
|
+
def __init__(
|
|
40
|
+
self,
|
|
41
|
+
*args: Any,
|
|
42
|
+
api_version_header_name: str,
|
|
43
|
+
api_version_var: ContextVar[date] | ContextVar[date | None],
|
|
44
|
+
**kwargs: Any,
|
|
45
|
+
):
|
|
39
46
|
super().__init__(*args, **kwargs)
|
|
40
47
|
self.versioned_routes: dict[date, list[BaseRoute]] = {}
|
|
41
48
|
self.unversioned_routes: list[BaseRoute] = []
|
|
42
49
|
self.api_version_header_name = api_version_header_name.lower()
|
|
50
|
+
self.api_version_var = api_version_var
|
|
43
51
|
|
|
44
52
|
@cached_property
|
|
45
53
|
def sorted_versioned_routes(self):
|
|
@@ -90,10 +98,7 @@ class _RootHeaderAPIRouter(APIRouter):
|
|
|
90
98
|
await self.lifespan(scope, receive, send)
|
|
91
99
|
return
|
|
92
100
|
|
|
93
|
-
|
|
94
|
-
header_value = request_headers.get(self.api_version_header_name.encode(), b"").decode()
|
|
95
|
-
if header_value:
|
|
96
|
-
header_value = date.fromisoformat(header_value)
|
|
101
|
+
header_value = self.api_version_var.get(None)
|
|
97
102
|
|
|
98
103
|
# if header_value is None, then it's an unversioned request and we need to use the unversioned routes
|
|
99
104
|
# if there will be a value, we search for the most suitable version
|
|
@@ -323,10 +323,9 @@ class VersionBundle:
|
|
|
323
323
|
# upon receiving `latest`.
|
|
324
324
|
|
|
325
325
|
head_schemas_package = cast(ModuleType, self.head_schemas_package)
|
|
326
|
-
|
|
327
326
|
if not hasattr(head_schemas_package, "__path__"):
|
|
328
327
|
raise CadwynStructureError(
|
|
329
|
-
f'The head schemas
|
|
328
|
+
f'The head schemas package must be a package. "{head_schemas_package.__name__}" is not a package.',
|
|
330
329
|
)
|
|
331
330
|
elif head_schemas_package.__name__.endswith(".head"):
|
|
332
331
|
return "head"
|
|
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
|
|
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
|