cadwyn 3.15.3__py3-none-any.whl → 3.15.3a1__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 +48 -24
- cadwyn/routing.py +4 -31
- {cadwyn-3.15.3.dist-info → cadwyn-3.15.3a1.dist-info}/METADATA +1 -1
- {cadwyn-3.15.3.dist-info → cadwyn-3.15.3a1.dist-info}/RECORD +7 -7
- {cadwyn-3.15.3.dist-info → cadwyn-3.15.3a1.dist-info}/WHEEL +1 -1
- {cadwyn-3.15.3.dist-info → cadwyn-3.15.3a1.dist-info}/LICENSE +0 -0
- {cadwyn-3.15.3.dist-info → cadwyn-3.15.3a1.dist-info}/entry_points.txt +0 -0
cadwyn/applications.py
CHANGED
|
@@ -81,15 +81,18 @@ class Cadwyn(FastAPI):
|
|
|
81
81
|
deprecated: bool | None = None,
|
|
82
82
|
include_in_schema: bool = True,
|
|
83
83
|
swagger_ui_parameters: dict[str, Any] | None = None,
|
|
84
|
-
generate_unique_id_function: Callable[[routing.APIRoute], str] = Default(
|
|
84
|
+
generate_unique_id_function: Callable[[routing.APIRoute], str] = Default(
|
|
85
85
|
generate_unique_id
|
|
86
|
-
),
|
|
86
|
+
), # noqa: B008
|
|
87
87
|
separate_input_output_schemas: bool = True,
|
|
88
88
|
**extra: Any,
|
|
89
89
|
) -> None:
|
|
90
90
|
self.versions = versions
|
|
91
91
|
# TODO: Remove argument entirely in any major version.
|
|
92
|
-
latest_schemas_package =
|
|
92
|
+
latest_schemas_package = (
|
|
93
|
+
extra.pop("latest_schemas_package", None)
|
|
94
|
+
or self.versions.head_schemas_package
|
|
95
|
+
)
|
|
93
96
|
self.versions.head_schemas_package = latest_schemas_package
|
|
94
97
|
self._latest_schemas_package = cast(ModuleType, latest_schemas_package)
|
|
95
98
|
|
|
@@ -145,10 +148,12 @@ class Cadwyn(FastAPI):
|
|
|
145
148
|
"responses": responses,
|
|
146
149
|
"generate_unique_id_function": generate_unique_id_function,
|
|
147
150
|
}
|
|
148
|
-
self.router: _RootHeaderAPIRouter =
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
151
|
+
self.router: _RootHeaderAPIRouter = (
|
|
152
|
+
_RootHeaderAPIRouter( # pyright: ignore[reportIncompatibleVariableOverride]
|
|
153
|
+
**self._kwargs_to_router,
|
|
154
|
+
api_version_header_name=api_version_header_name,
|
|
155
|
+
api_version_var=self.versions.api_version_var,
|
|
156
|
+
)
|
|
152
157
|
)
|
|
153
158
|
|
|
154
159
|
self.docs_url = docs_url
|
|
@@ -168,12 +173,16 @@ class Cadwyn(FastAPI):
|
|
|
168
173
|
)
|
|
169
174
|
|
|
170
175
|
@property # pragma: no cover
|
|
171
|
-
@deprecated(
|
|
176
|
+
@deprecated(
|
|
177
|
+
"It is going to be deleted in the future. Use VersionBundle.head_schemas_package instead"
|
|
178
|
+
)
|
|
172
179
|
def latest_schemas_package(self):
|
|
173
180
|
return self._latest_schemas_package
|
|
174
181
|
|
|
175
182
|
@latest_schemas_package.setter # pragma: no cover
|
|
176
|
-
@deprecated(
|
|
183
|
+
@deprecated(
|
|
184
|
+
"It is going to be deleted in the future. Use VersionBundle.head_schemas_package instead"
|
|
185
|
+
)
|
|
177
186
|
def latest_schemas_package(self, value: ModuleType | None):
|
|
178
187
|
self._latest_schemas_package = value
|
|
179
188
|
|
|
@@ -260,7 +269,9 @@ class Cadwyn(FastAPI):
|
|
|
260
269
|
self.swaggers[header_value_str] = openapi
|
|
261
270
|
|
|
262
271
|
async def openapi_jsons(self, req: Request) -> JSONResponse:
|
|
263
|
-
version = req.query_params.get("version") or req.headers.get(
|
|
272
|
+
version = req.query_params.get("version") or req.headers.get(
|
|
273
|
+
self.router.api_version_header_name
|
|
274
|
+
)
|
|
264
275
|
openapi_of_a_version = self.swaggers.get(version)
|
|
265
276
|
if not openapi_of_a_version:
|
|
266
277
|
raise HTTPException(
|
|
@@ -294,7 +305,9 @@ class Cadwyn(FastAPI):
|
|
|
294
305
|
if version:
|
|
295
306
|
root_path = self._extract_root_path(req)
|
|
296
307
|
openapi_url = root_path + f"{self.openapi_url}?version={version}"
|
|
297
|
-
return get_redoc_html(
|
|
308
|
+
return get_redoc_html(
|
|
309
|
+
openapi_url=openapi_url, title=f"{self.title} - ReDoc"
|
|
310
|
+
)
|
|
298
311
|
|
|
299
312
|
return self._render_docs_dashboard(req, docs_url=cast(str, self.redoc_url))
|
|
300
313
|
|
|
@@ -307,7 +320,10 @@ class Cadwyn(FastAPI):
|
|
|
307
320
|
"docs.html",
|
|
308
321
|
{
|
|
309
322
|
"request": req,
|
|
310
|
-
"table": {
|
|
323
|
+
"table": {
|
|
324
|
+
version: f"{base_url}{docs_url}?version={version}"
|
|
325
|
+
for version in sorted(self.swaggers)
|
|
326
|
+
},
|
|
311
327
|
},
|
|
312
328
|
)
|
|
313
329
|
|
|
@@ -323,28 +339,36 @@ class Cadwyn(FastAPI):
|
|
|
323
339
|
except ValueError as e:
|
|
324
340
|
raise ValueError("header_value should be in ISO 8601 format") from e
|
|
325
341
|
|
|
326
|
-
added_routes: list[BaseRoute] = []
|
|
327
342
|
if header_value_as_dt not in self.router.versioned_routers: # pragma: no branch
|
|
328
|
-
self.router.versioned_routers[header_value_as_dt] = APIRouter(
|
|
329
|
-
|
|
330
|
-
versioned_router = self.router.versioned_routers[header_value_as_dt]
|
|
331
|
-
if self.openapi_url is not None: # pragma: no branch
|
|
332
|
-
versioned_router.add_route(
|
|
333
|
-
path=self.openapi_url,
|
|
334
|
-
endpoint=self.openapi_jsons,
|
|
335
|
-
include_in_schema=False,
|
|
343
|
+
self.router.versioned_routers[header_value_as_dt] = APIRouter(
|
|
344
|
+
**self._kwargs_to_router
|
|
336
345
|
)
|
|
337
|
-
|
|
346
|
+
if self.openapi_url is not None: # pragma: no branch
|
|
347
|
+
self.router.versioned_routers[header_value_as_dt].add_route(
|
|
348
|
+
path=self.openapi_url,
|
|
349
|
+
endpoint=self.openapi_jsons,
|
|
350
|
+
include_in_schema=False,
|
|
351
|
+
)
|
|
338
352
|
|
|
353
|
+
version_router = self.router.versioned_routers[header_value_as_dt]
|
|
354
|
+
added_routes: list[BaseRoute] = []
|
|
339
355
|
added_route_count = 0
|
|
340
356
|
for router in (first_router, *other_routers):
|
|
341
357
|
self.router.versioned_routers[header_value_as_dt].include_router(
|
|
342
358
|
router,
|
|
343
|
-
dependencies=[
|
|
359
|
+
dependencies=[
|
|
360
|
+
Depends(
|
|
361
|
+
_get_api_version_dependency(
|
|
362
|
+
self.router.api_version_header_name, header_value
|
|
363
|
+
)
|
|
364
|
+
)
|
|
365
|
+
],
|
|
344
366
|
)
|
|
345
367
|
added_route_count += len(router.routes)
|
|
346
368
|
|
|
347
|
-
added_routes
|
|
369
|
+
added_routes = (
|
|
370
|
+
version_router.routes[-added_route_count :]
|
|
371
|
+
)
|
|
348
372
|
self.router.routes.extend(added_routes)
|
|
349
373
|
|
|
350
374
|
self.enrich_swagger()
|
cadwyn/routing.py
CHANGED
|
@@ -12,12 +12,7 @@ from starlette.responses import RedirectResponse
|
|
|
12
12
|
from starlette.routing import BaseRoute, Match, Route
|
|
13
13
|
from starlette.types import Receive, Scope, Send
|
|
14
14
|
|
|
15
|
-
from
|
|
16
|
-
|
|
17
|
-
from .route_generation import (
|
|
18
|
-
InternalRepresentationOf,
|
|
19
|
-
generate_versioned_routers,
|
|
20
|
-
)
|
|
15
|
+
from .route_generation import InternalRepresentationOf, generate_versioned_routers # pyright: ignore[reportDeprecated]
|
|
21
16
|
|
|
22
17
|
# TODO: Remove this in a major version. This is only here for backwards compatibility
|
|
23
18
|
__all__ = ["InternalRepresentationOf", "generate_versioned_routers"]
|
|
@@ -74,19 +69,13 @@ class _RootHeaderAPIRouter(APIRouter):
|
|
|
74
69
|
# then the request version is older that the oldest route we have
|
|
75
70
|
_logger.info(
|
|
76
71
|
"Request version is older than the oldest version. No route can match this version",
|
|
77
|
-
extra={
|
|
78
|
-
"oldest_version": self.min_routes_version.isoformat(),
|
|
79
|
-
"request_version": request_version,
|
|
80
|
-
},
|
|
72
|
+
extra={"oldest_version": self.min_routes_version.isoformat(), "request_version": request_version},
|
|
81
73
|
)
|
|
82
74
|
return []
|
|
83
75
|
version_chosen = self.find_closest_date_but_not_new(request_header_value)
|
|
84
76
|
_logger.info(
|
|
85
77
|
"Partial match. The endpoint with a lower version was selected for the API call",
|
|
86
|
-
extra={
|
|
87
|
-
"version_chosen": version_chosen,
|
|
88
|
-
"request_version": request_version,
|
|
89
|
-
},
|
|
78
|
+
extra={"version_chosen": version_chosen, "request_version": request_version},
|
|
90
79
|
)
|
|
91
80
|
return self.versioned_routers[version_chosen].routes
|
|
92
81
|
|
|
@@ -113,26 +102,10 @@ class _RootHeaderAPIRouter(APIRouter):
|
|
|
113
102
|
routes = self.pick_version(request_header_value=header_value)
|
|
114
103
|
await self.process_request(scope=scope, receive=receive, send=send, routes=routes)
|
|
115
104
|
|
|
116
|
-
|
|
117
|
-
def add_api_route(self, *args: Any, **kwargs: Any):
|
|
105
|
+
def add_api_route(self, *args, **kwargs):
|
|
118
106
|
super().add_api_route(*args, **kwargs)
|
|
119
107
|
self.unversioned_routes.append(self.routes[-1])
|
|
120
108
|
|
|
121
|
-
@same_definition_as_in(APIRouter.add_route)
|
|
122
|
-
def add_route(self, *args: Any, **kwargs: Any):
|
|
123
|
-
super().add_route(*args, **kwargs)
|
|
124
|
-
self.unversioned_routes.append(self.routes[-1])
|
|
125
|
-
|
|
126
|
-
@same_definition_as_in(APIRouter.add_api_websocket_route)
|
|
127
|
-
def add_api_websocket_route(self, *args: Any, **kwargs: Any): # pragma: no cover
|
|
128
|
-
super().add_api_websocket_route(*args, **kwargs)
|
|
129
|
-
self.unversioned_routes.append(self.routes[-1])
|
|
130
|
-
|
|
131
|
-
@same_definition_as_in(APIRouter.add_websocket_route)
|
|
132
|
-
def add_websocket_route(self, *args: Any, **kwargs: Any): # pragma: no cover
|
|
133
|
-
super().add_websocket_route(*args, **kwargs)
|
|
134
|
-
self.unversioned_routes.append(self.routes[-1])
|
|
135
|
-
|
|
136
109
|
async def process_request(self, scope: Scope, receive: Receive, send: Send, routes: Sequence[BaseRoute]) -> None:
|
|
137
110
|
"""
|
|
138
111
|
its a copy-paste from starlette.routing.Router
|
|
@@ -4,7 +4,7 @@ cadwyn/_asts.py,sha256=OF1qQKPqTbgYhH1tYF-MB8CCU0r6YITZpMFegzmk0Ic,10118
|
|
|
4
4
|
cadwyn/_compat.py,sha256=yAPmfGl2vVEYXlNHHPMoa2JkEJCVPjbP_Uz0WOIVOp4,5494
|
|
5
5
|
cadwyn/_package_utils.py,sha256=trxTYLmppv-10SKhScfyDQJh21rsQGFoLaOtHycKKR0,1443
|
|
6
6
|
cadwyn/_utils.py,sha256=BFsfZBpdoL5RMAaT1V1cXJVpTZCmwksQ-Le2MTHivGI,4841
|
|
7
|
-
cadwyn/applications.py,sha256=
|
|
7
|
+
cadwyn/applications.py,sha256=nreLcBP8CSc22JLfRWjPP1Ngt4xawTwgl0qTil4d_Hc,17983
|
|
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
|
|
@@ -20,7 +20,7 @@ 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
22
|
cadwyn/route_generation.py,sha256=nn_PWDa2WQOF-z3IOYBfG9K8po0tHm2C_Q0sRJRr5Ck,39843
|
|
23
|
-
cadwyn/routing.py,sha256=
|
|
23
|
+
cadwyn/routing.py,sha256=38-NhKXGQkUlz3zKnfwIIw9QSYz2h2nXEaSMlBkXzoU,6507
|
|
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
|
|
@@ -31,8 +31,8 @@ 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
33
|
cadwyn/structure/versions.py,sha256=PuXYze89tWvLsOOiuAQtYRi-p1ue2FPfBWWR2bl8hLg,37236
|
|
34
|
-
cadwyn-3.15.
|
|
35
|
-
cadwyn-3.15.
|
|
36
|
-
cadwyn-3.15.
|
|
37
|
-
cadwyn-3.15.
|
|
38
|
-
cadwyn-3.15.
|
|
34
|
+
cadwyn-3.15.3a1.dist-info/LICENSE,sha256=KeCWewiDQYpmSnzF-p_0YpoWiyDcUPaCuG8OWQs4ig4,1072
|
|
35
|
+
cadwyn-3.15.3a1.dist-info/METADATA,sha256=aaXSojcoje-vXvK6fGtFVPOJIlDkqjrMWozw2J9md28,4399
|
|
36
|
+
cadwyn-3.15.3a1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
37
|
+
cadwyn-3.15.3a1.dist-info/entry_points.txt,sha256=eO05hLn9GoRzzpwT9GONPmXKsonjuMNssM2D2WHWKGk,46
|
|
38
|
+
cadwyn-3.15.3a1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|