Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip response fields where value is None #99

Open
mjreiss opened this issue Mar 12, 2021 · 0 comments
Open

Skip response fields where value is None #99

mjreiss opened this issue Mar 12, 2021 · 0 comments

Comments

@mjreiss
Copy link
Contributor

mjreiss commented Mar 12, 2021

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}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant