From 7dc65621b5b9dedcac281f926eb6acf0f1f9b72d Mon Sep 17 00:00:00 2001 From: Nicolas Lara Date: Fri, 27 Jan 2023 13:30:28 +0100 Subject: [PATCH 1/3] add default json schema implementation --- Cargo.toml | 9 +++++++++ src/lib.rs | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 9962372..befb0e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,8 +10,17 @@ readme = "README.md" keywords = ["serde", "wasm"] license = "MIT" +[features] +json = ["json_schema"] + [dependencies] serde = "^1.0.0" +[dependencies.schemars] +version = "0.8.8" +default-features = false +features = ["json_schema"] + + [dev-dependencies] serde_derive = "^1.0.0" diff --git a/src/lib.rs b/src/lib.rs index fd291bd..57477b9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -113,6 +113,17 @@ impl Ord for Value { } } +#[cfg(feature = "json_schema")] +impl JsonSchema for Value { + fn schema_name() -> String { + "JSON object".to_string() + } + + fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema { + schemars::schema::Schema::from(true) + } +} + impl Value { fn discriminant(&self) -> usize { match *self { From 7e1e492fab2ea9b3a266fdfff9670b37ef7a9f68 Mon Sep 17 00:00:00 2001 From: Nicolas Lara Date: Fri, 27 Jan 2023 13:40:48 +0100 Subject: [PATCH 2/3] fixes --- Cargo.toml | 9 ++------- src/lib.rs | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index befb0e1..085f100 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,16 +11,11 @@ keywords = ["serde", "wasm"] license = "MIT" [features] -json = ["json_schema"] +json_schema = [] [dependencies] serde = "^1.0.0" - -[dependencies.schemars] -version = "0.8.8" -default-features = false -features = ["json_schema"] - +schemars = { version = "0.8.11", default-features = false, cfg = "feature = \"json_schema\""} [dev-dependencies] serde_derive = "^1.0.0" diff --git a/src/lib.rs b/src/lib.rs index 57477b9..ff7a0f8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -114,7 +114,7 @@ impl Ord for Value { } #[cfg(feature = "json_schema")] -impl JsonSchema for Value { +impl schemars::JsonSchema for Value { fn schema_name() -> String { "JSON object".to_string() } From 77e371d590b209c463b315e128407ed1c49f6374 Mon Sep 17 00:00:00 2001 From: Nicolas Lara Date: Fri, 27 Jan 2023 13:47:51 +0100 Subject: [PATCH 3/3] better name --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index ff7a0f8..76a289b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -116,7 +116,7 @@ impl Ord for Value { #[cfg(feature = "json_schema")] impl schemars::JsonSchema for Value { fn schema_name() -> String { - "JSON object".to_string() + "JSON".to_string() } fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {