cadwyn 5.1.4__py3-none-any.whl → 5.2.1__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.
Potentially problematic release.
This version of cadwyn might be problematic. Click here for more details.
- cadwyn/_internal/__init__.py +0 -0
- cadwyn/_internal/context_vars.py +9 -0
- cadwyn/_render.py +1 -1
- cadwyn/applications.py +7 -1
- cadwyn/dependencies.py +3 -3
- cadwyn/middleware.py +6 -1
- cadwyn/route_generation.py +1 -2
- cadwyn/routing.py +10 -1
- cadwyn/structure/schemas.py +1 -1
- cadwyn/structure/versions.py +3 -6
- {cadwyn-5.1.4.dist-info → cadwyn-5.2.1.dist-info}/METADATA +1 -2
- {cadwyn-5.1.4.dist-info → cadwyn-5.2.1.dist-info}/RECORD +15 -13
- {cadwyn-5.1.4.dist-info → cadwyn-5.2.1.dist-info}/WHEEL +0 -0
- {cadwyn-5.1.4.dist-info → cadwyn-5.2.1.dist-info}/entry_points.txt +0 -0
- {cadwyn-5.1.4.dist-info → cadwyn-5.2.1.dist-info}/licenses/LICENSE +0 -0
|
File without changes
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
from contextvars import ContextVar
|
|
2
|
+
|
|
3
|
+
from typing_extensions import Literal
|
|
4
|
+
|
|
5
|
+
DEFAULT_API_VERSION_VAR: "ContextVar[str | None]" = ContextVar("cadwyn_default_api_version")
|
|
6
|
+
CURRENT_DEPENDENCY_SOLVER_OPTIONS = Literal["cadwyn", "fastapi"]
|
|
7
|
+
CURRENT_DEPENDENCY_SOLVER_VAR: ContextVar[CURRENT_DEPENDENCY_SOLVER_OPTIONS] = ContextVar(
|
|
8
|
+
"cadwyn_dependencies_current_dependency_solver"
|
|
9
|
+
)
|
cadwyn/_render.py
CHANGED
|
@@ -5,10 +5,10 @@ from enum import Enum
|
|
|
5
5
|
from typing import TYPE_CHECKING, Union
|
|
6
6
|
|
|
7
7
|
import typer
|
|
8
|
-
from issubclass import issubclass as lenient_issubclass
|
|
9
8
|
from pydantic import BaseModel
|
|
10
9
|
|
|
11
10
|
from cadwyn._asts import get_fancy_repr, pop_docstring_from_cls_body
|
|
11
|
+
from cadwyn._utils import lenient_issubclass
|
|
12
12
|
from cadwyn.exceptions import CadwynRenderError
|
|
13
13
|
from cadwyn.schema_generation import (
|
|
14
14
|
PydanticFieldWrapper,
|
cadwyn/applications.py
CHANGED
|
@@ -133,6 +133,12 @@ class Cadwyn(FastAPI):
|
|
|
133
133
|
stacklevel=2,
|
|
134
134
|
)
|
|
135
135
|
api_version_parameter_name = api_version_header_name
|
|
136
|
+
if api_version_default_value is not None and api_version_location == "path":
|
|
137
|
+
raise CadwynStructureError(
|
|
138
|
+
"You tried to pass an api_version_default_value while putting the API version in Path. "
|
|
139
|
+
"This is not currently supported by Cadwyn. "
|
|
140
|
+
"Please, open an issue on our github if you'd like to have it."
|
|
141
|
+
)
|
|
136
142
|
|
|
137
143
|
super().__init__(
|
|
138
144
|
debug=debug,
|
|
@@ -231,8 +237,8 @@ class Cadwyn(FastAPI):
|
|
|
231
237
|
versioning_middleware_class,
|
|
232
238
|
api_version_parameter_name=api_version_parameter_name,
|
|
233
239
|
api_version_manager=self._api_version_manager,
|
|
234
|
-
api_version_default_value=api_version_default_value,
|
|
235
240
|
api_version_var=self.versions.api_version_var,
|
|
241
|
+
api_version_default_value=api_version_default_value,
|
|
236
242
|
)
|
|
237
243
|
if self.api_version_format == "date" and (
|
|
238
244
|
sorted(self.versions.versions, key=lambda v: v.value, reverse=True) != list(self.versions.versions)
|
cadwyn/dependencies.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
from cadwyn.
|
|
1
|
+
from cadwyn._internal.context_vars import CURRENT_DEPENDENCY_SOLVER_OPTIONS, CURRENT_DEPENDENCY_SOLVER_VAR
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
async def current_dependency_solver() ->
|
|
5
|
-
return
|
|
4
|
+
async def current_dependency_solver() -> CURRENT_DEPENDENCY_SOLVER_OPTIONS:
|
|
5
|
+
return CURRENT_DEPENDENCY_SOLVER_VAR.get("fastapi")
|
cadwyn/middleware.py
CHANGED
|
@@ -7,10 +7,12 @@ from collections.abc import Awaitable, Callable
|
|
|
7
7
|
from contextvars import ContextVar
|
|
8
8
|
from typing import Annotated, Any, Literal, Protocol, Union
|
|
9
9
|
|
|
10
|
+
import fastapi
|
|
10
11
|
from fastapi import Request
|
|
11
12
|
from starlette.middleware.base import BaseHTTPMiddleware, DispatchFunction, RequestResponseEndpoint
|
|
12
13
|
from starlette.types import ASGIApp
|
|
13
14
|
|
|
15
|
+
from cadwyn._internal.context_vars import DEFAULT_API_VERSION_VAR
|
|
14
16
|
from cadwyn.structure.common import VersionType
|
|
15
17
|
|
|
16
18
|
|
|
@@ -69,6 +71,8 @@ def _generate_api_version_dependency(
|
|
|
69
71
|
annotation=Annotated[
|
|
70
72
|
validation_data_type, fastapi_depends_class(openapi_examples={"default": {"value": default_value}})
|
|
71
73
|
],
|
|
74
|
+
# Path-based parameters do not support a default value in FastAPI :(
|
|
75
|
+
default=default_value if fastapi_depends_class != fastapi.Path else inspect.Signature.empty,
|
|
72
76
|
),
|
|
73
77
|
],
|
|
74
78
|
)
|
|
@@ -103,10 +107,11 @@ class VersionPickingMiddleware(BaseHTTPMiddleware):
|
|
|
103
107
|
api_version = self._api_version_manager.get(request)
|
|
104
108
|
|
|
105
109
|
if api_version is None:
|
|
106
|
-
if callable(self.api_version_default_value):
|
|
110
|
+
if callable(self.api_version_default_value):
|
|
107
111
|
api_version = await self.api_version_default_value(request)
|
|
108
112
|
else:
|
|
109
113
|
api_version = self.api_version_default_value
|
|
114
|
+
DEFAULT_API_VERSION_VAR.set(api_version)
|
|
110
115
|
|
|
111
116
|
self.api_version_var.set(api_version)
|
|
112
117
|
response = await call_next(request)
|
cadwyn/route_generation.py
CHANGED
|
@@ -17,12 +17,11 @@ import fastapi.security.base
|
|
|
17
17
|
import fastapi.utils
|
|
18
18
|
from fastapi import APIRouter
|
|
19
19
|
from fastapi.routing import APIRoute
|
|
20
|
-
from issubclass import issubclass as lenient_issubclass
|
|
21
20
|
from pydantic import BaseModel
|
|
22
21
|
from starlette.routing import BaseRoute
|
|
23
22
|
from typing_extensions import TypeVar, assert_never
|
|
24
23
|
|
|
25
|
-
from cadwyn._utils import DATACLASS_SLOTS, Sentinel
|
|
24
|
+
from cadwyn._utils import DATACLASS_SLOTS, Sentinel, lenient_issubclass
|
|
26
25
|
from cadwyn.exceptions import (
|
|
27
26
|
CadwynError,
|
|
28
27
|
RouteAlreadyExistsError,
|
cadwyn/routing.py
CHANGED
|
@@ -11,6 +11,7 @@ from starlette.responses import RedirectResponse
|
|
|
11
11
|
from starlette.routing import BaseRoute, Match
|
|
12
12
|
from starlette.types import Receive, Scope, Send
|
|
13
13
|
|
|
14
|
+
from cadwyn._internal.context_vars import DEFAULT_API_VERSION_VAR
|
|
14
15
|
from cadwyn._utils import same_definition_as_in
|
|
15
16
|
from cadwyn.middleware import APIVersionFormat
|
|
16
17
|
from cadwyn.structure.common import VersionType
|
|
@@ -70,8 +71,8 @@ class _RootCadwynAPIRouter(APIRouter):
|
|
|
70
71
|
if scope["type"] == "lifespan":
|
|
71
72
|
await self.lifespan(scope, receive, send)
|
|
72
73
|
return
|
|
73
|
-
|
|
74
74
|
version = self.api_version_var.get(None)
|
|
75
|
+
default_version_that_was_picked = DEFAULT_API_VERSION_VAR.get(None)
|
|
75
76
|
|
|
76
77
|
# if version is None, then it's an unversioned request and we need to use the unversioned routes
|
|
77
78
|
# if there will be a value, we search for the most suitable version
|
|
@@ -81,6 +82,14 @@ class _RootCadwynAPIRouter(APIRouter):
|
|
|
81
82
|
routes = self.versioned_routers[version].routes
|
|
82
83
|
else:
|
|
83
84
|
routes = await self._get_routes_from_closest_suitable_version(version)
|
|
85
|
+
if default_version_that_was_picked:
|
|
86
|
+
# We add unversioned routes to versioned routes because otherwise unversioned routes
|
|
87
|
+
# will be completely unavailable when a default version is passed. So routes such as
|
|
88
|
+
# /docs will not be accessible at all.
|
|
89
|
+
|
|
90
|
+
# We use this order because if versioned routes go first and there is a versioned route that is
|
|
91
|
+
# the same as an unversioned route -- the unversioned one becomes impossible to match.
|
|
92
|
+
routes = self.unversioned_routes + routes
|
|
84
93
|
await self.process_request(scope=scope, receive=receive, send=send, routes=routes)
|
|
85
94
|
|
|
86
95
|
@cached_property
|
cadwyn/structure/schemas.py
CHANGED
|
@@ -2,7 +2,6 @@ from collections.abc import Callable
|
|
|
2
2
|
from dataclasses import dataclass
|
|
3
3
|
from typing import TYPE_CHECKING, Any, Literal, Union, cast
|
|
4
4
|
|
|
5
|
-
from issubclass import issubclass as lenient_issubclass
|
|
6
5
|
from pydantic import AliasChoices, AliasPath, BaseModel, Field
|
|
7
6
|
from pydantic._internal._decorators import PydanticDescriptorProxy, unwrap_wrapped_function
|
|
8
7
|
from pydantic.fields import FieldInfo
|
|
@@ -12,6 +11,7 @@ from cadwyn._utils import (
|
|
|
12
11
|
Sentinel,
|
|
13
12
|
fully_unwrap_decorator,
|
|
14
13
|
get_name_of_function_wrapped_in_pydantic_validator,
|
|
14
|
+
lenient_issubclass,
|
|
15
15
|
)
|
|
16
16
|
from cadwyn.exceptions import CadwynStructureError
|
|
17
17
|
|
cadwyn/structure/versions.py
CHANGED
|
@@ -24,8 +24,9 @@ from fastapi.routing import APIRoute, _prepare_response_content
|
|
|
24
24
|
from pydantic import BaseModel
|
|
25
25
|
from pydantic_core import PydanticUndefined
|
|
26
26
|
from starlette._utils import is_async_callable
|
|
27
|
-
from typing_extensions import Any,
|
|
27
|
+
from typing_extensions import Any, ParamSpec, TypeAlias, TypeVar, assert_never, deprecated, get_args
|
|
28
28
|
|
|
29
|
+
from cadwyn._internal.context_vars import CURRENT_DEPENDENCY_SOLVER_VAR
|
|
29
30
|
from cadwyn._utils import classproperty
|
|
30
31
|
from cadwyn.exceptions import (
|
|
31
32
|
CadwynError,
|
|
@@ -52,10 +53,6 @@ _CADWYN_REQUEST_PARAM_NAME = "cadwyn_request_param"
|
|
|
52
53
|
_CADWYN_RESPONSE_PARAM_NAME = "cadwyn_response_param"
|
|
53
54
|
_P = ParamSpec("_P")
|
|
54
55
|
_R = TypeVar("_R")
|
|
55
|
-
_CURRENT_DEPENDENCY_SOLVER_OPTIONS = Literal["cadwyn", "fastapi"]
|
|
56
|
-
_CURRENT_DEPENDENCY_SOLVER_VAR: ContextVar[_CURRENT_DEPENDENCY_SOLVER_OPTIONS] = ContextVar(
|
|
57
|
-
"cadwyn_dependencies_dry_run"
|
|
58
|
-
)
|
|
59
56
|
|
|
60
57
|
PossibleInstructions: TypeAlias = Union[
|
|
61
58
|
AlterSchemaSubInstruction, AlterEndpointSubInstruction, AlterEnumSubInstruction, SchemaHadInstruction, staticmethod
|
|
@@ -387,7 +384,7 @@ class VersionBundle:
|
|
|
387
384
|
request.scope["headers"] = tuple((key.encode(), value.encode()) for key, value in request_info.headers.items())
|
|
388
385
|
del request._headers
|
|
389
386
|
# This gives us the ability to tell the user whether cadwyn is running its dependencies or FastAPI
|
|
390
|
-
|
|
387
|
+
CURRENT_DEPENDENCY_SOLVER_VAR.set("cadwyn")
|
|
391
388
|
# Remember this: if len(body_params) == 1, then route.body_schema == route.dependant.body_params[0]
|
|
392
389
|
result = await solve_dependencies(
|
|
393
390
|
request=request,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cadwyn
|
|
3
|
-
Version: 5.1
|
|
3
|
+
Version: 5.2.1
|
|
4
4
|
Summary: Production-ready community-driven modern Stripe-like API versioning in FastAPI
|
|
5
5
|
Project-URL: Source code, https://github.com/zmievsa/cadwyn
|
|
6
6
|
Project-URL: Documentation, https://docs.cadwyn.dev
|
|
@@ -36,7 +36,6 @@ Classifier: Typing :: Typed
|
|
|
36
36
|
Requires-Python: >=3.9
|
|
37
37
|
Requires-Dist: backports-strenum<2,>=1.3.1; python_version < '3.11'
|
|
38
38
|
Requires-Dist: fastapi>=0.112.4
|
|
39
|
-
Requires-Dist: issubclass>=0.1.2
|
|
40
39
|
Requires-Dist: jinja2>=3.1.2
|
|
41
40
|
Requires-Dist: pydantic>=2.0.0
|
|
42
41
|
Requires-Dist: starlette>=0.30.0
|
|
@@ -2,17 +2,19 @@ cadwyn/__init__.py,sha256=uXmQDTDNA5BeRlLFn0cmIo6ohXvEApg2FSl2sFb8frw,1120
|
|
|
2
2
|
cadwyn/__main__.py,sha256=fGoKJPNVueqqXW4rqwmRUBBMoDGeLEyATdT-rel5Pvs,2449
|
|
3
3
|
cadwyn/_asts.py,sha256=QvqZmDdwH8U-Ocpj9vYR6MRrIANF8ugk9oZgAo76qLs,5223
|
|
4
4
|
cadwyn/_importer.py,sha256=QV6HqODCG9K2oL4Vc15fAqL2-plMvUWw_cgaj4Ln4C8,1075
|
|
5
|
-
cadwyn/_render.py,sha256=
|
|
5
|
+
cadwyn/_render.py,sha256=VAY2Twd_MfKaC8_X22AMIQd72_UHy87icdAbKL8hd90,5526
|
|
6
6
|
cadwyn/_utils.py,sha256=q_mTtMKTNTDzqCza67XST-jaPSfuTgnFLmOe0dlGeYY,2295
|
|
7
|
-
cadwyn/applications.py,sha256=
|
|
7
|
+
cadwyn/applications.py,sha256=xE-r96qSIWji6-mrpRhQVGTLHEvayfMDi0cRaIVPkds,20777
|
|
8
8
|
cadwyn/changelogs.py,sha256=aBTlsZ8PQpw9t4sSyezNTYDs6CMPtzIGulgAHA1ELPs,19622
|
|
9
|
-
cadwyn/dependencies.py,sha256=
|
|
9
|
+
cadwyn/dependencies.py,sha256=phUJ4Fy3UTegpOfDfHMjxsvASWo-1NQgwqphNnPdoVQ,241
|
|
10
10
|
cadwyn/exceptions.py,sha256=8D1G7ewLrMF5jq7leald1g0ulcH9zQl8ufEK3b7HHAE,1749
|
|
11
|
-
cadwyn/middleware.py,sha256=
|
|
11
|
+
cadwyn/middleware.py,sha256=jWhuISMEMo7kYLMJ8y4wzso1SNSpaW7Zkxocqi9MLEA,4617
|
|
12
12
|
cadwyn/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
13
|
-
cadwyn/route_generation.py,sha256=
|
|
14
|
-
cadwyn/routing.py,sha256=
|
|
13
|
+
cadwyn/route_generation.py,sha256=Po9wC4IvLBgX6EodWH3JFzEO7j3ckoXmIKMO-ubCGcA,25194
|
|
14
|
+
cadwyn/routing.py,sha256=Ii6Qbgm9lGks1IAk-kDuIu_dX3FXsA77KSfGOFmLbgc,7604
|
|
15
15
|
cadwyn/schema_generation.py,sha256=QK_G-G56S1brGTSpEGEE77tbifSi7IzwNK1oiVfMkPA,46850
|
|
16
|
+
cadwyn/_internal/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
17
|
+
cadwyn/_internal/context_vars.py,sha256=VcM8eAoSlvrIMFQhjZmjflV5o1yrPSEZZGkwOK4OSf4,378
|
|
16
18
|
cadwyn/static/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
17
19
|
cadwyn/static/docs.html,sha256=WNm5ANJVy51TcIUFOaqKf1Z8eF86CC85TTHPxACtkzw,3455
|
|
18
20
|
cadwyn/structure/__init__.py,sha256=Wgvjdq3vfl9Yhe-BkcFGAMi_Co11YOfTmJQqgF5Gzx4,655
|
|
@@ -20,10 +22,10 @@ cadwyn/structure/common.py,sha256=YuyfYMxkJcj2c5SFh9teBoEC2xLO5_2QjPzYjwdZcTs,47
|
|
|
20
22
|
cadwyn/structure/data.py,sha256=NWURVnP_84VI2ugp9ppo0Ofyve3pVYjymF9K82Jh-SA,7791
|
|
21
23
|
cadwyn/structure/endpoints.py,sha256=zUgzglNhBPnmWdJ03A8pFT4zPs_lj8nQ7c7Uo2d-ejU,6246
|
|
22
24
|
cadwyn/structure/enums.py,sha256=4FCc9aniLE3VuWAVIacrNP_FWxTIUm9JkeeHA_zZdwQ,1254
|
|
23
|
-
cadwyn/structure/schemas.py,sha256=
|
|
24
|
-
cadwyn/structure/versions.py,sha256=
|
|
25
|
-
cadwyn-5.1.
|
|
26
|
-
cadwyn-5.1.
|
|
27
|
-
cadwyn-5.1.
|
|
28
|
-
cadwyn-5.1.
|
|
29
|
-
cadwyn-5.1.
|
|
25
|
+
cadwyn/structure/schemas.py,sha256=O9yNw1OB0Qz-PvNB0FYlQm34gQsjyG2l9gg9x-RnJIY,10781
|
|
26
|
+
cadwyn/structure/versions.py,sha256=XeaZo6fUjQ_u32JBSLDKcuHkWm_z3z2mB_4yTe_Hr84,34307
|
|
27
|
+
cadwyn-5.2.1.dist-info/METADATA,sha256=HE7pZOYLsS3B8aW5VA-e5_-W1OxAE0T933Zy_0kDWco,4529
|
|
28
|
+
cadwyn-5.2.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
29
|
+
cadwyn-5.2.1.dist-info/entry_points.txt,sha256=mGX8wl-Xfhpr5M93SUmkykaqinUaYAvW9rtDSX54gx0,47
|
|
30
|
+
cadwyn-5.2.1.dist-info/licenses/LICENSE,sha256=KeCWewiDQYpmSnzF-p_0YpoWiyDcUPaCuG8OWQs4ig4,1072
|
|
31
|
+
cadwyn-5.2.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|