diff --git a/flask_restplus/reqparse.py b/flask_restplus/reqparse.py index d24b4d38..d66ec210 100644 --- a/flask_restplus/reqparse.py +++ b/flask_restplus/reqparse.py @@ -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: diff --git a/tests/test_reqparse.py b/tests/test_reqparse.py index db0bdbbf..42065315 100644 --- a/tests/test_reqparse.py +++ b/tests/test_reqparse.py @@ -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')