File tree Expand file tree Collapse file tree 1 file changed +38
-2
lines changed
Expand file tree Collapse file tree 1 file changed +38
-2
lines changed Original file line number Diff line number Diff line change 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
27from 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
743class ConnectionManager :
844 def __init__ (self ):
You can’t perform that action at this time.
0 commit comments