Add support for rust_decimal and bigdecimal (#101)

This commit is contained in:
timando 2021-11-26 07:42:25 +10:00 committed by GitHub
parent 3cac0e5048
commit f0d2b1c50c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 0 deletions

View file

@ -26,6 +26,8 @@ smallvec = { version = "1.0", optional = true }
arrayvec = { version = "0.5", default-features = false, optional = true } arrayvec = { version = "0.5", default-features = false, optional = true }
url = { version = "2.0", default-features = false, optional = true } url = { version = "2.0", default-features = false, optional = true }
bytes = { version = "1.0", optional = true } bytes = { version = "1.0", optional = true }
rust_decimal = { version = "1", default-features = false, optional = true }
bigdecimal = { version = "0.3", default-features = false, optional = true }
enumset = { version = "1.0", optional = true } enumset = { version = "1.0", optional = true }
[dev-dependencies] [dev-dependencies]

View 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);

View file

@ -45,6 +45,8 @@ mod bytes;
#[cfg(feature = "chrono")] #[cfg(feature = "chrono")]
mod chrono; mod chrono;
mod core; mod core;
#[cfg(any(feature = "rust_decimal", feature="bigdecimal"))]
mod decimal;
#[cfg(feature = "either")] #[cfg(feature = "either")]
mod either; mod either;
#[cfg(feature = "enumset")] #[cfg(feature = "enumset")]