flask_accepts
flask_accepts copied to clipboard
Skip response fields where value is None
Hi,
It would be nice if there was a way to filter out any fields where the return value is None
. Flask-RESTX provides this functionality in their marshal_with
decorator, which allows a skip_none
parameter to be passed in (docs). The solution for this would be to allow the responds
decorator to similarly take a skip_none
bool parameter (defaulting to False
), which would filter out any None
value fields produced in the serialized object.
I can try and get a tested solution put into a PR. I think it should just be something like this in def responds
:
if skip_none:
serialized = {k:v for k, v in serialized.items() if v is not None}