Skip to content

Commit

Permalink
Add support for indexmap v2
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkna authored and GREsau committed Aug 27, 2023
1 parent 5dbfa49 commit aeb9894
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions schemars/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down Expand Up @@ -69,6 +70,10 @@ required-features = ["chrono"]
name = "indexmap"
required-features = ["indexmap"]

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

[[test]]
name = "either"
required-features = ["either"]
Expand Down
8 changes: 8 additions & 0 deletions schemars/src/json_schema_impls/indexmap2.rs
Original file line number Diff line number Diff line change
@@ -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!((<K, V: JsonSchema, H> JsonSchema for IndexMap<K, V, H>) => HashMap<K, V, H>);
forward_impl!((<T: JsonSchema, H> JsonSchema for IndexSet<T, H>) => HashSet<T, H>);
2 changes: 2 additions & 0 deletions schemars/src/json_schema_impls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions schemars/tests/indexmap2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
mod util;
use indexmap2::{IndexMap, IndexSet};
use schemars::JsonSchema;
use util::*;

#[allow(dead_code)]
#[derive(JsonSchema)]
struct IndexMapTypes {
map: IndexMap<i32, bool>,
set: IndexSet<isize>,
}

#[test]
fn indexmap_types() -> TestResult {
test_default_generated_schema::<IndexMapTypes>("indexmap")
}

0 comments on commit aeb9894

Please sign in to comment.