Skip to content

Commit 6c3dd28

Browse files
committed
Fix wrapping of data parsed by schema with many=True
1 parent e03d2a6 commit 6c3dd28

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

flask_apispec/wrapper.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ def call_view(self, *args, **kwargs):
3535
for option in annotation.options:
3636
schema = utils.resolve_instance(option['args'])
3737
parsed = parser.parse(schema, locations=option['kwargs']['locations'])
38-
kwargs.update(parsed)
38+
if getattr(schema, 'many', False):
39+
args += tuple(parsed)
40+
else:
41+
kwargs.update(parsed)
3942
return self.func(*args, **kwargs)
4043

4144
def marshal_result(self, unpacked, status_code):

tests/test_views.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# -*- coding: utf-8 -*-
22

3+
import json
4+
35
from flask import make_response
46
from marshmallow import fields, Schema
57

@@ -28,6 +30,18 @@ def view(**kwargs):
2830
res = client.get('/', {'name': 'freddie'})
2931
assert res.json == {'name': 'freddie'}
3032

33+
def test_use_kwargs_schema_many(self, app, client):
34+
class ArgSchema(Schema):
35+
name = fields.Str()
36+
37+
@app.route('/', methods=('POST',))
38+
@use_kwargs(ArgSchema(many=True), locations=('json',))
39+
def view(*args):
40+
return list(args)
41+
data = [{'name': 'freddie'}, {'name': 'john'}]
42+
res = client.post('/', json.dumps(data), content_type='application/json')
43+
assert res.json == data
44+
3145
def test_use_kwargs_multiple(self, app, client):
3246
@app.route('/')
3347
@use_kwargs({'name': fields.Str()})

0 commit comments

Comments
 (0)