diff --git a/docs/src/Attributes/array_max_items.md b/docs/src/Attributes/array_max_items.md new file mode 100644 index 0000000..9ef7987 --- /dev/null +++ b/docs/src/Attributes/array_max_items.md @@ -0,0 +1,17 @@ +# Array: "max_items" validation + +The `#[validate(max_items = ???)]` attribute is used to determine the maximum number of items in an array. + +```rust +# extern crate serde_valid; +use serde_valid::Validate; + +#[derive(Validate)] +struct Data( + #[validate(max_items = 2)] + Vec, +); + +assert!(Data(vec![1, 2]).validate().is_ok()); +assert!(Data(vec![1, 2, 3]).validate().is_err()); +``` diff --git a/docs/src/Attributes/array_min_items.md b/docs/src/Attributes/array_min_items.md new file mode 100644 index 0000000..da7924c --- /dev/null +++ b/docs/src/Attributes/array_min_items.md @@ -0,0 +1,17 @@ +# Array: "min_items" validation + +The `#[validate(min_items = ???)]` attribute is used to determine the minimum number of items in an array. + +```rust +# extern crate serde_valid; +use serde_valid::Validate; + +#[derive(Validate)] +struct Data( + #[validate(min_items = 3)] + Vec, +); + +assert!(Data(vec![1, 2]).validate().is_err()); +assert!(Data(vec![1, 2, 3]).validate().is_ok()); +``` diff --git a/docs/src/Attributes/numeric_exclusive_maximum.md b/docs/src/Attributes/numeric_exclusive_maximum.md index e24cfed..0bb3fee 100644 --- a/docs/src/Attributes/numeric_exclusive_maximum.md +++ b/docs/src/Attributes/numeric_exclusive_maximum.md @@ -15,4 +15,4 @@ struct Data ( assert!(Data(5).validate().is_ok()); assert!(Data(6).validate().is_err()); assert!(Data(7).validate().is_err()); -``` \ No newline at end of file +``` diff --git a/docs/src/Attributes/object_max_properties.md b/docs/src/Attributes/object_max_properties.md new file mode 100644 index 0000000..382cbca --- /dev/null +++ b/docs/src/Attributes/object_max_properties.md @@ -0,0 +1,24 @@ +# Object: "max_properties" validation + +The `#[validate(max_properties = ???)]` attribute is used to determine the maximum number of properties allowed in a map. + +```rust +# extern crate serde_valid; +use serde_valid::Validate; +use std::collections::HashMap; + +#[derive(Validate)] +struct Data( + #[validate(max_properties = 2)] + HashMap, +); + +let mut map = HashMap::new(); +map.insert("key1".to_string(), "value1".to_string()); +map.insert("key2".to_string(), "value2".to_string()); + +assert!(Data(map.clone()).validate().is_ok()); + +map.insert("key3".to_string(), "value3".to_string()); +assert!(Data(map.clone()).validate().is_err()); +``` diff --git a/docs/src/Attributes/object_min_properties.md b/docs/src/Attributes/object_min_properties.md new file mode 100644 index 0000000..9362be4 --- /dev/null +++ b/docs/src/Attributes/object_min_properties.md @@ -0,0 +1,25 @@ +# Object: "min_properties" validation + +The `#[validate(min_properties = ???)]` attribute is used to determine the minimum number of properties allowed in a map. + +```rust +# extern crate serde_valid; +use serde_valid::Validate; +use std::collections::HashMap; + +#[derive(Validate)] +struct Data( + #[validate(min_properties = 3)] + HashMap, +); + +let mut map = HashMap::new(); +map.insert("key1".to_string(), "value1".to_string()); +map.insert("key2".to_string(), "value2".to_string()); + +assert!(Data(map.clone()).validate().is_err()); + +map.insert("key3".to_string(), "value3".to_string()); + +assert!(Data(map.clone()).validate().is_ok()); +``` \ No newline at end of file diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md index 73b4703..e839dc8 100644 --- a/docs/src/SUMMARY.md +++ b/docs/src/SUMMARY.md @@ -10,6 +10,10 @@ - [Numeric: "exclusive_maximum"](./Attributes/numeric_exclusive_maximum.md) - [Numeric: "exclusive_minimum"](./Attributes/numeric_exclusive_minimum.md) - [Numeric: "multiple_of"](./Attributes/numeric_multiple_of.md) + - [Object: "max_properties"](./Attributes/object_max_properties.md) + - [Object: "min_properties"](./Attributes/object_min_properties.md) + - [Array: "max_items"](./Attributes/array_max_items.md) + - [Array: "min_items"](./Attributes/array_min_items.md) - [Nested validation](./Attributes/nested.md) - [Custom Message](./Attributes/custom_message.md) - [Trailt](./trait.md)