Error on unknown schemars attr items

This commit is contained in:
Graham Esau 2020-06-04 19:39:57 +01:00
parent a829267111
commit b0a2f9994b
3 changed files with 27 additions and 24 deletions

View file

@ -9,6 +9,9 @@
- `SchemaSettings::bool_schemas` - this has been superseded by the `ReplaceBoolSchemas` visitor - `SchemaSettings::bool_schemas` - this has been superseded by the `ReplaceBoolSchemas` visitor
- `SchemaSettings::allow_ref_siblings` - this has been superseded by the `RemoveRefSiblings` visitor - `SchemaSettings::allow_ref_siblings` - this has been superseded by the `RemoveRefSiblings` visitor
### Fixed:
- **BREAKING CHANGE** unknown items in `#[schemars(...)]` attributes now cause a compilation error (https://github.com/GREsau/schemars/issues/18)
### Deprecated: ### Deprecated:
- `make_extensible`, `schema_for_any`, and `schema_for_none` methods on `SchemaGenerator` - `make_extensible`, `schema_for_any`, and `schema_for_none` methods on `SchemaGenerator`

View file

@ -4,6 +4,7 @@ mod schemars_to_serde;
pub use schemars_to_serde::process_serde_attrs; pub use schemars_to_serde::process_serde_attrs;
use proc_macro2::{Group, Span, TokenStream, TokenTree}; use proc_macro2::{Group, Span, TokenStream, TokenTree};
use quote::ToTokens;
use serde_derive_internals::Ctxt; use serde_derive_internals::Ctxt;
use syn::parse::{self, Parse}; use syn::parse::{self, Parse};
use syn::Meta::{List, NameValue}; use syn::Meta::{List, NameValue};
@ -117,31 +118,30 @@ impl Attrs {
} }
} }
Meta(_meta_item) => { _ if ignore_errors => {}
// TODO uncomment this for 0.8.0 (breaking change)
// https://github.com/GREsau/schemars/issues/18 Meta(meta_item) => {
// if !ignore_errors { let is_known_serde_keyword = schemars_to_serde::SERDE_KEYWORDS
// let path = meta_item .iter()
// .path() .any(|k| meta_item.path().is_ident(k));
// .into_token_stream() if !is_known_serde_keyword {
// .to_string() let path = meta_item
// .replace(' ', ""); .path()
// errors.error_spanned_by( .into_token_stream()
// meta_item.path(), .to_string()
// format!("unknown schemars container attribute `{}`", path), .replace(' ', "");
// ); errors.error_spanned_by(
// } meta_item.path(),
format!("unknown schemars container attribute `{}`", path),
);
}
} }
Lit(_lit) => { Lit(lit) => {
// TODO uncomment this for 0.8.0 (breaking change) errors.error_spanned_by(
// https://github.com/GREsau/schemars/issues/18 lit,
// if !ignore_errors { "unexpected literal in schemars container attribute",
// errors.error_spanned_by( );
// lit,
// "unexpected literal in schemars container attribute",
// );
// }
} }
} }
} }

View file

@ -5,7 +5,7 @@ use syn::parse::Parser;
use syn::{Attribute, Data, Field, Meta, NestedMeta, Variant}; use syn::{Attribute, Data, Field, Meta, NestedMeta, Variant};
// List of keywords that can appear in #[serde(...)]/#[schemars(...)] attributes which we want serde_derive_internals to parse for us. // List of keywords that can appear in #[serde(...)]/#[schemars(...)] attributes which we want serde_derive_internals to parse for us.
static SERDE_KEYWORDS: &[&str] = &[ pub(crate) static SERDE_KEYWORDS: &[&str] = &[
"rename", "rename",
"rename_all", "rename_all",
"deny_unknown_fields", "deny_unknown_fields",