44
55import pluggy
66from fastapi import FastAPI
7+ from fastapi .routing import APIWebSocketRoute
78from pluggy import PluginManager
89from rich .console import Console
910from rich .table import Table
@@ -155,7 +156,7 @@ def _load_configurations() -> None:
155156 logger .info ("No plugin configuration to load" )
156157
157158
158- def _load_routers (app : FastAPI ) -> None :
159+ def _load_routers (app : FastAPI ) -> Dict [ str , APIWebSocketRoute ] :
159160
160161 pm = _get_pluggin_manager (HookType .ROUTER )
161162
@@ -176,6 +177,7 @@ def _load_routers(app: FastAPI) -> None:
176177 registered_paths = {}
177178 registered_routes = {}
178179 registered_mounts = {}
180+ ws_routes = {}
179181
180182 for p , routers in grouped_routers .items ():
181183 p_name = Config .plugin_name (p )
@@ -259,6 +261,13 @@ def _load_routers(app: FastAPI) -> None:
259261 tags = tags ,
260262 )
261263 routes_count += len (routes )
264+ ws_routes .update (
265+ {
266+ tags [0 ]: route
267+ for route in routes
268+ if isinstance (route , APIWebSocketRoute )
269+ }
270+ )
262271
263272 if router_mounts :
264273 for m in router_mounts .values ():
@@ -272,20 +281,27 @@ def _load_routers(app: FastAPI) -> None:
272281 else :
273282 logger .info ("No plugin API router to load" )
274283
284+ return ws_routes
285+
275286
276- def show_endpoints (app : FastAPI ):
287+ def show_endpoints (app : FastAPI , ws_routes : Dict [ str , APIWebSocketRoute ] ):
277288 table = Table (title = "API Summary" )
278289 table .add_column ("Path" , justify = "left" , style = "cyan" , no_wrap = True )
279290 table .add_column ("Methods" , justify = "right" , style = "green" )
280291 table .add_column ("Plugin" , style = "magenta" )
281292
293+ # HTTP endpoints
282294 openapi = app .openapi ()
283295 for k , v in openapi ["paths" ].items ():
284296 path = k
285297 methods = ", " .join ([method .upper () for method in v .keys ()])
286- plugin = ", " .join ({tag for i in v .values () for tag in i [ "tags" ] })
298+ plugin = ", " .join ({i [ "tags" ][ 0 ] for i in v .values ()})
287299 table .add_row (path , methods , plugin )
288300
301+ # websockets endpoints
302+ for plugin , ws_route in ws_routes .items ():
303+ table .add_row (f"[cyan on red]{ ws_route .path } [/]" , "WEBSOCKET" , plugin )
304+
289305 console = Console ()
290306 with console .capture () as capture :
291307 console .print ()
@@ -305,11 +321,11 @@ def create_app():
305321 fps_config = Config (FPSConfig )
306322 app = FastAPI (** fps_config .__dict__ )
307323
308- _load_routers (app )
324+ ws_routes = _load_routers (app )
309325 _load_exceptions_handlers (app )
310326
311327 Config .check_not_used_sections ()
312328
313- show_endpoints (app )
329+ show_endpoints (app , ws_routes )
314330
315331 return app
0 commit comments