diff --git a/serde_valid/tests/length_test.rs b/serde_valid/tests/length_test.rs index 68ffd30..57854da 100644 --- a/serde_valid/tests/length_test.rs +++ b/serde_valid/tests/length_test.rs @@ -210,6 +210,35 @@ fn length_option_type_is_ok() { assert!(s.validate().is_ok()); } +#[test] +fn length_option_type_is_err() { + #[derive(Validate)] + struct TestStruct { + #[validate(min_length = 0)] + #[validate(max_length = 5)] + val: Option, + } + + let s = TestStruct { + val: Some(String::from("abcdefg")), + }; + + assert_eq!( + s.validate().unwrap_err().to_string(), + json!( + { + "errors":[], + "properties":{ + "val":{ + "errors": ["The length of the value must be `<= 5`."] + } + } + } + ) + .to_string() + ); +} + #[test] fn length_nested_option_type_is_ok() { #[derive(Validate)] diff --git a/serde_valid_derive/src/types/field.rs b/serde_valid_derive/src/types/field.rs index 3eb73d6..2f8b5bf 100644 --- a/serde_valid_derive/src/types/field.rs +++ b/serde_valid_derive/src/types/field.rs @@ -17,7 +17,9 @@ pub trait Field { fn attrs(&self) -> &Vec; + #[allow(dead_code)] fn vis(&self) -> &syn::Visibility; + #[allow(dead_code)] fn ty(&self) -> &syn::Type; }