Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion flask_apispec/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ def call_view(self, *args, **kwargs):
parsed = parser.parse(schema, locations=option['kwargs']['locations'])
if getattr(schema, 'many', False):
args += tuple(parsed)
else:
elif getattr(parsed, 'update', False):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is risk of a false-positive here, e.g. model objects with an update method, so I think type-checking is preferable to duck-typing in this case.

I'll make this change myself.

kwargs.update(parsed)
else:
args += (parsed, )

return self.func(*args, **kwargs)

def marshal_result(self, unpacked, status_code):
Expand Down
24 changes: 23 additions & 1 deletion tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json

from flask import make_response
from marshmallow import fields, Schema
from marshmallow import fields, Schema, post_load

from flask_apispec.utils import Ref
from flask_apispec.views import MethodResource
Expand All @@ -30,6 +30,28 @@ def view(**kwargs):
res = client.get('/', {'name': 'freddie'})
assert res.json == {'name': 'freddie'}

def test_use_kwargs_schema_with_post_load(self, app, client):
class User:
def __init__(self, name):
self.name = name

class ArgSchema(Schema):
name = fields.Str()

@post_load
def make_object(self, data):
return User(**data)

@app.route('/', methods=('POST', ))
@use_kwargs(ArgSchema())
def view(user):
assert isinstance(user, User)
return {'name': user.name}

data = {'name': 'freddie'}
res = client.post('/', data)
assert res.json == data

def test_use_kwargs_schema_many(self, app, client):
class ArgSchema(Schema):
name = fields.Str()
Expand Down