cadwyn 3.10.0__py3-none-any.whl → 3.11.0__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/applications.py CHANGED
@@ -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()
cadwyn/routing.py CHANGED
@@ -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__(self, *args: Any, api_version_header_name: str, **kwargs: Any):
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
- request_headers = dict(scope["headers"])
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 module must be a package. "{head_schemas_package.__name__}" is not a package.',
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"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cadwyn
3
- Version: 3.10.0
3
+ Version: 3.11.0
4
4
  Summary: Production-ready community-driven modern Stripe-like API versioning in FastAPI
5
5
  Home-page: https://github.com/zmievsa/cadwyn
6
6
  License: MIT
@@ -4,7 +4,7 @@ cadwyn/_asts.py,sha256=S-x9fVKTENZZxwWfabm0PbztcHyX2MJkI6Cwv5XgVrI,10138
4
4
  cadwyn/_compat.py,sha256=6QwtzbXn53mIhEFfEizmFjd-f894oLsM6ITxqq2rCpc,5408
5
5
  cadwyn/_package_utils.py,sha256=trxTYLmppv-10SKhScfyDQJh21rsQGFoLaOtHycKKR0,1443
6
6
  cadwyn/_utils.py,sha256=BFsfZBpdoL5RMAaT1V1cXJVpTZCmwksQ-Le2MTHivGI,4841
7
- cadwyn/applications.py,sha256=Hy9CyQH0TspktcI4oSRcbAcMSmM2K3Ua3hrMvC1of7E,12876
7
+ cadwyn/applications.py,sha256=sz4x_GoD3s1snm3M1Wgx22mdAICQXciVd9rhGWZk0II,12826
8
8
  cadwyn/codegen/README.md,sha256=hc7AE87LsEsvbh-wX1H10JEWh-8bLHoe-1CkY3h00FI,879
9
9
  cadwyn/codegen/__init__.py,sha256=JgddDjxMTjSfVrMXHwNu1ODgdn2QfPWpccrRKquBV6k,355
10
10
  cadwyn/codegen/_common.py,sha256=FTI4fqpUFGBMACVlPiDMHTWhqwW_-zQNa_4Qh7m-hCA,5877
@@ -19,8 +19,8 @@ cadwyn/exceptions.py,sha256=gsb1vszQ2VsnfTBM5B8AYmXwCW0yvA8pJ1GhNkGzgyE,1440
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=DiCeJdM5p36ZBixzxyi3DSxZQhpDbfetXQMhtNwzDfM,34810
23
- cadwyn/routing.py,sha256=S7KQzCuGCiriGwxigw1ZloHLA7OmS7VO54YWtjsryHs,6378
22
+ cadwyn/route_generation.py,sha256=7nHe_IP7Uz1rXmnItJsQ2yIuqe3lRgtOr8_MP_6Vg8c,35704
23
+ cadwyn/routing.py,sha256=nswSMfpGMYk-TSbNY6NmH7NuWM0GoWwK_McTzPiKluk,6392
24
24
  cadwyn/static/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
25
  cadwyn/static/docs.html,sha256=WNm5ANJVy51TcIUFOaqKf1Z8eF86CC85TTHPxACtkzw,3455
26
26
  cadwyn/structure/__init__.py,sha256=HjaNd6H4m4Cia42-dCO7A7sLWuVII7oldjaCabhbs_o,697
@@ -30,9 +30,9 @@ cadwyn/structure/endpoints.py,sha256=VngfAydGBwekhV2tBOtNDPVgl3X1IgYxUCw--VZ5cQY
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=elWGyibosoxFemC19WDAX3APZtI1f4gEh402njZmY4U,36078
34
- cadwyn-3.10.0.dist-info/LICENSE,sha256=KeCWewiDQYpmSnzF-p_0YpoWiyDcUPaCuG8OWQs4ig4,1072
35
- cadwyn-3.10.0.dist-info/METADATA,sha256=Xaxi6Z533Cs80dutkvWbYJxU4XHKhFaoImC9IEhS2ZI,4360
36
- cadwyn-3.10.0.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
37
- cadwyn-3.10.0.dist-info/entry_points.txt,sha256=eO05hLn9GoRzzpwT9GONPmXKsonjuMNssM2D2WHWKGk,46
38
- cadwyn-3.10.0.dist-info/RECORD,,
33
+ cadwyn/structure/versions.py,sha256=aVmI71vBtMpyu9dT5m732feTJWdKOXNpPZQb80G8y9c,36078
34
+ cadwyn-3.11.0.dist-info/LICENSE,sha256=KeCWewiDQYpmSnzF-p_0YpoWiyDcUPaCuG8OWQs4ig4,1072
35
+ cadwyn-3.11.0.dist-info/METADATA,sha256=6bHtgZeWr378YbnPVUELXHlcyga0DH0UFJbsmK-Nsb8,4360
36
+ cadwyn-3.11.0.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
37
+ cadwyn-3.11.0.dist-info/entry_points.txt,sha256=eO05hLn9GoRzzpwT9GONPmXKsonjuMNssM2D2WHWKGk,46
38
+ cadwyn-3.11.0.dist-info/RECORD,,