Run cargo fmt

This commit is contained in:
Graham Esau 2019-12-29 22:09:54 +00:00
parent 98f981634c
commit 58cc7fac25
22 changed files with 57 additions and 74 deletions

View file

@ -22,11 +22,9 @@ pub struct MyStruct {
} }
#[derive(JsonSchema)] #[derive(JsonSchema)]
pub enum MyEnum { pub enum MyEnum {
StringNewType(String), StringNewType(String),
StructVariant { StructVariant { floats: Vec<f32> },
floats: Vec<f32>,
}
} }
fn main() { fn main() {
@ -131,11 +129,9 @@ pub struct MyStruct {
#[derive(Deserialize, Serialize, JsonSchema)] #[derive(Deserialize, Serialize, JsonSchema)]
#[serde(untagged)] #[serde(untagged)]
pub enum MyEnum { pub enum MyEnum {
StringNewType(String), StringNewType(String),
StructVariant { StructVariant { floats: Vec<f32> },
floats: Vec<f32>,
}
} }
fn main() { fn main() {

View file

@ -38,7 +38,9 @@ mod as_string {
D: Deserializer<'de>, D: Deserializer<'de>,
{ {
let string = String::deserialize(deserializer)?; let string = String::deserialize(deserializer)?;
string.parse().map_err(|_| D::Error::custom("Input was not valid")) string
.parse()
.map_err(|_| D::Error::custom("Input was not valid"))
} }
} }

View file

@ -16,7 +16,7 @@ pub struct MyStruct {
/// # My Amazing Enum /// # My Amazing Enum
#[derive(JsonSchema)] #[derive(JsonSchema)]
pub enum MyEnum { pub enum MyEnum {
/// A wrapper around a `String` /// A wrapper around a `String`
StringNewType(String), StringNewType(String),
/// A struct-like enum variant which contains /// A struct-like enum variant which contains
@ -24,7 +24,7 @@ pub enum MyEnum {
StructVariant { StructVariant {
/// The floats themselves /// The floats themselves
floats: Vec<f32>, floats: Vec<f32>,
} },
} }
fn main() { fn main() {

View file

@ -8,11 +8,9 @@ pub struct MyStruct {
} }
#[derive(JsonSchema)] #[derive(JsonSchema)]
pub enum MyEnum { pub enum MyEnum {
StringNewType(String), StringNewType(String),
StructVariant { StructVariant { floats: Vec<f32> },
floats: Vec<f32>,
}
} }
fn main() { fn main() {

View file

@ -1,6 +1,6 @@
// Pretend that this is somebody else's crate, not a module. // Pretend that this is somebody else's crate, not a module.
mod other_crate { mod other_crate {
// Neither Schemars nor the other crate provides a JsonSchema impl // Neither Schemars nor the other crate provides a JsonSchema impl
// for this struct. // for this struct.
pub struct Duration { pub struct Duration {
pub secs: i64, pub secs: i64,

View file

@ -14,11 +14,9 @@ pub struct MyStruct {
#[derive(Deserialize, Serialize, JsonSchema)] #[derive(Deserialize, Serialize, JsonSchema)]
#[schemars(untagged)] #[schemars(untagged)]
pub enum MyEnum { pub enum MyEnum {
StringNewType(String), StringNewType(String),
StructVariant { StructVariant { floats: Vec<f32> },
floats: Vec<f32>,
}
} }
fn main() { fn main() {

View file

@ -13,11 +13,9 @@ pub struct MyStruct {
#[derive(Deserialize, Serialize, JsonSchema)] #[derive(Deserialize, Serialize, JsonSchema)]
#[serde(untagged)] #[serde(untagged)]
pub enum MyEnum { pub enum MyEnum {
StringNewType(String), StringNewType(String),
StructVariant { StructVariant { floats: Vec<f32> },
floats: Vec<f32>,
}
} }
fn main() { fn main() {

View file

@ -38,7 +38,9 @@ mod as_string {
D: Deserializer<'de>, D: Deserializer<'de>,
{ {
let string = String::deserialize(deserializer)?; let string = String::deserialize(deserializer)?;
string.parse().map_err(|_| D::Error::custom("Input was not valid")) string
.parse()
.map_err(|_| D::Error::custom("Input was not valid"))
} }
} }

View file

@ -16,7 +16,7 @@ pub struct MyStruct {
/// # My Amazing Enum /// # My Amazing Enum
#[derive(JsonSchema)] #[derive(JsonSchema)]
pub enum MyEnum { pub enum MyEnum {
/// A wrapper around a `String` /// A wrapper around a `String`
StringNewType(String), StringNewType(String),
/// A struct-like enum variant which contains /// A struct-like enum variant which contains
@ -24,7 +24,7 @@ pub enum MyEnum {
StructVariant { StructVariant {
/// The floats themselves /// The floats themselves
floats: Vec<f32>, floats: Vec<f32>,
} },
} }
fn main() { fn main() {

View file

@ -8,11 +8,9 @@ pub struct MyStruct {
} }
#[derive(JsonSchema)] #[derive(JsonSchema)]
pub enum MyEnum { pub enum MyEnum {
StringNewType(String), StringNewType(String),
StructVariant { StructVariant { floats: Vec<f32> },
floats: Vec<f32>,
}
} }
fn main() { fn main() {

View file

@ -1,6 +1,6 @@
// Pretend that this is somebody else's crate, not a module. // Pretend that this is somebody else's crate, not a module.
mod other_crate { mod other_crate {
// Neither Schemars nor the other crate provides a JsonSchema impl // Neither Schemars nor the other crate provides a JsonSchema impl
// for this struct. // for this struct.
pub struct Duration { pub struct Duration {
pub secs: i64, pub secs: i64,

View file

@ -14,11 +14,9 @@ pub struct MyStruct {
#[derive(Deserialize, Serialize, JsonSchema)] #[derive(Deserialize, Serialize, JsonSchema)]
#[schemars(untagged)] #[schemars(untagged)]
pub enum MyEnum { pub enum MyEnum {
StringNewType(String), StringNewType(String),
StructVariant { StructVariant { floats: Vec<f32> },
floats: Vec<f32>,
}
} }
fn main() { fn main() {

View file

@ -13,11 +13,9 @@ pub struct MyStruct {
#[derive(Deserialize, Serialize, JsonSchema)] #[derive(Deserialize, Serialize, JsonSchema)]
#[serde(untagged)] #[serde(untagged)]
pub enum MyEnum { pub enum MyEnum {
StringNewType(String), StringNewType(String),
StructVariant { StructVariant { floats: Vec<f32> },
floats: Vec<f32>,
}
} }
fn main() { fn main() {

View file

@ -192,7 +192,7 @@ impl SchemaGenerator {
/// assert_eq!(extensible_schema, extensible_schema2); /// assert_eq!(extensible_schema, extensible_schema2);
/// ``` /// ```
pub fn make_extensible(&self, schema: SchemaObject) -> SchemaObject { pub fn make_extensible(&self, schema: SchemaObject) -> SchemaObject {
if schema.is_ref() && !self.settings().allow_ref_siblings{ if schema.is_ref() && !self.settings().allow_ref_siblings {
SchemaObject { SchemaObject {
subschemas: Some(Box::new(SubschemaValidation { subschemas: Some(Box::new(SubschemaValidation {
all_of: Some(vec![schema.into()]), all_of: Some(vec![schema.into()]),

View file

@ -15,7 +15,11 @@ where
no_ref_schema!(); no_ref_schema!();
fn schema_name() -> String { fn schema_name() -> String {
format!("Array_up_to_size_{}_of_{}", A::CAPACITY, A::Item::schema_name()) format!(
"Array_up_to_size_{}_of_{}",
A::CAPACITY,
A::Item::schema_name()
)
} }
fn json_schema(gen: &mut SchemaGenerator) -> Schema { fn json_schema(gen: &mut SchemaGenerator) -> Schema {

View file

@ -69,8 +69,7 @@ mod tests {
#[test] #[test]
fn schema_for_map_any_value_no_bool_schema() { fn schema_for_map_any_value_no_bool_schema() {
let settings = let settings = SchemaSettings::default().with(|s| s.bool_schemas = BoolSchemas::Disabled);
SchemaSettings::default().with(|s| s.bool_schemas = BoolSchemas::Disabled);
let schema = custom_schema_object_for::<BTreeMap<String, serde_json::Value>>(settings); let schema = custom_schema_object_for::<BTreeMap<String, serde_json::Value>>(settings);
assert_eq!( assert_eq!(
schema.instance_type, schema.instance_type,

View file

@ -32,22 +32,18 @@ macro_rules! forward_impl {
} }
mod array; mod array;
#[cfg(feature = "arrayvec")]
mod arrayvec;
#[cfg(std_atomic)] #[cfg(std_atomic)]
mod atomic; mod atomic;
#[cfg(feature = "chrono")] #[cfg(feature = "chrono")]
mod chrono; mod chrono;
#[cfg(feature = "indexmap")] mod core;
mod indexmap;
#[cfg(feature = "either")] #[cfg(feature = "either")]
mod either; mod either;
#[cfg(feature = "uuid")]
mod uuid;
#[cfg(feature = "smallvec")]
mod smallvec;
#[cfg(feature = "arrayvec")]
mod arrayvec;
mod core;
mod ffi; mod ffi;
#[cfg(feature = "indexmap")]
mod indexmap;
mod maps; mod maps;
#[cfg(num_nonzero_signed)] #[cfg(num_nonzero_signed)]
mod nonzero_signed; mod nonzero_signed;
@ -55,6 +51,10 @@ mod nonzero_unsigned;
mod primitives; mod primitives;
mod sequences; mod sequences;
mod serdejson; mod serdejson;
#[cfg(feature = "smallvec")]
mod smallvec;
mod time; mod time;
mod tuple; mod tuple;
#[cfg(feature = "uuid")]
mod uuid;
mod wrapper; mod wrapper;

View file

@ -16,11 +16,9 @@ pub struct MyStruct {
} }
#[derive(JsonSchema)] #[derive(JsonSchema)]
pub enum MyEnum { pub enum MyEnum {
StringNewType(String), StringNewType(String),
StructVariant { StructVariant { floats: Vec<f32> },
floats: Vec<f32>,
}
} }
fn main() { fn main() {
@ -125,11 +123,9 @@ pub struct MyStruct {
#[derive(Deserialize, Serialize, JsonSchema)] #[derive(Deserialize, Serialize, JsonSchema)]
#[serde(untagged)] #[serde(untagged)]
pub enum MyEnum { pub enum MyEnum {
StringNewType(String), StringNewType(String),
StructVariant { StructVariant { floats: Vec<f32> },
floats: Vec<f32>,
}
} }
fn main() { fn main() {

View file

@ -4,10 +4,10 @@ use util::*;
#[test] #[test]
fn arrayvec() -> TestResult { fn arrayvec() -> TestResult {
test_default_generated_schema::<ArrayVec::<[i32; 16]>>("arrayvec") test_default_generated_schema::<ArrayVec<[i32; 16]>>("arrayvec")
} }
#[test] #[test]
fn arrayvec_string() -> TestResult { fn arrayvec_string() -> TestResult {
test_default_generated_schema::<ArrayString::<[u8; 16]>>("arrayvec_string") test_default_generated_schema::<ArrayString<[u8; 16]>>("arrayvec_string")
} }

View file

@ -1,9 +1,9 @@
mod util; mod util;
use schemars::JsonSchema; use schemars::JsonSchema;
use serde::{Serialize}; use serde::Serialize;
use util::*;
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use util::*;
enum Or<A, B> { enum Or<A, B> {
#[allow(dead_code)] #[allow(dead_code)]

View file

@ -1,6 +1,6 @@
mod util; mod util;
use uuid::Uuid;
use util::*; use util::*;
use uuid::Uuid;
#[test] #[test]
fn uuid() -> TestResult { fn uuid() -> TestResult {

View file

@ -53,7 +53,7 @@ pub fn derive_json_schema(input: proc_macro::TokenStream) -> proc_macro::TokenSt
} }
} }
} }
let schema_name = if type_params.is_empty() { let schema_name = if type_params.is_empty() {
quote! { quote! {
#schema_base_name.to_owned() #schema_base_name.to_owned()
@ -135,7 +135,7 @@ fn schema_for_enum(variants: &[Variant], cattrs: &serde_attr::Container) -> Toke
} }
fn schema_for_external_tagged_enum<'a>( fn schema_for_external_tagged_enum<'a>(
variants: impl Iterator<Item = &'a Variant<'a>> variants: impl Iterator<Item = &'a Variant<'a>>,
) -> TokenStream { ) -> TokenStream {
let (unit_variants, complex_variants): (Vec<_>, Vec<_>) = let (unit_variants, complex_variants): (Vec<_>, Vec<_>) =
variants.partition(|v| is_unit_variant(v)); variants.partition(|v| is_unit_variant(v));
@ -241,9 +241,7 @@ fn schema_for_internal_tagged_enum<'a>(
}) })
} }
fn schema_for_untagged_enum<'a>( fn schema_for_untagged_enum<'a>(variants: impl Iterator<Item = &'a Variant<'a>>) -> TokenStream {
variants: impl Iterator<Item = &'a Variant<'a>>
) -> TokenStream {
let schemas = variants.map(|variant| { let schemas = variants.map(|variant| {
let schema_expr = schema_for_untagged_enum_variant(variant); let schema_expr = schema_for_untagged_enum_variant(variant);
set_metadata_on_schema_from_docs(schema_expr, &variant.original.attrs) set_metadata_on_schema_from_docs(schema_expr, &variant.original.attrs)
@ -257,9 +255,7 @@ fn schema_for_untagged_enum<'a>(
}) })
} }
fn schema_for_untagged_enum_variant( fn schema_for_untagged_enum_variant(variant: &Variant) -> TokenStream {
variant: &Variant
) -> TokenStream {
match variant.style { match variant.style {
Style::Unit => schema_for_unit_struct(), Style::Unit => schema_for_unit_struct(),
Style::Newtype => schema_for_newtype_struct(&variant.fields[0]), Style::Newtype => schema_for_newtype_struct(&variant.fields[0]),