aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
diff options
context:
space:
mode:
authorVincent Prouillet2017-01-16 20:56:05 +0900
committerVincent Prouillet2017-01-16 20:56:05 +0900
commitade9820f497d678296530bbf13bb4de46253d0fe (patch)
treeab821e4d55e1fd2af4d0ef22e5c2336ba69343cf /README.md
parent3302d261744c12001ec2cd980fffd32a829185aa (diff)
downloadvalidator-ade9820f497d678296530bbf13bb4de46253d0fe.tar.bz2
Struct level validation
Diffstat (limited to 'README.md')
-rw-r--r--README.md22
1 files changed, 22 insertions, 0 deletions
diff --git a/README.md b/README.md
index 62db83c..8dbc675 100644
--- a/README.md
+++ b/README.md
@@ -126,3 +126,25 @@ Examples:
```
TODO: have it return a bool and pass a `code` to the `custom` validator instead?
+
+## Struct level validation
+Often, some error validation can only be applied when looking at the full struct, here's how it works here:
+
+
+```rust
+#[derive(Debug, Validate, Deserialize)]
+#[validate(schema(function = "validate_category", skip_on_field_errors = false)]
+struct CategoryData {
+ category: String,
+ name: String,
+}
+```
+
+The function mentioned should return a `Option<(String, String)>` where the tuple is (key error, error code)
+and will be called after validation is done for all fields.
+This means that the error can be reported on an existing field or on a new key.
+
+The `skip_on_field_errors` defaults to `true` if not present and will ensure that the function is not called
+if an error happened while validating the struct fields.
+
+