Skip to content

Commit

Permalink
Add App(resolver=...) for app-wide default resolver (spec-first#735)
Browse files Browse the repository at this point in the history
* Add App(resolver=...) for app-wide default resolver

* test api.resolver _is_ resolver
  • Loading branch information
dtkav authored and jmcs committed Oct 29, 2018
1 parent 920f13d commit 6bcf2b3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 5 additions & 2 deletions connexion/apps/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class AbstractApp(object):
def __init__(self, import_name, api_cls, port=None, specification_dir='',
host=None, server=None, arguments=None, auth_all_paths=False, debug=False,
options=None):
resolver=None, options=None):
"""
:param import_name: the name of the application package
:type import_name: str
Expand All @@ -32,10 +32,12 @@ def __init__(self, import_name, api_cls, port=None, specification_dir='',
:type auth_all_paths: bool
:param debug: include debugging information
:type debug: bool
:param resolver: Callable that maps operationID to a function
"""
self.port = port
self.host = host
self.debug = debug
self.resolver = resolver
self.import_name = import_name
self.arguments = arguments or {}
self.api_cls = api_cls
Expand Down Expand Up @@ -84,7 +86,7 @@ def set_errors_handlers(self):

def add_api(self, specification, base_path=None, arguments=None,
auth_all_paths=None, validate_responses=False,
strict_validation=False, resolver=Resolver(), resolver_error=None,
strict_validation=False, resolver=None, resolver_error=None,
pythonic_params=False, pass_context_arg_name=None, options=None,
validator_map=None):
"""
Expand Down Expand Up @@ -123,6 +125,7 @@ def add_api(self, specification, base_path=None, arguments=None,
if self.resolver_error is not None:
resolver_error_handler = self._resolver_error_handler

resolver = resolver or self.resolver
resolver = Resolver(resolver) if hasattr(resolver, '__call__') else resolver

auth_all_paths = auth_all_paths if auth_all_paths is not None else self.auth_all_paths
Expand Down
11 changes: 11 additions & 0 deletions tests/api/test_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ def test_app_with_relative_path(simple_api_spec_dir, spec):
assert get_bye.data == b'Goodbye jsantos'


@pytest.mark.parametrize("spec", SPECS)
def test_app_with_resolver(simple_api_spec_dir, spec):
from connexion.resolver import Resolver
resolver = Resolver()
app = App(__name__, port=5001,
specification_dir='..' / simple_api_spec_dir.relative_to(TEST_FOLDER),
resolver=resolver)
api = app.add_api(spec)
assert api.resolver is resolver


@pytest.mark.parametrize("spec", SPECS)
def test_app_with_different_server_option(simple_api_spec_dir, spec):
# Create the app with a relative path and run the test_app testcase below.
Expand Down

0 comments on commit 6bcf2b3

Please sign in to comment.