flask-rest-jsonapi icon indicating copy to clipboard operation
flask-rest-jsonapi copied to clipboard

Allow providing `get_schema_kwargs` as a function

Open multimeric opened this issue 6 years ago • 1 comments
trafficstars

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.

multimeric avatar Nov 11 '19 06:11 multimeric

Coverage Status

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

coveralls avatar Nov 11 '19 06:11 coveralls