From aebf40180a7008e016889cb3b94c00c5309c3a92 Mon Sep 17 00:00:00 2001 From: Sohum Banerjea Date: Mon, 1 Jan 2024 11:46:12 +1100 Subject: [PATCH] Revert "Fix schemas for bigdecimal/rust_decimal (#248)" This reverts commit db1dd4703926ed91ea2435b41bb51fa2c72976ff. # Conflicts: # schemars/Cargo.toml # schemars/tests/decimal.rs # schemars/tests/expected/bigdecimal03.json --- schemars/Cargo.toml | 4 ---- schemars/src/json_schema_impls/decimal.rs | 11 +++++------ schemars/tests/decimal.rs | 17 ----------------- schemars/tests/expected/rust_decimal.json | 6 ------ 4 files changed, 5 insertions(+), 33 deletions(-) delete mode 100644 schemars/tests/decimal.rs delete mode 100644 schemars/tests/expected/rust_decimal.json diff --git a/schemars/Cargo.toml b/schemars/Cargo.toml index fb6b06e5..a856a964 100644 --- a/schemars/Cargo.toml +++ b/schemars/Cargo.toml @@ -123,9 +123,5 @@ required-features = ["smol_str"] name = "semver" required-features = ["semver"] -[[test]] -name = "decimal" -required-features = ["rust_decimal", "bigdecimal03", "bigdecimal04"] - [package.metadata.docs.rs] all-features = true diff --git a/schemars/src/json_schema_impls/decimal.rs b/schemars/src/json_schema_impls/decimal.rs index 643ca44d..7b2bae56 100644 --- a/schemars/src/json_schema_impls/decimal.rs +++ b/schemars/src/json_schema_impls/decimal.rs @@ -5,11 +5,14 @@ use std::borrow::Cow; 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 { - "Decimal".to_owned() + $name.to_owned() } fn schema_id() -> Cow<'static, str> { @@ -18,11 +21,7 @@ macro_rules! decimal_impl { fn json_schema(_: &mut SchemaGenerator) -> Schema { SchemaObject { - instance_type: Some(InstanceType::String.into()), - string: Some(Box::new(StringValidation { - pattern: Some(r"^-?[0-9]+(\.[0-9]+)?$".to_owned()), - ..Default::default() - })), + instance_type: Some(InstanceType::$instance_type.into()), ..Default::default() } .into() diff --git a/schemars/tests/decimal.rs b/schemars/tests/decimal.rs deleted file mode 100644 index d245583b..00000000 --- a/schemars/tests/decimal.rs +++ /dev/null @@ -1,17 +0,0 @@ -mod util; -use util::*; - -#[test] -fn rust_decimal() -> TestResult { - test_default_generated_schema::("rust_decimal") -} - -#[test] -fn bigdecimal03() -> TestResult { - test_default_generated_schema::("bigdecimal03") -} - -#[test] -fn bigdecimal04() -> TestResult { - test_default_generated_schema::("bigdecimal04") -} diff --git a/schemars/tests/expected/rust_decimal.json b/schemars/tests/expected/rust_decimal.json deleted file mode 100644 index 855db6f7..00000000 --- a/schemars/tests/expected/rust_decimal.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "Decimal", - "type": "string", - "pattern": "^-?[0-9]+(\\.[0-9]+)?$" -} \ No newline at end of file