Skip to content

Commit 17f3555

Browse files
committed
Add support for schemars v1
* Copy existing `schemars_0_9` code to `schemars_1` and update feature flags and names * Add extra bounds for BTreeMap and HashMap keys * Update snapshot files for v0.9->v1 differences * Bumped syn in lockfile as schemars_derive uses types introduced in syn 2.0.81
1 parent 03a071a commit 17f3555

35 files changed

+3497
-13
lines changed

Cargo.lock

Lines changed: 32 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

serde_with/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1212
* Add support for `Range`, `RangeFrom`, `RangeTo`, `RangeInclusive` (#851)
1313
`RangeToInclusive` is currently unsupported by serde.
1414
* Add `schemars` implementations for `Bound`, `Range`, `RangeFrom`, `RangeTo`, `RangeInclusive`.
15+
* Added support for `schemars` v1 under the `schemars_1` feature flag
1516

1617
## [3.13.0] - 2025-06-14
1718

serde_with/Cargo.toml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ alloc = ["serde/alloc", "base64?/alloc", "chrono_0_4?/alloc", "hex?/alloc", "ser
4141
## Enables support for various types from the std library.
4242
## This will enable `std` support in all dependencies too.
4343
## The feature enabled by default and also enables `alloc`.
44-
std = ["alloc", "serde/std", "chrono_0_4?/clock", "chrono_0_4?/std", "indexmap_1?/std", "indexmap_2?/std", "time_0_3?/serde-well-known", "time_0_3?/std", "schemars_0_9?/std"]
44+
std = ["alloc", "serde/std", "chrono_0_4?/clock", "chrono_0_4?/std", "indexmap_1?/std", "indexmap_2?/std", "time_0_3?/serde-well-known", "time_0_3?/std", "schemars_0_9?/std", "schemars_1?/std"]
4545

4646
#! # Documentation
4747
#!
@@ -113,20 +113,27 @@ json = ["dep:serde_json", "alloc"]
113113
##
114114
## This pulls in [`serde_with_macros`] as a dependency.
115115
macros = ["dep:serde_with_macros"]
116-
## This feature enables integration with `schemars` 0.8.
116+
## This feature enables integration with `schemars` v0.8.
117117
## This makes `#[derive(JsonSchema)]` pick up the correct schema for the type
118118
## used within `#[serde_as(as = ...)]`.
119119
##
120120
## This pulls in [`schemars` v0.8](::schemars_0_8) as a dependency. It will also implicitly enable
121121
## the `std` feature as `schemars` is not `#[no_std]`.
122122
schemars_0_8 = ["dep:schemars_0_8", "std", "serde_with_macros?/schemars_0_8"]
123-
## This feature enables integration with `schemars` 0.9
123+
## This feature enables integration with `schemars` v0.9
124124
## This makes `#[derive(JsonSchema)]` pick up the correct schema for the type
125125
## used within `#[serde_as(as = ...)]`.
126126
##
127127
## This pulls in [`schemars` v0.9](::schemars_0_9) as a dependency. It will also implicitly enable
128128
## the `alloc` feature.
129129
schemars_0_9 = ["dep:schemars_0_9", "alloc", "serde_with_macros?/schemars_0_9", "dep:serde_json"]
130+
## This feature enables integration with `schemars` v1
131+
## This makes `#[derive(JsonSchema)]` pick up the correct schema for the type
132+
## used within `#[serde_as(as = ...)]`.
133+
##
134+
## This pulls in [`schemars` v1](::schemars_1) as a dependency. It will also implicitly enable
135+
## the `alloc` feature.
136+
schemars_1 = ["dep:schemars_1", "alloc", "serde_with_macros?/schemars_1", "dep:serde_json"]
130137
## The feature enables integration of `time` v0.3 specific conversions.
131138
## This includes support for the timestamp and duration types.
132139
##
@@ -146,6 +153,7 @@ indexmap_1 = { package = "indexmap", version = "1.8", optional = true, default-f
146153
indexmap_2 = { package = "indexmap", version = "2.0", optional = true, default-features = false, features = ["serde"] }
147154
schemars_0_8 = { package = "schemars", version = "0.8.16", optional = true, default-features = false }
148155
schemars_0_9 = { package = "schemars", version = "0.9.0", optional = true, default-features = false }
156+
schemars_1 = { package = "schemars", version = "1.0.2", optional = true, default-features = false }
149157
serde = { version = "1.0.152", default-features = false }
150158
serde_derive = "1.0.152"
151159
serde_json = { version = "1.0.45", optional = true, default-features = false }
@@ -165,6 +173,7 @@ ron = "0.10"
165173
rustversion = "1.0.0"
166174
schemars_0_8 = { package = "schemars", version = "0.8.16" }
167175
schemars_0_9 = { package = "schemars", version = "0.9.0" }
176+
schemars_1 = { package = "schemars", version = "1.0.2" }
168177
serde = { version = "1.0.152", default-features = false, features = ["derive"] }
169178
serde_json = { version = "1.0.25", features = ["preserve_order"] }
170179
serde_test = "1.0.124"
@@ -247,6 +256,11 @@ name = "schemars_0_9"
247256
path = "tests/schemars_0_9/main.rs"
248257
required-features = ["schemars_0_9", "std"]
249258

259+
[[test]]
260+
name = "schemars_1"
261+
path = "tests/schemars_1/main.rs"
262+
required-features = ["schemars_1", "std"]
263+
250264
[package.metadata.docs.rs]
251265
all-features = true
252266
rustdoc-args = [

serde_with/src/lib.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ pub mod schemars_0_8;
312312
#[cfg(feature = "schemars_0_9")]
313313
#[cfg_attr(docsrs, doc(cfg(feature = "schemars_0_9")))]
314314
pub mod schemars_0_9;
315+
#[cfg(feature = "schemars_1")]
316+
#[cfg_attr(docsrs, doc(cfg(feature = "schemars_1")))]
317+
pub mod schemars_1;
315318
pub mod ser;
316319
mod serde_conv;
317320
#[cfg(feature = "time_0_3")]
@@ -2594,6 +2597,10 @@ pub struct SetLastValueWins<T>(PhantomData<T>);
25942597
/// It is added implicitly by the [`#[serde_as]`](crate::serde_as) macro when any `schemars`
25952598
/// feature is enabled.
25962599
///
2597-
/// [`JsonSchema`]: ::schemars_0_8::JsonSchema
2598-
#[cfg(any(feature = "schemars_0_8", feature = "schemars_0_9"))]
2600+
/// [`JsonSchema`]: ::schemars_1::JsonSchema
2601+
#[cfg(any(
2602+
feature = "schemars_0_8",
2603+
feature = "schemars_0_9",
2604+
feature = "schemars_1"
2605+
))]
25992606
pub struct Schema<T: ?Sized, TA>(PhantomData<T>, PhantomData<TA>);

0 commit comments

Comments
 (0)