Add support for rust_decimal and bigdecimal (#101)
This commit is contained in:
parent
3cac0e5048
commit
f0d2b1c50c
3 changed files with 35 additions and 0 deletions
31
schemars/src/json_schema_impls/decimal.rs
Normal file
31
schemars/src/json_schema_impls/decimal.rs
Normal file
|
@ -0,0 +1,31 @@
|
|||
use crate::gen::SchemaGenerator;
|
||||
use crate::schema::*;
|
||||
use crate::JsonSchema;
|
||||
|
||||
macro_rules! decimal_impl {
|
||||
($type:ty) => {
|
||||
decimal_impl!($type => Number, "Number");
|
||||
};
|
||||
($type:ty => $instance_type:ident, $name:expr) => {
|
||||
impl JsonSchema for $type {
|
||||
no_ref_schema!();
|
||||
|
||||
fn schema_name() -> String {
|
||||
$name.to_owned()
|
||||
}
|
||||
|
||||
fn json_schema(_: &mut SchemaGenerator) -> Schema {
|
||||
SchemaObject {
|
||||
instance_type: Some(InstanceType::$instance_type.into()),
|
||||
..Default::default()
|
||||
}
|
||||
.into()
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(feature="rust_decimal")]
|
||||
decimal_impl!(rust_decimal::Decimal);
|
||||
#[cfg(feature="bigdecimal")]
|
||||
decimal_impl!(bigdecimal::BigDecimal);
|
Loading…
Add table
Add a link
Reference in a new issue