Can't seem to find this anywhere, but a field that allows an incoming value to be matched across several different types/fields would be pretty handy.
Example could be something like this:
fields.Union([fields.Str(validate=validate.Length(max=20)), fields.Int()])
Where if it failed to validate against the first field, it'd go through the rest of the fields provided until it finds one it matches, otherwise raising an error.
There isn't a built-in union field at the moment, and we don't have plans to add one in the near future. Since we won't get to this soon, I'm going to close this issue for now.
If you end up developing this as a separate package, please comment here and add it to the wiki: https://github.com/marshmallow-code/marshmallow/wiki/Ecosystem
Here's an implementation. https://github.com/adamboche/python-marshmallow-union
I've added a link in the wiki as suggested.
What's the recommended way of implementing this with marshmallow? validate?
Most helpful comment
Here's an implementation. https://github.com/adamboche/python-marshmallow-union
I've added a link in the wiki as suggested.