diff --git a/schemars/tests/validate.rs b/schemars/tests/validate.rs index c2060e0..c8b6809 100644 --- a/schemars/tests/validate.rs +++ b/schemars/tests/validate.rs @@ -42,6 +42,7 @@ pub struct Struct { #[validate(required)] required_option: Option, #[validate(required)] + #[validate] #[serde(flatten)] required_flattened: Option, } diff --git a/schemars_derive/src/attr/mod.rs b/schemars_derive/src/attr/mod.rs index cc81a92..b1b9f04 100644 --- a/schemars_derive/src/attr/mod.rs +++ b/schemars_derive/src/attr/mod.rs @@ -104,7 +104,7 @@ impl Attrs { for meta_item in attrs .iter() - .flat_map(|attr| get_meta_items(attr, attr_type, errors)) + .flat_map(|attr| get_meta_items(attr, attr_type, errors, ignore_errors)) .flatten() { match &meta_item { @@ -201,6 +201,7 @@ fn get_meta_items( attr: &syn::Attribute, attr_type: &'static str, errors: &Ctxt, + ignore_errors: bool, ) -> Result, ()> { if !attr.path.is_ident(attr_type) { return Ok(Vec::new()); @@ -209,11 +210,15 @@ fn get_meta_items( match attr.parse_meta() { Ok(List(meta)) => Ok(meta.nested.into_iter().collect()), Ok(other) => { - errors.error_spanned_by(other, format!("expected #[{}(...)]", attr_type)); + if !ignore_errors { + errors.error_spanned_by(other, format!("expected #[{}(...)]", attr_type)) + } Err(()) } Err(err) => { - errors.error_spanned_by(attr, err); + if !ignore_errors { + errors.error_spanned_by(attr, err) + } Err(()) } } diff --git a/schemars_derive/src/attr/validation.rs b/schemars_derive/src/attr/validation.rs index 398fa59..1a93a2a 100644 --- a/schemars_derive/src/attr/validation.rs +++ b/schemars_derive/src/attr/validation.rs @@ -99,7 +99,7 @@ impl ValidationAttrs { for meta_item in attrs .iter() - .flat_map(|attr| get_meta_items(attr, attr_type, errors)) + .flat_map(|attr| get_meta_items(attr, attr_type, errors, ignore_errors)) .flatten() { match &meta_item {