Skip to content

Commit

Permalink
Show API summary
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Dec 22, 2021
1 parent df59b19 commit 2ce73fe
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
27 changes: 27 additions & 0 deletions fps/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from fastapi import FastAPI
from pluggy import PluginManager
from starlette.routing import Mount
from rich.console import Console
from rich.table import Table

from fps import hooks
from fps.config import Config, FPSConfig, create_default_plugin_model
Expand Down Expand Up @@ -271,6 +273,29 @@ def _load_routers(app: FastAPI) -> None:
logger.info("No plugin API router to load")


def show_endpoints(app: FastAPI):
table = Table(title="API Summary")
table.add_column("Path", justify="left", style="cyan", no_wrap=True)
table.add_column("Methods", justify="right", style="green")
table.add_column("Plugin", style="magenta")


openapi = app.openapi()
for k, v in openapi["paths"].items():
path = k
methods = ", ".join([method.upper() for method in v.keys()])
plugin = ", ".join({tag for i in v.values() for tag in i["tags"]})
table.add_row(path, methods, plugin)

console = Console()
with console.capture() as capture:
console.print()
console.print(table)

str_output = capture.get()
logger.info(str_output)


def create_app():

logging.getLogger("fps")
Expand All @@ -286,4 +311,6 @@ def create_app():

Config.check_not_used_sections()

show_endpoints(app)

return app
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ install_requires =
fastapi
pluggy>=1.0,<2.0
click
rich

[options.extras_require]
uvicorn =
Expand Down

0 comments on commit 2ce73fe

Please sign in to comment.