spakky-fastapi 1.7.0__py3-none-any.whl → 2.0.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.
@@ -1,24 +0,0 @@
1
- from logging import Logger
2
-
3
- from fastapi import FastAPI
4
- from spakky.application.interfaces.pluggable import IPluggable
5
- from spakky.application.interfaces.registry import IPodRegistry
6
-
7
- from spakky_fastapi.post_processor import FastAPIPostProcessor
8
-
9
-
10
- class FastAPIPlugin(IPluggable):
11
- app: FastAPI
12
- logger: Logger
13
-
14
- def __init__(self, app: FastAPI, logger: Logger) -> None:
15
- self.app = app
16
- self.logger = logger
17
-
18
- def register(self, registry: IPodRegistry) -> None:
19
- registry.register_post_processor(
20
- FastAPIPostProcessor(
21
- self.app,
22
- self.logger,
23
- )
24
- )
@@ -1,69 +0,0 @@
1
- from inspect import signature, getmembers
2
- from logging import Logger
3
- from dataclasses import asdict
4
-
5
- from fastapi import APIRouter, FastAPI
6
- from fastapi.exceptions import FastAPIError
7
- from fastapi.utils import create_model_field # type: ignore
8
- from spakky.application.interfaces.container import IPodContainer
9
- from spakky.application.interfaces.post_processor import IPodPostProcessor
10
- from spakky.pod.order import Order
11
-
12
- from spakky_fastapi.stereotypes.api_controller import (
13
- ApiController,
14
- Route,
15
- WebSocketRoute,
16
- )
17
-
18
-
19
- @Order(1)
20
- class FastAPIPostProcessor(IPodPostProcessor):
21
- __app: FastAPI
22
- __logger: Logger
23
-
24
- def __init__(self, app: FastAPI, logger: Logger) -> None:
25
- super().__init__()
26
- self.__app = app
27
- self.__logger = logger
28
-
29
- def post_process(self, container: IPodContainer, pod: object) -> object:
30
- if not ApiController.exists(pod):
31
- return pod
32
- controller = ApiController.get(pod)
33
- router: APIRouter = APIRouter(prefix=controller.prefix, tags=controller.tags)
34
- for name, method in getmembers(pod, callable):
35
- route: Route | None = Route.get_or_none(method)
36
- websocket_route: WebSocketRoute | None = WebSocketRoute.get_or_none(method)
37
- if route is None and websocket_route is None:
38
- continue
39
- if route is not None:
40
- # pylint: disable=line-too-long
41
- self.__logger.info(
42
- f"[{type(self).__name__}] {route.methods!r} {controller.prefix}{route.path} -> {method.__qualname__}"
43
- )
44
- if route.name is None:
45
- route.name = " ".join([x.capitalize() for x in name.split("_")])
46
- if route.description is None:
47
- route.description = method.__doc__
48
- if route.response_model is None:
49
- return_annotation: type | None = signature(method).return_annotation
50
- if return_annotation is not None:
51
- try:
52
- create_model_field("", return_annotation)
53
- except FastAPIError:
54
- pass
55
- else:
56
- route.response_model = return_annotation
57
- router.add_api_route(endpoint=method, **asdict(route))
58
- if websocket_route is not None:
59
- # pylint: disable=line-too-long
60
- self.__logger.info(
61
- f"[{type(self).__name__}] [WebSocket] {controller.prefix}{websocket_route.path} -> {method.__qualname__}"
62
- )
63
- if websocket_route.name is None:
64
- websocket_route.name = " ".join(
65
- [x.capitalize() for x in name.split("_")]
66
- )
67
- router.add_api_websocket_route(endpoint=method, **asdict(websocket_route))
68
- self.__app.include_router(router)
69
- return pod
@@ -1,16 +0,0 @@
1
- spakky_fastapi/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- spakky_fastapi/aspects/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- spakky_fastapi/aspects/authenticate.py,sha256=Nzyh7iVJy5OmQ3x2ZCPobhPNWgvK604IHaN0pmTdjkI,3997
4
- spakky_fastapi/error.py,sha256=gLZObCZQpBjFmUstRWNDWy2if5DvNIY3WwY6jruwhak,1833
5
- spakky_fastapi/middlewares/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- spakky_fastapi/middlewares/error_handling.py,sha256=_ThkgNkDjVzegxz-QDpMxp1-grG1gx5vrhF4o3Lb2hE,1211
7
- spakky_fastapi/plugins/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
- spakky_fastapi/plugins/authenticate.py,sha256=63tsHFjEzHklsmNyjPoksqiwiwo04h1dJjpzJq9pRf0,434
9
- spakky_fastapi/plugins/fast_api.py,sha256=K09znsenVDu7t-NNPSRtNxX7nzutDxBJqUGy20yT3oM,645
10
- spakky_fastapi/post_processor.py,sha256=bwKkIRJrL6TwmIkV0pobkIRpjmCvhuYT6UOg1kbEHpg,2970
11
- spakky_fastapi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
- spakky_fastapi/stereotypes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
- spakky_fastapi/stereotypes/api_controller.py,sha256=MuZPHEv41KNi2dhZOWCigBSBOp6_JZ6ZUgvNfHulvWU,19330
14
- spakky_fastapi-1.7.0.dist-info/METADATA,sha256=3lmGxpIfMOY0tYBkj17_I3ZMTlqxys1BPfJM6HjYysM,1854
15
- spakky_fastapi-1.7.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
16
- spakky_fastapi-1.7.0.dist-info/RECORD,,
File without changes