Ignore fields with validation instruction with nest_all_fields#379
Ignore fields with validation instruction with nest_all_fields#379LeMarwin wants to merge 1 commit intoKeats:masterfrom
nest_all_fields#379Conversation
Problem: * `nest_all_fields` adds #[validate(nested)] for all fields, making the macro unusable in a situation where some fields have specific validation instruction. * adding #[validate(skip)] along with other #[validate] attrs skips field validation entirely Solution: only add #[validate(nested)] to fields that don't have other validation attributes
|
How about things like that https://github.com/Keats/validator/blob/master/validator_derive_tests/tests/nested.rs#L273-L336 eg containers where you have length validation but also want to validate the values |
Okay, I missed that usecase since tests didn't break. I guess that makes this PR a breaking change and thus undesirable, since if someone relied on How about adding |
Problem:
nest_all_fieldsadds #[validate(nested)] for all fields, making the macro unusable in a situation where some fields have specific validation instruction.#[validate(skip)]along with other#[validate]attrs skips field validation entirelySolution: only add
#[validate(nested)]to fields that don't have other validation attributes.Essentially this makes
nest_all_fieldssemantically closer tovalidate_all_fieldsbut inserts#[validate(nested)]if no validation instruction is present. But renaming it is a breaking changeConcrete example of what I wanted to enable:
It's obvious that this should work: we gave explicit validation instruction, so there's no need to insert
#[validate(nested)]Moreover, this PR enables something like this:
which follows the same logic as the previous example, and is quite handy in general