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 X-Total-Count header to the listing resources to enable pagination #55

Closed
frol opened this issue Mar 30, 2017 · 0 comments
Closed

Comments

@frol
Copy link
Owner

frol commented Mar 30, 2017

I would expect to return a lazy queryset from the resource method handler, and some smart (explicit) magic will take care of OpenAPI/Swagger documentation, offsetting and limiting the data, and setting X-Total-Count header to the response.

There are a few solutions I have in mind, but none of them is perfect to me:

  • Wrap the @api.response() decorator, so we have the input parameters available, the original response, and the control over serialization:

    @api.route('/my_resources/')
    class MyResources(Resource):
        @parameters.MyParametersInheritedFromPaginationParameters().paginate(
            api.response(schemas.MySchema)
        )
        def get(self, args):
             return models.MyResource.query.all()

    or

    @api.route('/my_resources/')
    class MyResources(Resource):
        @api.parameters(parameters.MyParametersInheritedFromPaginationParameters())
        @api.paginate(
            api.response(schemas.MySchema)
        )
        def get(self, args):
             return models.MyResource.query.all()
  • Extend the @api.response decorator to have hooks before the object gets dumped with a schema (so we can limit and offset the queryset), and after the Response is generated (so we can inject the header)

References:

P.S. To document the headers in Swagger.json, we need the latest master of flask-restplus (the latest 0.10.1 release doesn't include the fix for noirbizarre/flask-restplus#119).

khorolets added a commit to khorolets/flask-restplus-server-example that referenced this issue Sep 27, 2018
khorolets added a commit to khorolets/flask-restplus-server-example that referenced this issue Sep 27, 2018
khorolets added a commit to khorolets/flask-restplus-server-example that referenced this issue Sep 27, 2018
@frol frol closed this as completed in #122 Sep 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant