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

Fix for #725 "Using a list for "Multiple Locations" yields an unexpected exception" #729

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion flask_restplus/reqparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,13 @@ def parse(self, request, bundle_errors=False):
def __schema__(self):
if self.location == 'cookie':
return
if isinstance(self.location, six.string_types):
location = self.location
else:
location = self.location[-1]
param = {
'name': self.name,
'in': LOCATIONS.get(self.location, 'query')
'in': LOCATIONS.get(location, 'query')
}
_handle_arg_type(self, param)
if self.required:
Expand Down
18 changes: 18 additions & 0 deletions tests/test_reqparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,24 @@ def test_files_and_body_location(self):

assert cm.value.msg == "Can't use formData and body at the same time"

def test_location_json_or_values(self):
parser = RequestParser()
parser.add_argument('in_json_or_values', type=str, location=['json', 'values'])
assert parser.__schema__ == [{
'name': 'in_json_or_values',
'type': 'string',
'in': 'query',
}]

def test_location_values_or_json(self):
parser = RequestParser()
parser.add_argument('in_values_or_json', type=str, location=['values', 'json'])
assert parser.__schema__ == [{
'name': 'in_values_or_json',
'type': 'string',
'in': 'body',
}]

def test_models(self):
todo_fields = Model('Todo', {
'task': fields.String(required=True, description='The task details')
Expand Down