Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

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

Open
wants to merge 11 commits into
base: dev
Choose a base branch
from

Conversation

multimeric
Copy link

@multimeric multimeric commented Oct 3, 2019

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 multimeric marked this pull request as ready for review October 4, 2019 07:52
@multimeric multimeric changed the title Add webargs Fields, Mixins and field instances to facilitate query parameter parsing Add Fields and Parser mixin to facilitate query parameter parsing with webargs Oct 7, 2019
@multimeric
Copy link
Author

multimeric commented Oct 10, 2019

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Request argument schema
1 participant