Added a wrapper for get_oas to throw spec info (#12) (#13)

* Added a wrapper for get_oas to throw spec info (#12)

* Added tests generate_oas

* Moved params to Application

Co-authored-by: Спиненко Иван ispinenko@ussc.ru <ispinenko@ussc.ru>
This commit is contained in:
spinenkoia
2021-04-04 16:22:05 +05:00
committed by GitHub
parent 7492af5acf
commit beb638c0af
9 changed files with 89 additions and 18 deletions

View File

@@ -1,5 +1,5 @@
from importlib import resources
from typing import Iterable
from typing import Iterable, Optional
import jinja2
from aiohttp import web
@@ -13,6 +13,8 @@ def setup(
apps_to_expose: Iterable[web.Application] = (),
url_prefix: str = "/oas",
enable: bool = True,
version_spec: Optional[str] = None,
title_spec: Optional[str] = None,
):
if enable:
oas_app = web.Application()
@@ -20,6 +22,9 @@ def setup(
oas_app["index template"] = jinja2.Template(
resources.read_text("aiohttp_pydantic.oas", "index.j2")
)
oas_app["version_spec"] = version_spec
oas_app["title_spec"] = title_spec
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")