Skip to content

Commit b9eca34

Browse files
authored
Merge pull request #1 from Abstract-OS/nicolas/conditional-json-schema
Nicolas conditional json schema
2 parents 6de19db + 77e371d commit b9eca34

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ readme = "README.md"
1010
keywords = ["serde", "wasm"]
1111
license = "MIT"
1212

13+
[features]
14+
json_schema = []
15+
1316
[dependencies]
1417
serde = "^1.0.0"
18+
schemars = { version = "0.8.11", default-features = false, cfg = "feature = \"json_schema\""}
1519

1620
[dev-dependencies]
1721
serde_derive = "^1.0.0"

src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,17 @@ impl Ord for Value {
113113
}
114114
}
115115

116+
#[cfg(feature = "json_schema")]
117+
impl schemars::JsonSchema for Value {
118+
fn schema_name() -> String {
119+
"JSON".to_string()
120+
}
121+
122+
fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
123+
schemars::schema::Schema::from(true)
124+
}
125+
}
126+
116127
impl Value {
117128
fn discriminant(&self) -> usize {
118129
match *self {

0 commit comments

Comments
 (0)