marshmallow-jsonapi
marshmallow-jsonapi copied to clipboard
Add Fields and Parser mixin to facilitate query parameter parsing with webargs
Closes #257.
This PR doesn't provide a pre-built schema per-se, because your JSON API implementation may or may not implement all of the query parameters. For this reason, this only adds Field subclasses that you can use in your schemas:
from marshmallow_jsonapi import query_fields as qf
from webargs.flaskparser import FlaskParser
from marshmallow import Schema
# Setup the parser, with a custom `parse_querystring`
class FlaskJsonApiParser(NestedQueryParserMixin, FlaskParser):
pass
parser = FlaskJsonApiParser()
class JsonApiRequestSchema(Schema):
sort = qf.Sort()
include = qf.Include()
fields = qf.Fields()
page = qf.PagePagination()
filter = qf.Filter()
@parser.use_args(JsonApiRequestSchema())
def greet(args):
return 'You requested to include these relationships: ' + ', '.join(args['include'])
Oh, if anyone is interested in accessing these features right now, in case this is not merged or not merged for a long time, I've published the changes as a separate library here: https://github.com/TMiguelT/marshmallow-jsonapi-webargs