Compare commits

..

3 commits
master ... fork

Author SHA1 Message Date
de9566709a feat: support hashbrown015 2025-02-15 23:02:32 +03:00
0b5abbcd0f add support for compact_str crate 2025-02-15 23:02:15 +03:00
Graham Esau
efb74969e2
Update dependencies (#368) 2025-01-24 22:03:59 +00:00
8 changed files with 44 additions and 1372 deletions

View file

@ -24,6 +24,14 @@ jobs:
fail-fast: false fail-fast: false
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Downgrade packages for MSRV
if: matrix.rust == '1.70.0'
run: |
cargo add --dev jsonschema@0.20
cargo add --dev garde --git https://github.com/jprochazk/garde.git --rev be00ddddf8de14530ee890ccfdbaf0b13fb32852
cargo add --dev validator@0.18.1
cargo update url --precise 2.5.2
working-directory: ./schemars
- uses: dtolnay/rust-toolchain@master - uses: dtolnay/rust-toolchain@master
with: with:
toolchain: ${{ matrix.rust }} toolchain: ${{ matrix.rust }}

1362
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -20,6 +20,7 @@ dyn-clone = "1.0"
ref-cast = "1.0.22" ref-cast = "1.0.22"
# optional dependencies # optional dependencies
hashbrown015 = { version = "0.15", default-features = false, optional = true, package = "hashbrown" }
arrayvec07 = { version = "0.7", default-features = false, optional = true, package = "arrayvec" } arrayvec07 = { version = "0.7", default-features = false, optional = true, package = "arrayvec" }
bigdecimal04 = { version = "0.4", default-features = false, optional = true, package = "bigdecimal" } bigdecimal04 = { version = "0.4", default-features = false, optional = true, package = "bigdecimal" }
bytes1 = { version = "1.0", default-features = false, optional = true, package = "bytes" } bytes1 = { version = "1.0", default-features = false, optional = true, package = "bytes" }
@ -32,19 +33,20 @@ smallvec1 = { version = "1.0", default-features = false, optional = true, packag
smol_str02 = { version = "0.2.1", default-features = false, optional = true, package = "smol_str" } smol_str02 = { version = "0.2.1", default-features = false, optional = true, package = "smol_str" }
url2 = { version = "2.0", default-features = false, optional = true, package = "url" } url2 = { version = "2.0", default-features = false, optional = true, package = "url" }
uuid1 = { version = "1.0", default-features = false, optional = true, package = "uuid" } uuid1 = { version = "1.0", default-features = false, optional = true, package = "uuid" }
compact_str08 = { version = "0.8", default-features = false, optional = true, package = "compact_str" }
[dev-dependencies] [dev-dependencies]
pretty_assertions = "1.2.1" pretty_assertions = "1.2.1"
trybuild = "1.0" trybuild = "1.0"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
jsonschema = { version = "0.20", default-features = false } jsonschema = { version = "0.28", default-features = false }
snapbox = { version = "0.6.17", features = ["json"] } snapbox = { version = "0.6.17", features = ["json"] }
serde_repr = "0.1.19" serde_repr = "0.1.19"
# Use github source until published garde version supports `length(equal = ...)` attr garde = { version = "0.22", features = ["derive", "email", "regex", "url"] }
garde = { git = "https://github.com/jprochazk/garde.git", rev = "be00ddddf8de14530ee890ccfdbaf0b13fb32852", features = ["derive", "email", "regex", "url"] } validator = { version = "0.20", features = ["derive"] }
validator = { version = "0.18.1", features = ["derive"] }
regex = { version = "1.10.6", default-features = false } regex = { version = "1.10.6", default-features = false }
hashbrown015 = { version = "0.15", default-features = false, features = ["serde"], package = "hashbrown" }
arrayvec07 = { version = "0.7", default-features = false, features = ["serde"], package = "arrayvec"} arrayvec07 = { version = "0.7", default-features = false, features = ["serde"], package = "arrayvec"}
bigdecimal04 = { version = "0.4", default-features = false, features = ["serde"], package = "bigdecimal" } bigdecimal04 = { version = "0.4", default-features = false, features = ["serde"], package = "bigdecimal" }
bytes1 = { version = "1.0", default-features = false, features = ["serde"], package = "bytes" } bytes1 = { version = "1.0", default-features = false, features = ["serde"], package = "bytes" }
@ -55,6 +57,7 @@ rust_decimal1 = { version = "1", default-features = false, features = ["serde"],
semver1 = { version = "1.0.9", default-features = false, features = ["serde"], package = "semver" } semver1 = { version = "1.0.9", default-features = false, features = ["serde"], package = "semver" }
smallvec1 = { version = "1.0", default-features = false, features = ["serde"], package = "smallvec" } smallvec1 = { version = "1.0", default-features = false, features = ["serde"], package = "smallvec" }
smol_str02 = { version = "0.2.1", default-features = false, features = ["serde"], package = "smol_str" } smol_str02 = { version = "0.2.1", default-features = false, features = ["serde"], package = "smol_str" }
compact_str08 = { version = "0.8", default-features = false, features = ["serde"], package = "compact_str" }
url2 = { version = "2.0", default-features = false, features = ["serde"], package = "url" } url2 = { version = "2.0", default-features = false, features = ["serde"], package = "url" }
uuid1 = { version = "1.0", default-features = false, features = ["serde"], package = "uuid" } uuid1 = { version = "1.0", default-features = false, features = ["serde"], package = "uuid" }

View file

@ -83,6 +83,12 @@ forward_impl!((<A: smallvec1::Array> crate::JsonSchema for smallvec1::SmallVec<A
#[cfg(feature = "smol_str02")] #[cfg(feature = "smol_str02")]
forward_impl!(smol_str02::SmolStr => alloc::string::String); forward_impl!(smol_str02::SmolStr => alloc::string::String);
#[cfg(feature = "compact_str08")]
forward_impl!(compact_str08::CompactString => alloc::string::String);
#[cfg(feature = "hashbrown015")]
forward_impl!((<K: crate::JsonSchema, V: crate::JsonSchema> crate::JsonSchema for hashbrown015::HashMap<K, V>) => std::collections::HashMap<K, V>);
#[cfg(feature = "url2")] #[cfg(feature = "url2")]
mod url2; mod url2;

View file

@ -0,0 +1,11 @@
use compact_str08::CompactString;
use crate::prelude::*;
#[test]
fn compact_str() {
test!(CompactString)
.assert_identical::<String>()
.assert_allows_ser_roundtrip(["".into(), "test".into()])
.assert_matches_de_roundtrip(arbitrary_values());
}

View file

@ -60,8 +60,12 @@ fn custom_struct() {
fn custom_struct_openapi3() { fn custom_struct_openapi3() {
let value = struct_value(); let value = struct_value();
test!(value: value.clone(), SchemaSettings::openapi3()) test!(value: value.clone(), SchemaSettings::openapi3()).assert_snapshot();
.assert_snapshot()
// schemars uses a nonstandard meta-schema for openapi 3.0 which the jsonschema crate doesn't
// accept, so we swap it out for the standard draft-04 meta-schema.
let draft04 = "http://json-schema.org/draft-04/schema".to_owned();
test!(value: value.clone(), SchemaSettings::openapi3().with(|o| o.meta_schema = Some(draft04)))
.assert_allows_ser_roundtrip([value, MyStruct::default()]); .assert_allows_ser_roundtrip([value, MyStruct::default()]);
} }

View file

@ -41,6 +41,8 @@ mod skip;
mod smallvec; mod smallvec;
#[cfg(feature = "smol_str02")] #[cfg(feature = "smol_str02")]
mod smol_str; mod smol_str;
#[cfg(feature = "compact_str08")]
mod compact_str;
mod std_types; mod std_types;
mod structs; mod structs;
mod transform; mod transform;

View file

@ -5,7 +5,7 @@ use schemars::{
}; };
use serde::{de::DeserializeOwned, Serialize}; use serde::{de::DeserializeOwned, Serialize};
use serde_json::{json, Value}; use serde_json::{json, Value};
use snapbox::IntoJson; use snapbox::{data::DataFormat, IntoJson};
use std::{ use std::{
any::type_name, borrow::Borrow, cell::OnceCell, f64, marker::PhantomData, path::Path, any::type_name, borrow::Borrow, cell::OnceCell, f64, marker::PhantomData, path::Path,
sync::OnceLock, sync::OnceLock,
@ -74,18 +74,18 @@ impl<T: JsonSchema> TestHelper<T> {
if self.de_schema == self.ser_schema { if self.de_schema == self.ser_schema {
snapbox::assert_data_eq!( snapbox::assert_data_eq!(
(&self.de_schema).into_json(), (&self.de_schema).into_json(),
snapbox::Data::read_from(Path::new(&common_path), None).raw() snapbox::Data::read_from(Path::new(&common_path), Some(DataFormat::Json)).raw()
); );
_ = std::fs::remove_file(de_path); _ = std::fs::remove_file(de_path);
_ = std::fs::remove_file(ser_path); _ = std::fs::remove_file(ser_path);
} else { } else {
snapbox::assert_data_eq!( snapbox::assert_data_eq!(
(&self.de_schema).into_json(), (&self.de_schema).into_json(),
snapbox::Data::read_from(Path::new(&de_path), None).raw() snapbox::Data::read_from(Path::new(&de_path), Some(DataFormat::Json)).raw()
); );
snapbox::assert_data_eq!( snapbox::assert_data_eq!(
(&self.ser_schema).into_json(), (&self.ser_schema).into_json(),
snapbox::Data::read_from(Path::new(&ser_path), None).raw() snapbox::Data::read_from(Path::new(&ser_path), Some(DataFormat::Json)).raw()
); );
_ = std::fs::remove_file(common_path); _ = std::fs::remove_file(common_path);
} }