apryor6 / flask_accepts

Easy, opinionated Flask input/output handling mixing Marshmallow with flask-restx
BSD 3-Clause "New" or "Revised" License
169 stars 40 forks source link

Option to skip response fields where value is None #100

Closed mjreiss closed 3 years ago

mjreiss commented 3 years ago

Resolves issue https://github.com/apryor6/flask_accepts/issues/99.

Why

It would be nice if there was a way to filter out any fields where the return value is None. For some responses, if a value is not present then it is better to not return the field all together rather than return a JSON null. Flask-RESTX provides this functionality in their marshal_with decorator, which allows a skip_none parameter to be passed in (docs). The proposed 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.

In this PR

apryor6 commented 3 years ago

Available in 0.17.7