Apply clippy fixes
This commit is contained in:
parent
39bae201eb
commit
824993ca76
6 changed files with 26 additions and 28 deletions
|
@ -263,7 +263,7 @@ impl SchemaGenerator {
|
||||||
/// The keys of the returned `Map` are the [schema names](JsonSchema::schema_name), and the values are the schemas
|
/// The keys of the returned `Map` are the [schema names](JsonSchema::schema_name), and the values are the schemas
|
||||||
/// themselves.
|
/// themselves.
|
||||||
pub fn take_definitions(&mut self) -> Map<String, Schema> {
|
pub fn take_definitions(&mut self) -> Map<String, Schema> {
|
||||||
std::mem::replace(&mut self.definitions, Map::default())
|
std::mem::take(&mut self.definitions)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an iterator over the [visitors](SchemaSettings::visitors) being used by this `SchemaGenerator`.
|
/// Returns an iterator over the [visitors](SchemaSettings::visitors) being used by this `SchemaGenerator`.
|
||||||
|
|
|
@ -128,7 +128,7 @@ impl<'a> serde::Serializer for Serializer<'a> {
|
||||||
self.serialize_none()
|
self.serialize_none()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_some<T: ?Sized>(mut self, value: &T) -> Result<Self::Ok, Self::Error>
|
fn serialize_some<T: ?Sized>(self, value: &T) -> Result<Self::Ok, Self::Error>
|
||||||
where
|
where
|
||||||
T: serde::Serialize,
|
T: serde::Serialize,
|
||||||
{
|
{
|
||||||
|
@ -153,7 +153,7 @@ impl<'a> serde::Serializer for Serializer<'a> {
|
||||||
if self.gen.settings().option_add_null_type {
|
if self.gen.settings().option_add_null_type {
|
||||||
schema = match schema {
|
schema = match schema {
|
||||||
Schema::Bool(true) => Schema::Bool(true),
|
Schema::Bool(true) => Schema::Bool(true),
|
||||||
Schema::Bool(false) => <()>::json_schema(&mut self.gen),
|
Schema::Bool(false) => <()>::json_schema(self.gen),
|
||||||
Schema::Object(SchemaObject {
|
Schema::Object(SchemaObject {
|
||||||
instance_type: Some(ref mut instance_type),
|
instance_type: Some(ref mut instance_type),
|
||||||
..
|
..
|
||||||
|
@ -163,7 +163,7 @@ impl<'a> serde::Serializer for Serializer<'a> {
|
||||||
}
|
}
|
||||||
schema => SchemaObject {
|
schema => SchemaObject {
|
||||||
subschemas: Some(Box::new(SubschemaValidation {
|
subschemas: Some(Box::new(SubschemaValidation {
|
||||||
any_of: Some(vec![schema, <()>::json_schema(&mut self.gen)]),
|
any_of: Some(vec![schema, <()>::json_schema(self.gen)]),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})),
|
})),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
|
|
@ -17,7 +17,7 @@ fn eight() -> i32 {
|
||||||
8
|
8
|
||||||
}
|
}
|
||||||
|
|
||||||
fn null() -> () {}
|
fn null() {}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn examples() -> TestResult {
|
fn examples() -> TestResult {
|
||||||
|
|
|
@ -4,7 +4,7 @@ use std::collections::HashMap;
|
||||||
use util::*;
|
use util::*;
|
||||||
|
|
||||||
// In real code, this would typically be a Regex, potentially created in a `lazy_static!`.
|
// In real code, this would typically be a Regex, potentially created in a `lazy_static!`.
|
||||||
static STARTS_WITH_HELLO: &'static str = r"^[Hh]ello\b";
|
static STARTS_WITH_HELLO: &str = r"^[Hh]ello\b";
|
||||||
|
|
||||||
const MIN: u32 = 1;
|
const MIN: u32 = 1;
|
||||||
const MAX: u32 = 1000;
|
const MAX: u32 = 1000;
|
||||||
|
|
|
@ -46,14 +46,14 @@ pub fn process_serde_attrs(input: &mut syn::DeriveInput) -> Result<(), Vec<syn::
|
||||||
|
|
||||||
fn process_serde_variant_attrs<'a>(ctxt: &Ctxt, variants: impl Iterator<Item = &'a mut Variant>) {
|
fn process_serde_variant_attrs<'a>(ctxt: &Ctxt, variants: impl Iterator<Item = &'a mut Variant>) {
|
||||||
for v in variants {
|
for v in variants {
|
||||||
process_attrs(&ctxt, &mut v.attrs);
|
process_attrs(ctxt, &mut v.attrs);
|
||||||
process_serde_field_attrs(&ctxt, v.fields.iter_mut());
|
process_serde_field_attrs(ctxt, v.fields.iter_mut());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_serde_field_attrs<'a>(ctxt: &Ctxt, fields: impl Iterator<Item = &'a mut Field>) {
|
fn process_serde_field_attrs<'a>(ctxt: &Ctxt, fields: impl Iterator<Item = &'a mut Field>) {
|
||||||
for f in fields {
|
for f in fields {
|
||||||
process_attrs(&ctxt, &mut f.attrs);
|
process_attrs(ctxt, &mut f.attrs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,10 +71,10 @@ fn process_attrs(ctxt: &Ctxt, attrs: &mut Vec<Attribute>) {
|
||||||
// Copy appropriate #[schemars(...)] attributes to #[serde(...)] attributes
|
// Copy appropriate #[schemars(...)] attributes to #[serde(...)] attributes
|
||||||
let (mut serde_meta, mut schemars_meta_names): (Vec<_>, HashSet<_>) = schemars_attrs
|
let (mut serde_meta, mut schemars_meta_names): (Vec<_>, HashSet<_>) = schemars_attrs
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|at| get_meta_items(&ctxt, at))
|
.flat_map(|at| get_meta_items(ctxt, at))
|
||||||
.flatten()
|
.flatten()
|
||||||
.filter_map(|meta| {
|
.filter_map(|meta| {
|
||||||
let keyword = get_meta_ident(&ctxt, &meta).ok()?;
|
let keyword = get_meta_ident(ctxt, &meta).ok()?;
|
||||||
if keyword.ends_with("with") || !SERDE_KEYWORDS.contains(&keyword.as_ref()) {
|
if keyword.ends_with("with") || !SERDE_KEYWORDS.contains(&keyword.as_ref()) {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
@ -91,10 +91,10 @@ fn process_attrs(ctxt: &Ctxt, attrs: &mut Vec<Attribute>) {
|
||||||
// Re-add #[serde(...)] attributes that weren't overridden by #[schemars(...)] attributes
|
// Re-add #[serde(...)] attributes that weren't overridden by #[schemars(...)] attributes
|
||||||
for meta in serde_attrs
|
for meta in serde_attrs
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flat_map(|at| get_meta_items(&ctxt, &at))
|
.flat_map(|at| get_meta_items(ctxt, &at))
|
||||||
.flatten()
|
.flatten()
|
||||||
{
|
{
|
||||||
if let Ok(i) = get_meta_ident(&ctxt, &meta) {
|
if let Ok(i) = get_meta_ident(ctxt, &meta) {
|
||||||
if !schemars_meta_names.contains(&i)
|
if !schemars_meta_names.contains(&i)
|
||||||
&& SERDE_KEYWORDS.contains(&i.as_ref())
|
&& SERDE_KEYWORDS.contains(&i.as_ref())
|
||||||
&& i != "bound"
|
&& i != "bound"
|
||||||
|
|
|
@ -112,7 +112,7 @@ impl ValidationAttrs {
|
||||||
} else if self.length_equal.is_some() {
|
} else if self.length_equal.is_some() {
|
||||||
mutual_exclusive_error(&nv.path, "equal")
|
mutual_exclusive_error(&nv.path, "equal")
|
||||||
} else {
|
} else {
|
||||||
self.length_min = str_or_num_to_expr(&errors, "min", &nv.lit);
|
self.length_min = str_or_num_to_expr(errors, "min", &nv.lit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
NestedMeta::Meta(Meta::NameValue(nv)) if nv.path.is_ident("max") => {
|
NestedMeta::Meta(Meta::NameValue(nv)) if nv.path.is_ident("max") => {
|
||||||
|
@ -121,7 +121,7 @@ impl ValidationAttrs {
|
||||||
} else if self.length_equal.is_some() {
|
} else if self.length_equal.is_some() {
|
||||||
mutual_exclusive_error(&nv.path, "equal")
|
mutual_exclusive_error(&nv.path, "equal")
|
||||||
} else {
|
} else {
|
||||||
self.length_max = str_or_num_to_expr(&errors, "max", &nv.lit);
|
self.length_max = str_or_num_to_expr(errors, "max", &nv.lit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
NestedMeta::Meta(Meta::NameValue(nv)) if nv.path.is_ident("equal") => {
|
NestedMeta::Meta(Meta::NameValue(nv)) if nv.path.is_ident("equal") => {
|
||||||
|
@ -133,14 +133,14 @@ impl ValidationAttrs {
|
||||||
mutual_exclusive_error(&nv.path, "max")
|
mutual_exclusive_error(&nv.path, "max")
|
||||||
} else {
|
} else {
|
||||||
self.length_equal =
|
self.length_equal =
|
||||||
str_or_num_to_expr(&errors, "equal", &nv.lit);
|
str_or_num_to_expr(errors, "equal", &nv.lit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
meta => {
|
meta => {
|
||||||
if !ignore_errors {
|
if !ignore_errors {
|
||||||
errors.error_spanned_by(
|
errors.error_spanned_by(
|
||||||
meta,
|
meta,
|
||||||
format!("unknown item in schemars length attribute"),
|
"unknown item in schemars length attribute".to_string(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,21 +155,21 @@ impl ValidationAttrs {
|
||||||
if self.range_min.is_some() {
|
if self.range_min.is_some() {
|
||||||
duplicate_error(&nv.path)
|
duplicate_error(&nv.path)
|
||||||
} else {
|
} else {
|
||||||
self.range_min = str_or_num_to_expr(&errors, "min", &nv.lit);
|
self.range_min = str_or_num_to_expr(errors, "min", &nv.lit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
NestedMeta::Meta(Meta::NameValue(nv)) if nv.path.is_ident("max") => {
|
NestedMeta::Meta(Meta::NameValue(nv)) if nv.path.is_ident("max") => {
|
||||||
if self.range_max.is_some() {
|
if self.range_max.is_some() {
|
||||||
duplicate_error(&nv.path)
|
duplicate_error(&nv.path)
|
||||||
} else {
|
} else {
|
||||||
self.range_max = str_or_num_to_expr(&errors, "max", &nv.lit);
|
self.range_max = str_or_num_to_expr(errors, "max", &nv.lit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
meta => {
|
meta => {
|
||||||
if !ignore_errors {
|
if !ignore_errors {
|
||||||
errors.error_spanned_by(
|
errors.error_spanned_by(
|
||||||
meta,
|
meta,
|
||||||
format!("unknown item in schemars range attribute"),
|
"unknown item in schemars range attribute".to_string(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -247,7 +247,7 @@ impl ValidationAttrs {
|
||||||
if !ignore_errors {
|
if !ignore_errors {
|
||||||
errors.error_spanned_by(
|
errors.error_spanned_by(
|
||||||
meta,
|
meta,
|
||||||
format!("unknown item in schemars regex attribute"),
|
"unknown item in schemars regex attribute".to_string(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -261,8 +261,8 @@ impl ValidationAttrs {
|
||||||
if path.is_ident("contains") =>
|
if path.is_ident("contains") =>
|
||||||
{
|
{
|
||||||
match (&self.contains, &self.regex) {
|
match (&self.contains, &self.regex) {
|
||||||
(Some(_), _) => duplicate_error(&path),
|
(Some(_), _) => duplicate_error(path),
|
||||||
(None, Some(_)) => mutual_exclusive_error(&path, "regex"),
|
(None, Some(_)) => mutual_exclusive_error(path, "regex"),
|
||||||
(None, None) => {
|
(None, None) => {
|
||||||
self.contains = get_lit_str(errors, attr_type, "contains", lit)
|
self.contains = get_lit_str(errors, attr_type, "contains", lit)
|
||||||
.map(|litstr| litstr.value())
|
.map(|litstr| litstr.value())
|
||||||
|
@ -292,9 +292,7 @@ impl ValidationAttrs {
|
||||||
if !ignore_errors {
|
if !ignore_errors {
|
||||||
errors.error_spanned_by(
|
errors.error_spanned_by(
|
||||||
meta,
|
meta,
|
||||||
format!(
|
"unknown item in schemars contains attribute".to_string(),
|
||||||
"unknown item in schemars contains attribute"
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -319,7 +317,7 @@ impl ValidationAttrs {
|
||||||
if let Some(length_min) = self
|
if let Some(length_min) = self
|
||||||
.length_min
|
.length_min
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.or_else(|| self.length_equal.as_ref())
|
.or(self.length_equal.as_ref())
|
||||||
{
|
{
|
||||||
string_validation.push(quote! {
|
string_validation.push(quote! {
|
||||||
validation.min_length = Some(#length_min as u32);
|
validation.min_length = Some(#length_min as u32);
|
||||||
|
@ -332,7 +330,7 @@ impl ValidationAttrs {
|
||||||
if let Some(length_max) = self
|
if let Some(length_max) = self
|
||||||
.length_max
|
.length_max
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.or_else(|| self.length_equal.as_ref())
|
.or(self.length_equal.as_ref())
|
||||||
{
|
{
|
||||||
string_validation.push(quote! {
|
string_validation.push(quote! {
|
||||||
validation.max_length = Some(#length_max as u32);
|
validation.max_length = Some(#length_max as u32);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue