Skip to content

Skip response fields where value is None #99

Description

@mjreiss

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}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions