cadwyn 3.15.5__py3-none-any.whl → 3.15.6__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/__init__.py +3 -1
- cadwyn/route_generation.py +17 -21
- cadwyn/structure/versions.py +4 -3
- {cadwyn-3.15.5.dist-info → cadwyn-3.15.6.dist-info}/METADATA +1 -1
- {cadwyn-3.15.5.dist-info → cadwyn-3.15.6.dist-info}/RECORD +8 -8
- {cadwyn-3.15.5.dist-info → cadwyn-3.15.6.dist-info}/LICENSE +0 -0
- {cadwyn-3.15.5.dist-info → cadwyn-3.15.6.dist-info}/WHEEL +0 -0
- {cadwyn-3.15.5.dist-info → cadwyn-3.15.6.dist-info}/entry_points.txt +0 -0
cadwyn/__init__.py
CHANGED
|
@@ -7,7 +7,7 @@ from .route_generation import (
|
|
|
7
7
|
VersionedAPIRouter,
|
|
8
8
|
generate_versioned_routers,
|
|
9
9
|
)
|
|
10
|
-
from .structure import VersionBundle
|
|
10
|
+
from .structure import HeadVersion, Version, VersionBundle
|
|
11
11
|
|
|
12
12
|
__version__ = importlib.metadata.version("cadwyn")
|
|
13
13
|
__all__ = [
|
|
@@ -15,6 +15,8 @@ __all__ = [
|
|
|
15
15
|
"VersionedAPIRouter",
|
|
16
16
|
"generate_code_for_versioned_packages",
|
|
17
17
|
"VersionBundle",
|
|
18
|
+
"HeadVersion",
|
|
19
|
+
"Version",
|
|
18
20
|
"generate_versioned_routers",
|
|
19
21
|
"InternalRepresentationOf",
|
|
20
22
|
]
|
cadwyn/route_generation.py
CHANGED
|
@@ -12,6 +12,7 @@ from enum import Enum
|
|
|
12
12
|
from pathlib import Path
|
|
13
13
|
from types import GenericAlias, MappingProxyType, ModuleType
|
|
14
14
|
from typing import (
|
|
15
|
+
TYPE_CHECKING,
|
|
15
16
|
Annotated,
|
|
16
17
|
Any,
|
|
17
18
|
Generic,
|
|
@@ -28,23 +29,18 @@ import fastapi.params
|
|
|
28
29
|
import fastapi.routing
|
|
29
30
|
import fastapi.security.base
|
|
30
31
|
import fastapi.utils
|
|
31
|
-
from fastapi import
|
|
32
|
+
from fastapi import (
|
|
33
|
+
APIRouter,
|
|
34
|
+
Request, # noqa: F401 # We import Request for libraries like svcs that expect it to be in globals
|
|
35
|
+
Response, # noqa: F401 # We import Request for libraries like svcs that expect it to be in globals
|
|
36
|
+
)
|
|
32
37
|
from fastapi._compat import ModelField as FastAPIModelField
|
|
33
38
|
from fastapi._compat import create_body_model
|
|
34
|
-
from fastapi.dependencies.models import Dependant
|
|
35
|
-
from fastapi.dependencies.utils import (
|
|
36
|
-
get_body_field,
|
|
37
|
-
get_dependant,
|
|
38
|
-
get_parameterless_sub_dependant,
|
|
39
|
-
)
|
|
40
39
|
from fastapi.params import Depends
|
|
41
40
|
from fastapi.routing import APIRoute
|
|
42
41
|
from issubclass import issubclass as lenient_issubclass
|
|
43
42
|
from pydantic import BaseModel
|
|
44
|
-
from starlette.routing import
|
|
45
|
-
BaseRoute,
|
|
46
|
-
request_response,
|
|
47
|
-
)
|
|
43
|
+
from starlette.routing import BaseRoute
|
|
48
44
|
from typing_extensions import Self, assert_never, deprecated
|
|
49
45
|
|
|
50
46
|
from cadwyn._compat import get_annotation_from_model_field, model_fields, rebuild_fastapi_body_param
|
|
@@ -68,6 +64,9 @@ from cadwyn.structure.endpoints import (
|
|
|
68
64
|
)
|
|
69
65
|
from cadwyn.structure.versions import _CADWYN_REQUEST_PARAM_NAME, _CADWYN_RESPONSE_PARAM_NAME, VersionChange
|
|
70
66
|
|
|
67
|
+
if TYPE_CHECKING:
|
|
68
|
+
from fastapi.dependencies.models import Dependant
|
|
69
|
+
|
|
71
70
|
_T = TypeVar("_T", bound=Callable[..., Any])
|
|
72
71
|
_R = TypeVar("_R", bound=fastapi.routing.APIRouter)
|
|
73
72
|
# This is a hack we do because we can't guarantee how the user will use the router.
|
|
@@ -308,7 +307,7 @@ class _EndpointTransformer(Generic[_R]):
|
|
|
308
307
|
|
|
309
308
|
def _replace_internal_representation_with_the_versioned_schema(
|
|
310
309
|
self,
|
|
311
|
-
copy_of_dependant: Dependant,
|
|
310
|
+
copy_of_dependant: "Dependant",
|
|
312
311
|
schema_to_internal_request_body_representation: dict[type[BaseModel], type[BaseModel]],
|
|
313
312
|
):
|
|
314
313
|
body_param: FastAPIModelField = copy_of_dependant.body_params[0]
|
|
@@ -658,15 +657,12 @@ def _modify_callable(
|
|
|
658
657
|
|
|
659
658
|
|
|
660
659
|
def _remake_endpoint_dependencies(route: fastapi.routing.APIRoute):
|
|
661
|
-
|
|
660
|
+
# Unlike get_dependant, APIRoute is the public API of FastAPI and it's (almost) guaranteed to be stable.
|
|
661
|
+
|
|
662
|
+
route_copy = fastapi.routing.APIRoute(route.path, route.endpoint, dependencies=route.dependencies)
|
|
663
|
+
route.dependant = route_copy.dependant
|
|
664
|
+
route.body_field = route_copy.body_field
|
|
662
665
|
_add_request_and_response_params(route)
|
|
663
|
-
route.body_field = get_body_field(dependant=route.dependant, name=route.unique_id)
|
|
664
|
-
for depends in route.dependencies[::-1]:
|
|
665
|
-
route.dependant.dependencies.insert(
|
|
666
|
-
0,
|
|
667
|
-
get_parameterless_sub_dependant(depends=depends, path=route.path_format),
|
|
668
|
-
)
|
|
669
|
-
route.app = request_response(route.get_route_handler())
|
|
670
666
|
|
|
671
667
|
|
|
672
668
|
def _add_request_and_response_params(route: APIRoute):
|
|
@@ -681,7 +677,7 @@ def _add_data_migrations_to_route(
|
|
|
681
677
|
head_route: Any,
|
|
682
678
|
template_body_field: type[BaseModel] | None,
|
|
683
679
|
template_body_field_name: str | None,
|
|
684
|
-
dependant_for_request_migrations: Dependant,
|
|
680
|
+
dependant_for_request_migrations: "Dependant",
|
|
685
681
|
versions: VersionBundle,
|
|
686
682
|
):
|
|
687
683
|
if not (route.dependant.request_param_name and route.dependant.response_param_name): # pragma: no cover
|
cadwyn/structure/versions.py
CHANGED
|
@@ -285,6 +285,8 @@ class VersionBundle:
|
|
|
285
285
|
raise CadwynStructureError(
|
|
286
286
|
"Versions are not sorted correctly. Please sort them in descending order.",
|
|
287
287
|
)
|
|
288
|
+
if not self.versions:
|
|
289
|
+
raise CadwynStructureError("You must define at least one non-head version in a VersionBundle.")
|
|
288
290
|
if self.versions[-1].version_changes:
|
|
289
291
|
raise CadwynStructureError(
|
|
290
292
|
f'The first version "{self.versions[-1].value}" cannot have any version changes. '
|
|
@@ -325,7 +327,7 @@ class VersionBundle:
|
|
|
325
327
|
raise CadwynStructureError(
|
|
326
328
|
f'The head schemas package must be a package. "{head_schemas_package.__name__}" is not a package.',
|
|
327
329
|
)
|
|
328
|
-
elif head_schemas_package.__name__.endswith(".head"):
|
|
330
|
+
elif head_schemas_package.__name__.endswith(".head") or head_schemas_package.__name__ == "head":
|
|
329
331
|
return "head"
|
|
330
332
|
elif head_schemas_package.__name__.endswith(".latest"):
|
|
331
333
|
warnings.warn(
|
|
@@ -463,7 +465,6 @@ class VersionBundle:
|
|
|
463
465
|
request.scope["headers"] = tuple((key.encode(), value.encode()) for key, value in request_info.headers.items())
|
|
464
466
|
del request._headers
|
|
465
467
|
# Remember this: if len(body_params) == 1, then route.body_schema == route.dependant.body_params[0]
|
|
466
|
-
|
|
467
468
|
dependencies, errors, _, _, _ = await solve_dependencies(
|
|
468
469
|
request=request,
|
|
469
470
|
response=response,
|
|
@@ -803,7 +804,7 @@ async def _get_body(
|
|
|
803
804
|
) from e
|
|
804
805
|
except HTTPException:
|
|
805
806
|
raise
|
|
806
|
-
except Exception as e:
|
|
807
|
+
except Exception as e:
|
|
807
808
|
raise HTTPException(status_code=400, detail="There was an error parsing the body") from e
|
|
808
809
|
return body
|
|
809
810
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
cadwyn/__init__.py,sha256=
|
|
1
|
+
cadwyn/__init__.py,sha256=Wh_CtNgodacy8plxyDXCDb52CDftbql4jGXQ2pldX4s,605
|
|
2
2
|
cadwyn/__main__.py,sha256=cc-5iYItjxRnB09uxuxlEbjrLm1AEhXI2KrI5iakEOw,4376
|
|
3
3
|
cadwyn/_asts.py,sha256=OF1qQKPqTbgYhH1tYF-MB8CCU0r6YITZpMFegzmk0Ic,10118
|
|
4
4
|
cadwyn/_compat.py,sha256=yAPmfGl2vVEYXlNHHPMoa2JkEJCVPjbP_Uz0WOIVOp4,5494
|
|
@@ -19,7 +19,7 @@ cadwyn/exceptions.py,sha256=aJKx1qgzZqShL4MX3COjS780qzNJcdZFeGzYYa5gbzw,1726
|
|
|
19
19
|
cadwyn/main.py,sha256=kt2Vn7TIA4ZnD_xrgz57TOjUk-4zVP8SV8nuTZBEaaU,218
|
|
20
20
|
cadwyn/middleware.py,sha256=8cuBri_yRkl0goe6G0MLwtL04WGbW9Infah3wy9hUVM,3372
|
|
21
21
|
cadwyn/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
22
|
-
cadwyn/route_generation.py,sha256=
|
|
22
|
+
cadwyn/route_generation.py,sha256=mMfAy-5bz6JmW3JlzM1elG4CFrQgMWoUKLlnqXB5S00,39827
|
|
23
23
|
cadwyn/routing.py,sha256=o6IMjxTxARPa5BxFfsXqOP3bVw9Ya6OBAEbUwH9lMVM,7445
|
|
24
24
|
cadwyn/static/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
25
25
|
cadwyn/static/docs.html,sha256=WNm5ANJVy51TcIUFOaqKf1Z8eF86CC85TTHPxACtkzw,3455
|
|
@@ -30,9 +30,9 @@ cadwyn/structure/endpoints.py,sha256=JhTgVrqLjm5LkE9thjvU1UuWcSCmDgW2bMdqznsZb2Y
|
|
|
30
30
|
cadwyn/structure/enums.py,sha256=iMokxA2QYJ61SzyB-Pmuq3y7KL7-e6TsnjLVUaVZQnw,954
|
|
31
31
|
cadwyn/structure/modules.py,sha256=1FK-lLm-zOTXEvn-QtyBH38aDRht5PDQiZrOPCsBlM4,1268
|
|
32
32
|
cadwyn/structure/schemas.py,sha256=0ylArAkUw626VkUOJSulOwJs7CS6lrGBRECEG5HFD4Q,8897
|
|
33
|
-
cadwyn/structure/versions.py,sha256=
|
|
34
|
-
cadwyn-3.15.
|
|
35
|
-
cadwyn-3.15.
|
|
36
|
-
cadwyn-3.15.
|
|
37
|
-
cadwyn-3.15.
|
|
38
|
-
cadwyn-3.15.
|
|
33
|
+
cadwyn/structure/versions.py,sha256=_NthvvuN7l01J-E2zCZmYtpJZjiVO-wqSDvMSFXhzno,37400
|
|
34
|
+
cadwyn-3.15.6.dist-info/LICENSE,sha256=KeCWewiDQYpmSnzF-p_0YpoWiyDcUPaCuG8OWQs4ig4,1072
|
|
35
|
+
cadwyn-3.15.6.dist-info/METADATA,sha256=lZHxh7mAPk71OebTBR9qv-k6OU5oUnARbzFYbVWqV_k,4397
|
|
36
|
+
cadwyn-3.15.6.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
|
37
|
+
cadwyn-3.15.6.dist-info/entry_points.txt,sha256=eO05hLn9GoRzzpwT9GONPmXKsonjuMNssM2D2WHWKGk,46
|
|
38
|
+
cadwyn-3.15.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|