Skip to content

Commit 3ba9523

Browse files
committed
Stub router class to attempt auto-asyncapi-registration
1 parent d56ea39 commit 3ba9523

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

src/http_app/routes/ws/chat.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,44 @@
1-
from fastapi import APIRouter
1+
from typing import Optional, Sequence, Callable
2+
3+
from fastapi.types import DecoratedCallable
4+
from typing_extensions import Annotated, Doc
5+
6+
from fastapi import APIRouter, params
27
from starlette.websockets import WebSocket, WebSocketDisconnect
38

4-
router = APIRouter(prefix="/chat")
59

10+
class AsyncAPIEnabledRouter(APIRouter):
11+
def websocket(self, path: Annotated[
12+
str,
13+
Doc(
14+
"""
15+
WebSocket path.
16+
"""
17+
),
18+
], name: Annotated[
19+
Optional[str],
20+
Doc(
21+
"""
22+
A name for the WebSocket. Only used internally.
23+
"""
24+
),
25+
] = None, *, dependencies: Annotated[
26+
Optional[Sequence[params.Depends]],
27+
Doc(
28+
"""
29+
A list of dependencies (using `Depends()`) to be used for this
30+
WebSocket.
31+
32+
Read more about it in the
33+
[FastAPI docs for WebSockets](https://fastapi.tiangolo.com/advanced/websockets/).
34+
"""
35+
),
36+
] = None) -> Callable[[DecoratedCallable], DecoratedCallable]:
37+
route = super().websocket(path, name, dependencies=dependencies)
38+
return route
39+
40+
41+
router = AsyncAPIEnabledRouter(prefix="/chat")
642

743
class ConnectionManager:
844
def __init__(self):

0 commit comments

Comments
 (0)