Repository: GREsau/schemars
Pull request #339 (2024-09-09 20:46:27)

Remove enumset optional dependency
While updating integration tests, I discovered that the `JsonSchema` impl for enumset does not accurately represent how it is de/serialized by default. By default, it's serialized as an integer, but the `JsonSchema` impl assumes that it's a set (or in JSON, an array) of variant names.

It's possible to fix the impl, but I'm concerned that some consumers may be subtly broken by changing the behaviour (even if it's actually "fixing" it). I'm honestly more comfortable removing it entirely to make it more obviously "blow up" at compile-time, and then consumers can decide whether they want the old behaviour (e.g. `#[schemars(with = "BTreeSet<Enum>")]`) or a schema corresponding to the actual default serialization format for enumset (e.g. `#[schemars(with = "u64")]`).


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e21e380..cfb6097 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,11 @@
 # Changelog
 
+## [1.0.0-alpha.16] - **in-dev**
+
+### Removed (_⚠️ breaking changes ⚠️_)
+
+- the `enumset1`/`enumset` optional dependency has been removed, as its `JsonSchema` impl did not actually match the default serialization format of `EnumSet` (https://github.com/GREsau/schemars/pull/339)
+
 ## [1.0.0-alpha.15] - 2024-09-05
 
 ### Added
diff --git a/Cargo.lock b/Cargo.lock
index 665db12..40a1e2c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -51,40 +51,6 @@ dependencies = [
  "num-traits",
 ]
 
-[[package]]
-name = "darling"
-version = "0.20.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0209d94da627ab5605dcccf08bb18afa5009cfbef48d8a8b7d7bdbc79be25c5e"
-dependencies = [
- "darling_core",
- "darling_macro",
-]
-
-[[package]]
-name = "darling_core"
-version = "0.20.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "177e3443818124b357d8e76f53be906d60937f0d3a90773a664fa63fa253e621"
-dependencies = [
- "fnv",
- "ident_case",
- "proc-macro2",
- "quote",
- "syn",
-]
-
-[[package]]
-name = "darling_macro"
-version = "0.20.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5"
-dependencies = [
- "darling_core",
- "quote",
- "syn",
-]
-
 [[package]]
 name = "diff"
 version = "0.1.13"
@@ -103,39 +69,12 @@ version = "1.9.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
 
-[[package]]
-name = "enumset"
-version = "1.1.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "226c0da7462c13fb57e5cc9e0dc8f0635e7d27f276a3a7fd30054647f669007d"
-dependencies = [
- "enumset_derive",
-]
-
-[[package]]
-name = "enumset_derive"
-version = "0.8.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e08b6c6ab82d70f08844964ba10c7babb716de2ecaeab9be5717918a5177d3af"
-dependencies = [
- "darling",
- "proc-macro2",
- "quote",
- "syn",
-]
-
 [[package]]
 name = "equivalent"
 version = "1.0.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
 
-[[package]]
-name = "fnv"
-version = "1.0.7"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
-
 [[package]]
 name = "form_urlencoded"
 version = "1.2.0"
@@ -157,12 +96,6 @@ version = "0.14.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156"
 
-[[package]]
-name = "ident_case"
-version = "1.0.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
-
 [[package]]
 name = "idna"
 version = "0.4.0"
@@ -317,7 +250,6 @@ dependencies = [
  "chrono",
  "dyn-clone",
  "either",
- "enumset",
  "indexmap",
  "pretty_assertions",
  "ref-cast",
diff --git a/README.md b/README.md
index be8bfc9..d26db12 100644
--- a/README.md
+++ b/README.md
@@ -268,7 +268,6 @@ Schemars can implement `JsonSchema` on types from several popular crates, enable
 - `bytes1` - [bytes](https://crates.io/crates/bytes) (^1.0)
 - `chrono04` - [chrono](https://crates.io/crates/chrono) (^0.4)
 - `either1` - [either](https://crates.io/crates/either) (^1.3)
-- `enumset1` - [enumset](https://crates.io/crates/enumset) (^1.0)
 - `indexmap2` - [indexmap](https://crates.io/crates/indexmap) (^2.0)
 - `rust_decimal1` - [rust_decimal](https://crates.io/crates/rust_decimal) (^1.0)
 - `semver1` - [semver](https://crates.io/crates/semver) (^1.0.9)
diff --git a/docs/0-migrating.md b/docs/0-migrating.md
index 80fccb3..be79b36 100644
--- a/docs/0-migrating.md
+++ b/docs/0-migrating.md
@@ -23,10 +23,9 @@ All optional dependencies are now suffixed by their version:
 - `url` is now `url2`
 - `bytes` is now `bytes1`
 - `rust_decimal` is now `rust_decimal1`
-- `enumset` is now `enumset1`
 - `smol_str` is now `smol_str02`
 - `semver` is now `semver1`
-- `indexmap`, `uuid08`, `arrayvec05` and `bigdecimal03` have been removed
+- `enumset`, `indexmap`, `uuid08`, `arrayvec05` and `bigdecimal03` have been removed
 - `indexmap2`, `arrayvec07` and `bigdecimal04` are unchanged
 
 ## `Schema` is now a wrapper around `serde_json::Value`
diff --git a/docs/4-features.md b/docs/4-features.md
index c2b80d1..b0b2046 100644
--- a/docs/4-features.md
+++ b/docs/4-features.md
@@ -18,7 +18,6 @@ Schemars can implement `JsonSchema` on types from several popular crates, enable
 - `bytes1` - [bytes](https://crates.io/crates/bytes) (^1.0)
 - `chrono04` - [chrono](https://crates.io/crates/chrono) (^0.4)
 - `either1` - [either](https://crates.io/crates/either) (^1.3)
-- `enumset1` - [enumset](https://crates.io/crates/enumset) (^1.0)
 - `indexmap2` - [indexmap](https://crates.io/crates/indexmap) (^2.0)
 - `rust_decimal1` - [rust_decimal](https://crates.io/crates/rust_decimal) (^1.0)
 - `semver1` - [semver](https://crates.io/crates/semver) (^1.0.9)
diff --git a/schemars/Cargo.toml b/schemars/Cargo.toml
index 7645939..8139ae0 100644
--- a/schemars/Cargo.toml
+++ b/schemars/Cargo.toml
@@ -25,7 +25,6 @@ bigdecimal04 = { version = "0.4", default-features = false, optional = true, pac
 bytes1 = { version = "1.0", default-features = false, optional = true, package = "bytes" }
 chrono04 = { version = "0.4", default-features = false, optional = true, package = "chrono" }
 either1 = { version = "1.3", default-features = false, optional = true,  package = "either" }
-enumset1 = { version = "1.0", default-features = false, optional = true, package = "enumset" }
 indexmap2 = { version = "2.0", default-features = false, optional = true, package = "indexmap" }
 rust_decimal1 = { version = "1", default-features = false, optional = true, package = "rust_decimal"}
 semver1 = { version = "1.0.9", default-features = false, optional = true, package = "semver" }
@@ -104,10 +103,6 @@ required-features = ["arrayvec07"]
 name = "url"
 required-features = ["url2"]
 
-[[test]]
-name = "enumset"
-required-features = ["enumset1"]
-
 [[test]]
 name = "smol_str"
 required-features = ["smol_str02"]
diff --git a/schemars/src/json_schema_impls/mod.rs b/schemars/src/json_schema_impls/mod.rs
index 1921a6a..0a8bcb3 100644
--- a/schemars/src/json_schema_impls/mod.rs
+++ b/schemars/src/json_schema_impls/mod.rs
@@ -75,9 +75,6 @@ mod decimal;
 #[cfg(feature = "either1")]
 mod either1;
 
-#[cfg(feature = "enumset1")]
-forward_impl!((<T: enumset1::EnumSetType + crate::JsonSchema> crate::JsonSchema for enumset1::EnumSet<T>) => alloc::collections::BTreeSet<T>);
-
 #[cfg(feature = "indexmap2")]
 mod indexmap2;
 


Test patch:
diff --git a/schemars/tests/enumset.rs b/schemars/tests/enumset.rs
deleted file mode 100644
index c04ba0e..0000000
--- a/schemars/tests/enumset.rs
+++ /dev/null
@@ -1,18 +0,0 @@
-mod util;
-use enumset1::{EnumSet, EnumSetType};
-use schemars::JsonSchema;
-use util::*;
-
-// needed to derive EnumSetType when using a crate alias
-extern crate enumset1 as enumset;
-
-#[derive(EnumSetType, JsonSchema)]
-enum Foo {
-    Bar,
-    Baz,
-}
-
-#[test]
-fn enumset() -> TestResult {
-    test_default_generated_schema::<EnumSet<Foo>>("enumset")
-}