miLibris / flask-rest-jsonapi

Flask extension to build REST APIs around JSONAPI 1.0 specification.
http://flask-rest-jsonapi.readthedocs.io
MIT License
598 stars 153 forks source link

Allow providing `get_schema_kwargs` as a function #179

Open multimeric opened 4 years ago

multimeric commented 4 years ago

Allows users to provide fields like get_schema_kwargs as functions instead of dictionaries. These functions have access to the view's args and kwargs.

For example:

    class PersonDetail(ResourceDetail):
        schema = person_schema
        data_layer = {
            'model': person_model,
            'session': session,
            'url_field': 'person_id'
        }

        def get_schema_kwargs(self, args, kwargs):
            return dict(
                exclude=['name']
            )

You can still use the simpler method of providing a dictionary, too.

I've added two tests for these two use-cases.

coveralls commented 4 years ago

Coverage Status

Coverage decreased (-0.06%) to 90.709% when pulling 53886869811fce7cc1713f42b7142dfec148048e on TMiguelT:get_schema_kwargs into b44bc08b11213d49fadae873650d3555889052ec on miLibris:master.