Support for #[schemars(crate = "...")] (#80)
This commit is contained in:
parent
ebd7ff32ce
commit
b2b733ba5c
6 changed files with 87 additions and 10 deletions
|
@ -11,6 +11,10 @@ use syn::Meta::{List, NameValue};
|
|||
use syn::MetaNameValue;
|
||||
use syn::NestedMeta::{Lit, Meta};
|
||||
|
||||
// FIXME using the same struct for containers+variants+fields means that
|
||||
// with/schema_with are accepted (but ignored) on containers, and
|
||||
// repr/crate_name are accepted (but ignored) on variants and fields etc.
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct Attrs {
|
||||
pub with: Option<WithAttr>,
|
||||
|
@ -19,6 +23,7 @@ pub struct Attrs {
|
|||
pub deprecated: bool,
|
||||
pub examples: Vec<syn::Path>,
|
||||
pub repr: Option<syn::Type>,
|
||||
pub crate_name: Option<syn::Path>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -123,6 +128,16 @@ impl Attrs {
|
|||
}
|
||||
}
|
||||
|
||||
Meta(NameValue(m)) if m.path.is_ident("crate") => {
|
||||
if let Ok(p) = parse_lit_into_path(errors, attr_type, "crate", &m.lit) {
|
||||
if self.crate_name.is_some() {
|
||||
duplicate_error(m)
|
||||
} else {
|
||||
self.crate_name = Some(p)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_ if ignore_errors => {}
|
||||
|
||||
Meta(meta_item) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue