diff --git a/schemars/src/json_schema_impls/decimal.rs b/schemars/src/json_schema_impls/decimal.rs index 6058a7f..d7fc8a1 100644 --- a/schemars/src/json_schema_impls/decimal.rs +++ b/schemars/src/json_schema_impls/decimal.rs @@ -25,7 +25,7 @@ macro_rules! decimal_impl { }; } -#[cfg(feature="rust_decimal")] +#[cfg(feature = "rust_decimal")] decimal_impl!(rust_decimal::Decimal); -#[cfg(feature="bigdecimal")] +#[cfg(feature = "bigdecimal")] decimal_impl!(bigdecimal::BigDecimal); diff --git a/schemars/tests/bound.rs b/schemars/tests/bound.rs index 8df3e91..cb545dd 100644 --- a/schemars/tests/bound.rs +++ b/schemars/tests/bound.rs @@ -18,7 +18,10 @@ impl Iterator for MyIterator { // which MyIterator does not. #[derive(JsonSchema)] #[schemars(bound = "T::Item: JsonSchema", rename = "MyContainer")] -pub struct MyContainer where T: Iterator { +pub struct MyContainer +where + T: Iterator, +{ pub associated: T::Item, pub generic: PhantomData, } diff --git a/schemars_derive/src/attr/mod.rs b/schemars_derive/src/attr/mod.rs index 26c1f3e..f790694 100644 --- a/schemars_derive/src/attr/mod.rs +++ b/schemars_derive/src/attr/mod.rs @@ -27,7 +27,7 @@ pub struct Attrs { pub examples: Vec, pub repr: Option, pub crate_name: Option, - pub is_renamed: bool + pub is_renamed: bool, } #[derive(Debug)] @@ -153,9 +153,7 @@ impl Attrs { } } - Meta(NameValue(m)) if m.path.is_ident("rename") => { - self.is_renamed = true - } + Meta(NameValue(m)) if m.path.is_ident("rename") => self.is_renamed = true, Meta(NameValue(m)) if m.path.is_ident("crate") && attr_type == "schemars" => { if let Ok(p) = parse_lit_into_path(errors, attr_type, "crate", &m.lit) { diff --git a/schemars_derive/src/lib.rs b/schemars_derive/src/lib.rs index 7e7060e..f8173f4 100644 --- a/schemars_derive/src/lib.rs +++ b/schemars_derive/src/lib.rs @@ -95,26 +95,27 @@ fn derive_json_schema( // FIXME improve handling of generic type params which may not implement JsonSchema let type_params: Vec<_> = cont.generics.type_params().map(|ty| &ty.ident).collect(); - let schema_name = if type_params.is_empty() || (cont.attrs.is_renamed && !schema_base_name.contains('{')) { - quote! { - #schema_base_name.to_owned() - } - } else if cont.attrs.is_renamed { - let mut schema_name_fmt = schema_base_name; - for tp in &type_params { - schema_name_fmt.push_str(&format!("{{{}:.0}}", tp)); - } - quote! { - format!(#schema_name_fmt #(,#type_params=#type_params::schema_name())*) - } - } else { - let mut schema_name_fmt = schema_base_name; - schema_name_fmt.push_str("_for_{}"); - schema_name_fmt.push_str(&"_and_{}".repeat(type_params.len() - 1)); - quote! { - format!(#schema_name_fmt #(,#type_params::schema_name())*) - } - }; + let schema_name = + if type_params.is_empty() || (cont.attrs.is_renamed && !schema_base_name.contains('{')) { + quote! { + #schema_base_name.to_owned() + } + } else if cont.attrs.is_renamed { + let mut schema_name_fmt = schema_base_name; + for tp in &type_params { + schema_name_fmt.push_str(&format!("{{{}:.0}}", tp)); + } + quote! { + format!(#schema_name_fmt #(,#type_params=#type_params::schema_name())*) + } + } else { + let mut schema_name_fmt = schema_base_name; + schema_name_fmt.push_str("_for_{}"); + schema_name_fmt.push_str(&"_and_{}".repeat(type_params.len() - 1)); + quote! { + format!(#schema_name_fmt #(,#type_params::schema_name())*) + } + }; let schema_expr = if repr { schema_exprs::expr_for_repr(&cont).map_err(|e| vec![e])?