diff --git a/schemars/Cargo.toml b/schemars/Cargo.toml index de804386..8470a24f 100644 --- a/schemars/Cargo.toml +++ b/schemars/Cargo.toml @@ -21,6 +21,7 @@ dyn-clone = "1.0" 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" } uuid1 = { version = "1.0", default-features = false, optional = true, package = "uuid" } @@ -69,6 +70,10 @@ required-features = ["chrono"] name = "indexmap" required-features = ["indexmap"] +[[test]] +name = "indexmap2" +required-features = ["indexmap2"] + [[test]] name = "either" required-features = ["either"] diff --git a/schemars/src/json_schema_impls/indexmap2.rs b/schemars/src/json_schema_impls/indexmap2.rs new file mode 100644 index 00000000..44eeedb3 --- /dev/null +++ b/schemars/src/json_schema_impls/indexmap2.rs @@ -0,0 +1,8 @@ +use crate::gen::SchemaGenerator; +use crate::schema::*; +use crate::JsonSchema; +use indexmap2::{IndexMap, IndexSet}; +use std::collections::{HashMap, HashSet}; + +forward_impl!(( JsonSchema for IndexMap) => HashMap); +forward_impl!(( JsonSchema for IndexSet) => HashSet); diff --git a/schemars/src/json_schema_impls/mod.rs b/schemars/src/json_schema_impls/mod.rs index d96bf382..22d1c46b 100644 --- a/schemars/src/json_schema_impls/mod.rs +++ b/schemars/src/json_schema_impls/mod.rs @@ -56,6 +56,8 @@ mod enumset; mod ffi; #[cfg(feature = "indexmap")] mod indexmap; +#[cfg(feature = "indexmap2")] +mod indexmap2; mod maps; mod nonzero_signed; mod nonzero_unsigned; diff --git a/schemars/tests/indexmap2.rs b/schemars/tests/indexmap2.rs new file mode 100644 index 00000000..efc77ddf --- /dev/null +++ b/schemars/tests/indexmap2.rs @@ -0,0 +1,16 @@ +mod util; +use indexmap2::{IndexMap, IndexSet}; +use schemars::JsonSchema; +use util::*; + +#[allow(dead_code)] +#[derive(JsonSchema)] +struct IndexMapTypes { + map: IndexMap, + set: IndexSet, +} + +#[test] +fn indexmap_types() -> TestResult { + test_default_generated_schema::("indexmap") +}