diff --git a/Cargo.toml b/Cargo.toml index 9962372..085f100 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,8 +10,12 @@ readme = "README.md" keywords = ["serde", "wasm"] license = "MIT" +[features] +json_schema = [] + [dependencies] serde = "^1.0.0" +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 fd291bd..76a289b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -113,6 +113,17 @@ impl Ord for Value { } } +#[cfg(feature = "json_schema")] +impl schemars::JsonSchema for Value { + fn schema_name() -> String { + "JSON".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 {