as_kwargs=True always?
I like using as_kwargs, coming from flask-apispec which has a @use_kwargs decorator.
Feature request: have a decorator that has as_kwargs=True so I don't have to type it every time
Thanks!
Thanks for the feedback.
I see several options
-
Create a new decorator that would be an alias to
argumentswithas_kwargsset toTrue(your suggestion). -
Add a
DEFAULT_AS_KWARGSclass attribute to set the default value foras_kwargs. -
If we went ahead with https://github.com/marshmallow-code/flask-smorest/issues/44#issuecomment-471619084, we could have
use_argsanduse_kwargsto specify deserialization schemas, andarguments(orparameters) to add extra information in the docs.
I'd like to give it some thought before doing anything.
Meanwhile, if you want to avoid duplication, you can subclass Blueprint to add use_kwargs. It should be straightforward.
Oh and while I'm making a wishlist - always having strict=True enabled would be nice too :)
I think this is a marshmallow issue.
strict is always True in marshmallow 3. If you're starting a new project, you could try to use marshmallow 3.
If you're stuck on marshmallow 2 for now, you may use a BaseSchema but don't erase Meta when subclassing:
class BaseSchema(ma.Schema):
class Meta:
strict = True
class MySchema(BaseSchema):
class Meta(BaseSchema.Meta): # Don't forget to also subclass Meta (or duplicate strict = True below)
fields = ...
@revmischa I'm open to adding a kwarguments decorator. Would you like to submit a PR?
It might be a good idea to edit ArgumentsMixin class as following:
from functools import partial
class ArgumentsMixin:
def kwarguments(self):
return partial(self.arguments, as_kwargs=True)