Closed williamlsh closed 3 months ago
I thought the previous behaviour was a bug (https://github.com/Keats/validator/issues/303) but I guess it makes more sense to handle Option that way
I just encountered a need for custom validators to take &Option<T>
. Use case is conditionally requiring a field to be defined if and only if another field is set to false
(using custom validator args/context for this). If the other field is set to true
then the optional field must be None
.
That sounds like something that should be defined at the schema level. Or make it more like django forms and allow accessing other fields from any field validation function but that's a new feature.
The latest
validator
versionv0.17.0
doesn't align with the following behavior any more for custom function.The custom function must now accept
&Option<T>
as its argument if it corresponds to the type of a struct field, in contrast to its previous behavior, which only accepted&T
even if the actual field type wasOption<T>
.