Skip to content

Commit

Permalink
Define Schema as a newtype around serde_json::Value (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
GREsau authored May 12, 2024
1 parent 7f6a7b7 commit 342cd5f
Show file tree
Hide file tree
Showing 79 changed files with 1,366 additions and 2,350 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- nightly
include:
- rust: 1.60.0
test_features: "--features impl_json_schema"
test_features: ""
allow_failure: false
- rust: stable
test_features: "--all-features"
Expand Down
100 changes: 35 additions & 65 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 29 additions & 55 deletions schemars/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,117 +15,91 @@ rust-version = "1.60"

[dependencies]
schemars_derive = { version = "=0.8.19", optional = true, path = "../schemars_derive" }
serde = { version = "1.0", features = ["derive"] }
serde = "1.0"
serde_json = "1.0.25"
dyn-clone = "1.0"
ref-cast = "1.0.22"

chrono = { version = "0.4", default-features = false, optional = true }
indexmap = { version = "1.2", features = ["serde-1"], optional = true }
indexmap2 = { version = "2.0", features = ["serde"], optional = true, package = "indexmap" }
either = { version = "1.3", default-features = false, optional = true }
uuid08 = { version = "0.8", default-features = false, optional = true, package = "uuid" }
# optional dependencies
chrono04 = { version = "0.4", default-features = false, optional = true, package = "chrono" }
indexmap2 = { version = "2.0", default-features = false, optional = true, package = "indexmap" }
either1 = { version = "1.3", default-features = false, optional = true, package = "either" }
uuid1 = { version = "1.0", default-features = false, optional = true, package = "uuid" }
smallvec = { version = "1.0", optional = true }
arrayvec05 = { version = "0.5", default-features = false, optional = true, package = "arrayvec" }
smallvec1 = { version = "1.0", default-features = false, optional = true, package = "smallvec" }
arrayvec07 = { version = "0.7", default-features = false, optional = true, package = "arrayvec" }
url = { version = "2.0", default-features = false, optional = true }
bytes = { version = "1.0", optional = true }
rust_decimal = { version = "1", default-features = false, optional = true }
bigdecimal03 = { version = "0.3", default-features = false, optional = true, package = "bigdecimal" }
url2 = { version = "2.0", default-features = false, optional = true, package = "url" }
bytes1 = { version = "1.0", default-features = false, optional = true, package = "bytes" }
rust_decimal1 = { version = "1", default-features = false, optional = true, package = "rust_decimal"}
bigdecimal04 = { version = "0.4", default-features = false, optional = true, package = "bigdecimal" }
enumset = { version = "1.0", optional = true }
smol_str = { version = "0.1.17", optional = true }
semver = { version = "1.0.9", features = ["serde"], optional = true }
enumset1 = { version = "1.0", default-features = false, optional = true, package = "enumset" }
smol_str02 = { version = "0.2.1", default-features = false, optional = true, package = "smol_str" }
semver1 = { version = "1.0.9", default-features = false, optional = true, package = "semver" }

[dev-dependencies]
pretty_assertions = "1.2.1"
trybuild = "1.0"
serde = { version = "1.0", features = ["derive"] }

[features]
default = ["derive"]

derive = ["schemars_derive"]

# Use a different representation for the map type of Schemars.
# This allows data to be read into a Value and written back to a JSON string
# while preserving the order of map keys in the input.
preserve_order = ["indexmap"]

impl_json_schema = ["derive"]
# derive_json_schema will be removed in a later version
derive_json_schema = ["impl_json_schema"]

# `uuid` feature contains `uuid08` only for back-compat - will be changed to include uuid 1.0 instead in a later version
uuid = ["uuid08"]
# `arrayvec` feature without version suffix is included only for back-compat - will be removed in a later version
arrayvec = ["arrayvec05"]
indexmap1 = ["indexmap"]

raw_value = ["serde_json/raw_value"]
# `bigdecimal` feature without version suffix is included only for back-compat - will be removed in a later version
bigdecimal = ["bigdecimal03"]

ui_test = []

[[test]]
name = "chrono"
required-features = ["chrono"]
name = "ui"
required-features = ["ui_test"]

[[test]]
name = "indexmap"
required-features = ["indexmap"]
name = "chrono"
required-features = ["chrono04"]

[[test]]
name = "indexmap2"
name = "indexmap"
required-features = ["indexmap2"]

[[test]]
name = "either"
required-features = ["either"]
required-features = ["either1"]

[[test]]
name = "uuid"
required-features = ["uuid08", "uuid1"]
required-features = ["uuid1"]

[[test]]
name = "smallvec"
required-features = ["smallvec"]
required-features = ["smallvec1"]

[[test]]
name = "bytes"
required-features = ["bytes"]
required-features = ["bytes1"]

[[test]]
name = "arrayvec"
required-features = ["arrayvec05", "arrayvec07"]

[[test]]
name = "schema_for_schema"
required-features = ["impl_json_schema"]

[[test]]
name = "ui"
required-features = ["ui_test"]
required-features = ["arrayvec07"]

[[test]]
name = "url"
required-features = ["url"]
required-features = ["url2"]

[[test]]
name = "enumset"
required-features = ["enumset"]
required-features = ["enumset1"]

[[test]]
name = "smol_str"
required-features = ["smol_str"]
required-features = ["smol_str02"]

[[test]]
name = "semver"
required-features = ["semver"]
required-features = ["semver1"]

[[test]]
name = "decimal"
required-features = ["rust_decimal", "bigdecimal03", "bigdecimal04"]
required-features = ["rust_decimal1", "bigdecimal04"]

[package.metadata.docs.rs]
all-features = true
10 changes: 6 additions & 4 deletions schemars/examples/custom_serialization.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use schemars::schema::{Schema, SchemaObject};
use schemars::Schema;
use schemars::{gen::SchemaGenerator, schema_for, JsonSchema};
use serde::{Deserialize, Serialize};

Expand All @@ -21,9 +21,11 @@ pub struct MyStruct {
}

fn make_custom_schema(gen: &mut SchemaGenerator) -> Schema {
let mut schema: SchemaObject = <String>::json_schema(gen).into();
schema.format = Some("boolean".to_owned());
schema.into()
let mut schema = String::json_schema(gen);
schema
.ensure_object()
.insert("format".into(), "boolean".into());
schema
}

fn eight() -> i32 {
Expand Down
Loading

0 comments on commit 342cd5f

Please sign in to comment.