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

Filter by dynamic schema #213

Open nazarlitvin opened 2 years ago

nazarlitvin commented 2 years ago

Hi, in my application, I use before_marshmallow to set the schema based on a user type, in overall it works well, but I faced a few difficulties:

  1. I have to provide a default schema and only then override it. Otherwise, it doesn't work. Like this:
    
    schema = BaseSchema

def before_marshmallow(self, args, kwargs): if (kwargs["user_type"] == "A"): self.schema = SchemaA elif (kwargs["user_type"] == "B"): self.schema = SchemaB



But, again, on overall it's OK. 

2. Much important issue is with filtering. With my approach, I'm only able to filter by fields from BaseSchema. Is there any workaround?