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 57c2db2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
26 changes: 26 additions & 0 deletions fps/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import pluggy
from fastapi import FastAPI
from pluggy import PluginManager
from rich.console import Console
from rich.table import Table
from starlette.routing import Mount

from fps import hooks
Expand Down Expand Up @@ -271,6 +273,28 @@ 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 +310,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 57c2db2

Please sign in to comment.