Skip to content
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

Remove AbstractSwaggerUIAPI class #1589

Merged
merged 1 commit into from
Sep 18, 2022
Merged
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
2 changes: 1 addition & 1 deletion connexion/apis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
"""


from .abstract import AbstractAPI, AbstractRoutingAPI, AbstractSwaggerUIAPI # NOQA
from .abstract import AbstractAPI, AbstractRoutingAPI # NOQA
32 changes: 0 additions & 32 deletions connexion/apis/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,38 +96,6 @@ def _set_jsonifier(cls):
cls.jsonifier = Jsonifier()


class AbstractSwaggerUIAPI(AbstractSpecAPI):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

if self.options.openapi_spec_available:
self.add_openapi_json()
self.add_openapi_yaml()

if self.options.openapi_console_ui_available:
self.add_swagger_ui()

@abc.abstractmethod
def add_openapi_json(self):
"""
Adds openapi spec to {base_path}/openapi.json
(or {base_path}/swagger.json for swagger2)
"""

@abc.abstractmethod
def add_openapi_yaml(self):
"""
Adds openapi spec to {base_path}/openapi.yaml
(or {base_path}/swagger.yaml for swagger2)
"""

@abc.abstractmethod
def add_swagger_ui(self):
"""
Adds swagger ui to {base_path}/ui/
"""


class AbstractRoutingAPI(AbstractSpecAPI):
def __init__(
self,
Expand Down
13 changes: 10 additions & 3 deletions connexion/middleware/swagger_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from starlette.templating import Jinja2Templates
from starlette.types import ASGIApp, Receive, Scope, Send

from connexion.apis import AbstractSwaggerUIAPI
from connexion.apis.abstract import AbstractSpecAPI
from connexion.middleware import AppMiddleware
from connexion.utils import yamldumper

Expand Down Expand Up @@ -71,11 +71,18 @@ async def default_fn(self, _scope: Scope, receive: Receive, send: Send) -> None:
await self.app(original_scope, receive, send)


class SwaggerUIAPI(AbstractSwaggerUIAPI):
class SwaggerUIAPI(AbstractSpecAPI):
def __init__(self, *args, default: ASGIApp, **kwargs):
super().__init__(*args, **kwargs)

self.router = Router(default=default)

super().__init__(*args, **kwargs)
if self.options.openapi_spec_available:
self.add_openapi_json()
self.add_openapi_yaml()

if self.options.openapi_console_ui_available:
self.add_swagger_ui()

self._templates = Jinja2Templates(
directory=str(self.options.openapi_console_ui_from_dir)
Expand Down