marshmallow-jsonapi icon indicating copy to clipboard operation
marshmallow-jsonapi copied to clipboard

Add Fields and Parser mixin to facilitate query parameter parsing with webargs

Open multimeric opened this issue 6 years ago • 1 comments

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'])

multimeric avatar Oct 03 '19 08:10 multimeric

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

multimeric avatar Oct 10 '19 06:10 multimeric