Clippy fixes
This commit is contained in:
parent
61d64df57d
commit
29dc025629
7 changed files with 69 additions and 63 deletions
|
@ -221,14 +221,12 @@ pub enum MyEnum {
|
|||
StructVariant { floats: Vec<f32> },
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let schema = schema_for_value!(MyStruct {
|
||||
my_int: 123,
|
||||
my_bool: true,
|
||||
my_nullable_enum: Some(MyEnum::StringNewType("foo".to_string()))
|
||||
});
|
||||
println!("{}", serde_json::to_string_pretty(&schema).unwrap());
|
||||
}
|
||||
```
|
||||
|
||||
<details>
|
||||
|
|
|
@ -88,15 +88,19 @@ impl<T: JsonSchema, E: JsonSchema> JsonSchema for Result<T, E> {
|
|||
}
|
||||
|
||||
fn json_schema(gen: &mut SchemaGenerator) -> Schema {
|
||||
let mut ok_schema = SchemaObject::default();
|
||||
ok_schema.instance_type = Some(InstanceType::Object.into());
|
||||
let mut ok_schema = SchemaObject {
|
||||
instance_type: Some(InstanceType::Object.into()),
|
||||
..Default::default()
|
||||
};
|
||||
let obj = ok_schema.object();
|
||||
obj.required.insert("Ok".to_owned());
|
||||
obj.properties
|
||||
.insert("Ok".to_owned(), gen.subschema_for::<T>());
|
||||
|
||||
let mut err_schema = SchemaObject::default();
|
||||
err_schema.instance_type = Some(InstanceType::Object.into());
|
||||
let mut err_schema = SchemaObject {
|
||||
instance_type: Some(InstanceType::Object.into()),
|
||||
..Default::default()
|
||||
};
|
||||
let obj = err_schema.object();
|
||||
obj.required.insert("Err".to_owned());
|
||||
obj.properties
|
||||
|
@ -114,31 +118,29 @@ impl<T: JsonSchema> JsonSchema for Bound<T> {
|
|||
}
|
||||
|
||||
fn json_schema(gen: &mut SchemaGenerator) -> Schema {
|
||||
let mut included_schema = SchemaObject::default();
|
||||
included_schema.instance_type = Some(InstanceType::Object.into());
|
||||
included_schema
|
||||
.object()
|
||||
.required
|
||||
.insert("Included".to_owned());
|
||||
included_schema
|
||||
.object()
|
||||
.properties
|
||||
let mut included_schema = SchemaObject {
|
||||
instance_type: Some(InstanceType::Object.into()),
|
||||
..Default::default()
|
||||
};
|
||||
let obj = included_schema.object();
|
||||
obj.required.insert("Included".to_owned());
|
||||
obj.properties
|
||||
.insert("Included".to_owned(), gen.subschema_for::<T>());
|
||||
|
||||
let mut excluded_schema = SchemaObject::default();
|
||||
excluded_schema.instance_type = Some(InstanceType::Object.into());
|
||||
excluded_schema
|
||||
.object()
|
||||
.required
|
||||
.insert("Excluded".to_owned());
|
||||
excluded_schema
|
||||
.object()
|
||||
.properties
|
||||
let mut excluded_schema = SchemaObject {
|
||||
instance_type: Some(InstanceType::Object.into()),
|
||||
..Default::default()
|
||||
};
|
||||
let obj = excluded_schema.object();
|
||||
obj.required.insert("Excluded".to_owned());
|
||||
obj.properties
|
||||
.insert("Excluded".to_owned(), gen.subschema_for::<T>());
|
||||
|
||||
let mut unbounded_schema = SchemaObject::default();
|
||||
unbounded_schema.instance_type = Some(InstanceType::String.into());
|
||||
unbounded_schema.const_value = Some(json!("Unbounded"));
|
||||
let unbounded_schema = SchemaObject {
|
||||
instance_type: Some(InstanceType::String.into()),
|
||||
const_value: Some(json!("Unbounded")),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let mut schema = SchemaObject::default();
|
||||
schema.subschemas().one_of = Some(vec![
|
||||
|
@ -156,8 +158,10 @@ impl<T: JsonSchema> JsonSchema for Range<T> {
|
|||
}
|
||||
|
||||
fn json_schema(gen: &mut SchemaGenerator) -> Schema {
|
||||
let mut schema = SchemaObject::default();
|
||||
schema.instance_type = Some(InstanceType::Object.into());
|
||||
let mut schema = SchemaObject {
|
||||
instance_type: Some(InstanceType::Object.into()),
|
||||
..Default::default()
|
||||
};
|
||||
let obj = schema.object();
|
||||
obj.required.insert("start".to_owned());
|
||||
obj.required.insert("end".to_owned());
|
||||
|
|
|
@ -9,20 +9,22 @@ impl JsonSchema for OsString {
|
|||
}
|
||||
|
||||
fn json_schema(gen: &mut SchemaGenerator) -> Schema {
|
||||
let mut unix_schema = SchemaObject::default();
|
||||
unix_schema.instance_type = Some(InstanceType::Object.into());
|
||||
unix_schema.object().required.insert("Unix".to_owned());
|
||||
unix_schema
|
||||
.object()
|
||||
.properties
|
||||
let mut unix_schema = SchemaObject {
|
||||
instance_type: Some(InstanceType::Object.into()),
|
||||
..Default::default()
|
||||
};
|
||||
let obj = unix_schema.object();
|
||||
obj.required.insert("Unix".to_owned());
|
||||
obj.properties
|
||||
.insert("Unix".to_owned(), <Vec<u8>>::json_schema(gen));
|
||||
|
||||
let mut win_schema = SchemaObject::default();
|
||||
win_schema.instance_type = Some(InstanceType::Object.into());
|
||||
win_schema.object().required.insert("Windows".to_owned());
|
||||
win_schema
|
||||
.object()
|
||||
.properties
|
||||
let mut win_schema = SchemaObject {
|
||||
instance_type: Some(InstanceType::Object.into()),
|
||||
..Default::default()
|
||||
};
|
||||
let obj = win_schema.object();
|
||||
obj.required.insert("Windows".to_owned());
|
||||
obj.properties
|
||||
.insert("Windows".to_owned(), <Vec<u16>>::json_schema(gen));
|
||||
|
||||
let mut schema = SchemaObject::default();
|
||||
|
|
|
@ -9,8 +9,10 @@ impl JsonSchema for Duration {
|
|||
}
|
||||
|
||||
fn json_schema(gen: &mut SchemaGenerator) -> Schema {
|
||||
let mut schema = SchemaObject::default();
|
||||
schema.instance_type = Some(InstanceType::Object.into());
|
||||
let mut schema = SchemaObject {
|
||||
instance_type: Some(InstanceType::Object.into()),
|
||||
..Default::default()
|
||||
};
|
||||
let obj = schema.object();
|
||||
obj.required.insert("secs".to_owned());
|
||||
obj.required.insert("nanos".to_owned());
|
||||
|
@ -28,8 +30,10 @@ impl JsonSchema for SystemTime {
|
|||
}
|
||||
|
||||
fn json_schema(gen: &mut SchemaGenerator) -> Schema {
|
||||
let mut schema = SchemaObject::default();
|
||||
schema.instance_type = Some(InstanceType::Object.into());
|
||||
let mut schema = SchemaObject {
|
||||
instance_type: Some(InstanceType::Object.into()),
|
||||
..Default::default()
|
||||
};
|
||||
let obj = schema.object();
|
||||
obj.required.insert("secs_since_epoch".to_owned());
|
||||
obj.required.insert("nanos_since_epoch".to_owned());
|
||||
|
|
|
@ -216,14 +216,12 @@ pub enum MyEnum {
|
|||
StructVariant { floats: Vec<f32> },
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let schema = schema_for_value!(MyStruct {
|
||||
my_int: 123,
|
||||
my_bool: true,
|
||||
my_nullable_enum: Some(MyEnum::StringNewType("foo".to_string()))
|
||||
});
|
||||
println!("{}", serde_json::to_string_pretty(&schema).unwrap());
|
||||
}
|
||||
```
|
||||
|
||||
<details>
|
||||
|
|
|
@ -143,7 +143,7 @@ fn add_trait_bounds(generics: &mut syn::Generics) {
|
|||
}
|
||||
}
|
||||
|
||||
fn compile_error<'a>(errors: Vec<syn::Error>) -> TokenStream {
|
||||
fn compile_error(errors: Vec<syn::Error>) -> TokenStream {
|
||||
let compile_errors = errors.iter().map(syn::Error::to_compile_error);
|
||||
quote! {
|
||||
#(#compile_errors)*
|
||||
|
|
|
@ -35,8 +35,8 @@ impl ToTokens for SchemaMetadata<'_> {
|
|||
impl<'a> SchemaMetadata<'a> {
|
||||
pub fn from_attrs(attrs: &'a Attrs) -> Self {
|
||||
SchemaMetadata {
|
||||
title: attrs.title.as_ref().and_then(none_if_empty),
|
||||
description: attrs.description.as_ref().and_then(none_if_empty),
|
||||
title: attrs.title.as_deref().and_then(none_if_empty),
|
||||
description: attrs.description.as_deref().and_then(none_if_empty),
|
||||
deprecated: attrs.deprecated,
|
||||
examples: &attrs.examples,
|
||||
read_only: false,
|
||||
|
@ -106,7 +106,7 @@ impl<'a> SchemaMetadata<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn none_if_empty(s: &String) -> Option<&str> {
|
||||
fn none_if_empty(s: &str) -> Option<&str> {
|
||||
if s.is_empty() {
|
||||
None
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue