A mixin that should be inherited by a custom serializer to include the logic for validating warnings.
This mixin works by recursively descending into nested levels of the root serializer,
collecting warnings in a dictionary structure, and raising them at a higher level.
To implement warnings in a custom serializer, two types of methods must be used.
The first type is used to handle field errors: warn_<field name>().
The second type is used for non-field warnings: warn().
Usage:
class NestedSerializer(WarningsSerializerMixin, serializers.Serializer):
baz = serializers.IntegerField()
def warn_baz(self, value):
...
def warn(self, attrs):
....
class RootSerializer(WarningsSerializerMixin, serializers.Serializer):
foo = NestedSerializer()
bar = serializers.CharField()
def warn_bar(self, value):
...
def warn(self, attrs):
...