Skip to content

Commit 1c0dd88

Browse files
authored
Merge pull request #64 from decaz/fix-schema-many
Fix wrapping of data parsed by schema with `many=True`
2 parents a104ccd + 6c3dd28 commit 1c0dd88

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

@@ -31,6 +33,18 @@ def view(**kwargs):
3133
res = client.get('/', {'name': 'freddie'})
3234
assert res.json == {'name': 'freddie'}
3335

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

0 commit comments

Comments
 (0)