Skip to content

Commit

Permalink
Fix schemas for bigdecimal/rust_decimal
Browse files Browse the repository at this point in the history
Both of these crates serialise decimals as strings, not as plain numbers
  • Loading branch information
GREsau committed Sep 17, 2023
1 parent a5e51b2 commit b77737d
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions schemars/src/json_schema_impls/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ 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()
"Decimal".to_owned()
}

fn json_schema(_: &mut SchemaGenerator) -> Schema {
SchemaObject {
instance_type: Some(InstanceType::$instance_type.into()),
instance_type: Some(InstanceType::String.into()),
string: Some(Box::new(StringValidation {
pattern: Some(r"^-?[0-9]+(\.[0-9]+)?$".to_owned()),
..Default::default()
})),
..Default::default()
}
.into()
Expand Down

0 comments on commit b77737d

Please sign in to comment.