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

Restoring Flask-Injector support by passing "undocumented" path parameters to the handler #526

Merged
merged 3 commits into from
Oct 11, 2017
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
9 changes: 5 additions & 4 deletions connexion/decorators/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,11 @@ def wrapper(request):

# Parse path parameters
path_params = request.path_params
for key, path_param_definitions in path_types.items():
if key in path_params:
kwargs[key] = get_val_from_param(path_params[key],
path_param_definitions)
for key, value in path_params.items():
if key in path_types:
kwargs[key] = get_val_from_param(value, path_types[key])
else: # Assume path params mechanism used for injection
kwargs[key] = value

# Add body parameters
if not has_kwargs and body_name not in arguments:
Expand Down
3 changes: 3 additions & 0 deletions requirements-devel.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
-e git+https://github.com/kennethreitz/requests#egg=requests
-e git+https://github.com/Yelp/swagger_spec_validator.git#egg=swagger-spec-validator
-e git+https://github.com/zalando/python-clickclick.git#egg=clickclick
inflection
mock
pytest
# This repo doesn't have the latest version released on PyPI
# -e hg+https://bitbucket.org/pitrou/pathlib#egg=pathlib
# PyYAML is not that easy to build manually, it may fail.
Expand Down
19 changes: 19 additions & 0 deletions tests/decorators/test_parameter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from connexion.decorators.parameter import parameter_to_arg
# we are using "mock" module here for Py 2.7 support
from mock import MagicMock


def test_injection(monkeypatch):
request = MagicMock(name='request', path_params={'p1': '123'})
request.args = {}
request.headers = {}
request.params = {}

func = MagicMock()

def handler(**kwargs):
func(**kwargs)

parameter_to_arg({}, [], handler)(request)

func.assert_called_with(p1='123')