Add sub-app to generate open api spec
This commit is contained in:
26
aiohttp_pydantic/oas/__init__.py
Normal file
26
aiohttp_pydantic/oas/__init__.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from typing import Iterable
|
||||
from importlib import resources
|
||||
|
||||
import jinja2
|
||||
from aiohttp import web
|
||||
from .view import get_oas, oas_ui
|
||||
from swagger_ui_bundle import swagger_ui_path
|
||||
|
||||
|
||||
def setup(
|
||||
app: web.Application,
|
||||
apps_to_expose: Iterable[web.Application] = (),
|
||||
url_prefix: str = "/oas",
|
||||
enable: bool = True,
|
||||
):
|
||||
if enable:
|
||||
oas_app = web.Application()
|
||||
oas_app["apps to expose"] = tuple(apps_to_expose) or (app,)
|
||||
oas_app["index template"] = jinja2.Template(
|
||||
resources.read_text("aiohttp_pydantic.oas", "index.j2")
|
||||
)
|
||||
oas_app.router.add_get("/spec", get_oas, name="spec")
|
||||
oas_app.router.add_static("/static", swagger_ui_path, name="static")
|
||||
oas_app.router.add_get("", oas_ui, name="index")
|
||||
|
||||
app.add_subapp(url_prefix, oas_app)
|
||||
Reference in New Issue
Block a user