Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Request argument schema
1 participant