Skip to content

Commit

Permalink
Merge 5eb2147 into 1f07bde
Browse files Browse the repository at this point in the history
  • Loading branch information
aparcar committed Feb 1, 2022
2 parents 1f07bde + 5eb2147 commit 7d2b4a1
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions connexion/apps/flask_app.py
Expand Up @@ -21,8 +21,9 @@


class FlaskApp(AbstractApp):
def __init__(self, import_name, server='flask', **kwargs):
def __init__(self, import_name, server='flask', extra_files=None, **kwargs):
super().__init__(import_name, FlaskApi, server=server, **kwargs)
self.extra_files = extra_files or []

def create_app(self):
app = flask.Flask(self.import_name, **self.server_args)
Expand Down Expand Up @@ -64,13 +65,21 @@ def common_error_handler(self, exception):
def add_api(self, specification, **kwargs):
api = super().add_api(specification, **kwargs)
self.app.register_blueprint(api.blueprint)
if isinstance(specification, (str, pathlib.Path)):
self.extra_files.append(self.specification_dir / specification)
return api

def add_error_handler(self, error_code, function):
# type: (int, FunctionType) -> None
self.app.register_error_handler(error_code, function)

def run(self, port=None, server=None, debug=None, host=None, **options): # pragma: no cover
def run(self,
port=None,
server=None,
debug=None,
host=None,
extra_files=None,
**options): # pragma: no cover
"""
Runs the application on a local development server.
:param host: the host interface to bind on.
Expand All @@ -81,6 +90,8 @@ def run(self, port=None, server=None, debug=None, host=None, **options): # prag
:type server: str | None
:param debug: include debugging information
:type debug: bool
:param extra_files: additional files to be watched by the reloader.
:type extra_files: Optional[Iterable[str | pathlib.Path]]
:param options: options to be forwarded to the underlying server
"""
# this functions is not covered in unit tests because we would effectively testing the mocks
Expand All @@ -99,9 +110,13 @@ def run(self, port=None, server=None, debug=None, host=None, **options): # prag
if debug is not None:
self.debug = debug

if extra_files is not None:
self.extra_files.extend(extra_files)

logger.debug('Starting %s HTTP server..', self.server, extra=vars(self))
if self.server == 'flask':
self.app.run(self.host, port=self.port, debug=self.debug, **options)
self.app.run(self.host, port=self.port, debug=self.debug,
extra_files=self.extra_files, **options)
elif self.server == 'tornado':
try:
import tornado.httpserver
Expand Down

0 comments on commit 7d2b4a1

Please sign in to comment.