Skip to content

Commit

Permalink
Implement user facing interface for ConnexionMiddleware (#1621)
Browse files Browse the repository at this point in the history
This PR adds an interface for the ConnexionMiddleware, similar to the
interface of the Connexion Apps.

The Connexion Apps are now a simple wrapper around the
ConnexionMiddleware and framework app, delegating the work to the
middleware. This enables a similar interface and behavior for users when
using either the middleware or apps.

The arguments are repeated everywhere there is a user interface, but are
parsed in a central place. Repeating the arguments is not DRY, but
needed to provide users with IDE autocomplete, typing, etc. They are
parsed in a single `_Options` class, which also provides a mechanism to
set default options on an App level, and override them on the more
granular API level.

This makes the long list of provided parameters a lot more manageable,
so I would like to use it for the `Jsonifier` as well, and re-add the
`debug` and `extra_files` arguments which I have dropped in previous
PRs. I'll submit a separate PR for this.

I renamed the `options` parameter to `swagger_ui_options` since it only
contains swagger UI options. This is a breaking change though, and we'll
need to highlight this upon release.

We still have quite a lot of `App`, `MiddlewareApp`, and abstract
classes. It would be great if we could find a way to reduce those
further, or at least find better naming to make it more clear what each
one does 🙂 .

Finally, I added examples on how the middleware can be used with third
party frameworks under `examples/frameworks`. Currently there's an
example for Starlette and Quart, but this should be easy to extend. They
also show how the `ASGIDecorator` and `StarletteDecorator` from my
previous PR can be used.
  • Loading branch information
RobbeSneyders committed Jan 26, 2023
1 parent 2bf18f6 commit edb0381
Show file tree
Hide file tree
Showing 47 changed files with 1,471 additions and 1,203 deletions.
9 changes: 4 additions & 5 deletions connexion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@

import werkzeug.exceptions as exceptions # NOQA

from .apis import AbstractAPI # NOQA
from .apps import AbstractApp # NOQA
from .apps.async_app import AsyncApp
from .apps.asynchronous import AsyncApp
from .datastructures import NoContent # NOQA
from .exceptions import ProblemException # NOQA
from .problem import problem # NOQA
Expand All @@ -21,14 +20,14 @@
try:
from flask import request # NOQA

from connexion.apis.flask_api import FlaskApi # NOQA
from connexion.apps.flask_app import FlaskApp
from connexion.apps.flask import FlaskApi, FlaskApp
except ImportError as e: # pragma: no cover
_flask_not_installed_error = not_installed_error(e)
FlaskApi = _flask_not_installed_error # type: ignore
FlaskApp = _flask_not_installed_error # type: ignore

from connexion.apps.async_app import AsyncApi, AsyncApp, ConnexionMiddleware
from connexion.apps.asynchronous import AsyncApi, AsyncApp
from connexion.middleware import ConnexionMiddleware

App = FlaskApp
Api = FlaskApi
Expand Down
16 changes: 0 additions & 16 deletions connexion/apis/__init__.py

This file was deleted.

219 changes: 0 additions & 219 deletions connexion/apis/abstract.py

This file was deleted.

100 changes: 0 additions & 100 deletions connexion/apis/flask_api.py

This file was deleted.

0 comments on commit edb0381

Please sign in to comment.