Implement JsonSchema for Weak/Wrapping/Reverse
This commit is contained in:
parent
e11d5e5a98
commit
e6c178117c
3 changed files with 44 additions and 40 deletions
|
@ -1,39 +0,0 @@
|
|||
use crate::gen::SchemaGenerator;
|
||||
use crate::schema::Schema;
|
||||
use crate::JsonSchema;
|
||||
|
||||
macro_rules! deref_impl {
|
||||
($($desc:tt)+) => {
|
||||
impl $($desc)+
|
||||
where
|
||||
T: ?Sized + JsonSchema,
|
||||
{
|
||||
fn is_referenceable() -> bool {
|
||||
T::is_referenceable()
|
||||
}
|
||||
|
||||
fn schema_name() -> String {
|
||||
T::schema_name()
|
||||
}
|
||||
|
||||
fn json_schema(gen: &mut SchemaGenerator) -> Schema {
|
||||
T::json_schema(gen)
|
||||
}
|
||||
|
||||
fn json_schema_optional(gen: &mut SchemaGenerator) -> Schema {
|
||||
T::json_schema_optional(gen)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
deref_impl!(<'a, T> JsonSchema for &'a T);
|
||||
deref_impl!(<'a, T> JsonSchema for &'a mut T);
|
||||
deref_impl!(<T> JsonSchema for Box<T>);
|
||||
deref_impl!(<T> JsonSchema for std::rc::Rc<T>);
|
||||
deref_impl!(<T> JsonSchema for std::sync::Arc<T>);
|
||||
deref_impl!(<T> JsonSchema for std::sync::Mutex<T>);
|
||||
deref_impl!(<T> JsonSchema for std::sync::RwLock<T>);
|
||||
deref_impl!(<T> JsonSchema for std::cell::Cell<T>);
|
||||
deref_impl!(<T> JsonSchema for std::cell::RefCell<T>);
|
||||
deref_impl!(<'a, T: ToOwned> JsonSchema for std::borrow::Cow<'a, T>);
|
|
@ -10,7 +10,7 @@ mod array;
|
|||
#[cfg(feature = "chrono")]
|
||||
mod chrono;
|
||||
mod core;
|
||||
mod deref;
|
||||
mod wrapper;
|
||||
mod maps;
|
||||
mod primitives;
|
||||
mod sequences;
|
||||
|
|
43
schemars/src/json_schema_impls/wrapper.rs
Normal file
43
schemars/src/json_schema_impls/wrapper.rs
Normal file
|
@ -0,0 +1,43 @@
|
|||
use crate::gen::SchemaGenerator;
|
||||
use crate::schema::Schema;
|
||||
use crate::JsonSchema;
|
||||
|
||||
macro_rules! deref_impl {
|
||||
($($desc:tt)+) => {
|
||||
impl $($desc)+
|
||||
where
|
||||
T: JsonSchema,
|
||||
{
|
||||
fn is_referenceable() -> bool {
|
||||
T::is_referenceable()
|
||||
}
|
||||
|
||||
fn schema_name() -> String {
|
||||
T::schema_name()
|
||||
}
|
||||
|
||||
fn json_schema(gen: &mut SchemaGenerator) -> Schema {
|
||||
T::json_schema(gen)
|
||||
}
|
||||
|
||||
fn json_schema_optional(gen: &mut SchemaGenerator) -> Schema {
|
||||
T::json_schema_optional(gen)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
deref_impl!(<'a, T: ?Sized> JsonSchema for &'a T);
|
||||
deref_impl!(<'a, T: ?Sized> JsonSchema for &'a mut T);
|
||||
deref_impl!(<T: ?Sized> JsonSchema for Box<T>);
|
||||
deref_impl!(<T: ?Sized> JsonSchema for std::rc::Rc<T>);
|
||||
deref_impl!(<T: ?Sized> JsonSchema for std::rc::Weak<T>);
|
||||
deref_impl!(<T: ?Sized> JsonSchema for std::sync::Arc<T>);
|
||||
deref_impl!(<T: ?Sized> JsonSchema for std::sync::Weak<T>);
|
||||
deref_impl!(<T: ?Sized> JsonSchema for std::sync::Mutex<T>);
|
||||
deref_impl!(<T: ?Sized> JsonSchema for std::sync::RwLock<T>);
|
||||
deref_impl!(<T: ?Sized> JsonSchema for std::cell::Cell<T>);
|
||||
deref_impl!(<T: ?Sized> JsonSchema for std::cell::RefCell<T>);
|
||||
deref_impl!(<'a, T: ?Sized + ToOwned> JsonSchema for std::borrow::Cow<'a, T>);
|
||||
deref_impl!(<T> JsonSchema for std::num::Wrapping<T>);
|
||||
deref_impl!(<T> JsonSchema for std::cmp::Reverse<T>);
|
Loading…
Add table
Add a link
Reference in a new issue