Closed schedutron closed 5 years ago
@akira-dev Could you please help here ?
@schedutron We got the same issue. Our solution was to add a new hook, see https://github.com/geokrety/flask-rest-jsonapi/commit/681c3fc198362ed5609d065aeb417664da0ee291
Please find PR #123
Thanks a lot, @kumy!
We're using flask-rest-jsonapi library for our project, which involves creating a discount code for events. The problem we are facing is that we are unable to make discount code's schema dynamic - i.e., it should change based on the data we receive from clients. Here is the sample POST data:
Based on the
used-for
attribute value, we want the schema to change - if the value isticket
, schema should beDiscountCodeSchemaTicket
and if the value isevent
, it should beDiscountCodeSchemaEvent
. We added this functionality in thebefore_post
method:But the problem is that this method isn't really called "before" the post method, but actually in between, after the schema has already been computed: https://github.com/miLibris/flask-rest-jsonapi/blob/a5ec222e5a55fcdc583a88cb9248977f9200c4d1/flask_rest_jsonapi/resource.py#L160
Thus, the code in
before_post
doesn't make any difference to the schema, and the default schema is chosen everytime.Now, this can be fixed by introducing a method, say
decide_schema()
that does the dynamic schema change before it is computed, but that requires change in this library's code. Since we want our project's code to be self-sufficient, can you suggest a way to accomplish this without making changes to the library code?