Skip to content

Show API summary #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions fps/app.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import json
import logging
from types import ModuleType
from typing import Callable, Dict, List

import pluggy
from fastapi import FastAPI
from fastapi.routing import APIWebSocketRoute
from pluggy import PluginManager
from starlette.routing import Mount

Expand Down Expand Up @@ -165,6 +167,7 @@ def _load_routers(app: FastAPI) -> None:
default_model = create_default_plugin_model(p_name)
Config.register(p_name, default_model)

ws_routes = {}
router_impls = pm.hook.router.get_hookimpls()
if router_impls:
grouped_routers = _grouped_hookimpls_results(pm.hook.router)
Expand Down Expand Up @@ -257,6 +260,13 @@ def _load_routers(app: FastAPI) -> None:
tags=tags,
)
routes_count += len(routes)
ws_routes.update(
{
tags[0]: route
for route in routes
if isinstance(route, APIWebSocketRoute)
}
)

if router_mounts:
for m in router_mounts.values():
Expand All @@ -270,6 +280,21 @@ def _load_routers(app: FastAPI) -> None:
else:
logger.info("No plugin API router to load")

fps_config = Config(FPSConfig)
if fps_config.show_endpoints:
openapi = app.openapi()
logger.info("")
for k, v in openapi["paths"].items():
path = k
methods = [method.upper() for method in v.keys()]
plugin = list({i["tags"][0] for i in v.values()})
o = {"path": path, "methods": methods, "plugin": plugin}
logger.info(f"ENDPOINT: {json.dumps(o)}")
for plugin, ws_route in ws_routes.items():
o = {"path": ws_route.path, "methods": ["WEBSOCKET"], "plugin": [plugin]}
logger.info(f"ENDPOINT: {json.dumps(o)}")
logger.info("")


def create_app():

Expand Down
1 change: 1 addition & 0 deletions fps/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class FPSConfig(BaseModel):
# plugins
enabled_plugins: List[str] = []
disabled_plugins: List[str] = []
show_endpoints: bool = False

@validator("enabled_plugins", "disabled_plugins")
def plugins_format(cls, plugins):
Expand Down