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