diff --git a/Cargo.lock b/Cargo.lock index 82b84cf4..3976f8aa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -334,6 +334,7 @@ checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" dependencies = [ "equivalent", "hashbrown", + "serde", ] [[package]] diff --git a/schemars/Cargo.toml b/schemars/Cargo.toml index 1fcb99b9..3e6b91f7 100644 --- a/schemars/Cargo.toml +++ b/schemars/Cargo.toml @@ -49,6 +49,7 @@ chrono04 = { version = "0.4", default-features = false, features = ["serde"], pa bigdecimal04 = { version = "0.4", default-features = false, features = ["serde"], package = "bigdecimal" } rust_decimal1 = { version = "1", default-features = false, features = ["serde"], package = "rust_decimal" } either1 = { version = "1.3", default-features = false, features = ["serde"], package = "either" } +indexmap2 = { version = "2.0", default-features = false, features = ["serde"], package = "indexmap" } [features] default = ["derive", "std"] diff --git a/schemars/tests/expected/indexmap.json b/schemars/tests/expected/indexmap.json deleted file mode 100644 index 8ba90a85..00000000 --- a/schemars/tests/expected/indexmap.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "title": "IndexMapTypes", - "type": "object", - "properties": { - "map": { - "type": "object", - "additionalProperties": { - "type": "boolean" - } - }, - "set": { - "type": "array", - "uniqueItems": true, - "items": { - "type": "integer", - "format": "int" - } - } - }, - "required": [ - "map", - "set" - ] -} \ No newline at end of file diff --git a/schemars/tests/indexmap.rs b/schemars/tests/indexmap.rs deleted file mode 100644 index 76fcd560..00000000 --- a/schemars/tests/indexmap.rs +++ /dev/null @@ -1,18 +0,0 @@ -mod util; -use std::collections::hash_map::RandomState; - -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") -} diff --git a/schemars/tests/integration/indexmap.rs b/schemars/tests/integration/indexmap.rs new file mode 100644 index 00000000..c6ef7d54 --- /dev/null +++ b/schemars/tests/integration/indexmap.rs @@ -0,0 +1,19 @@ +use crate::prelude::*; +use indexmap2::{indexmap, indexset, IndexMap, IndexSet}; +use std::collections::{BTreeMap, BTreeSet}; + +#[test] +fn indexmap() { + test!(IndexMap) + .assert_identical::>() + .assert_allows_ser_roundtrip([indexmap!(), indexmap!("key".to_owned() => true)]) + .assert_matches_de_roundtrip(arbitrary_values()); +} + +#[test] +fn indexset() { + test!(IndexSet) + .assert_identical::>() + .assert_allows_ser_roundtrip([indexset!(), indexset!("test".to_owned())]) + .assert_matches_de_roundtrip(arbitrary_values()); +} diff --git a/schemars/tests/integration/main.rs b/schemars/tests/integration/main.rs index b750ebfe..622d6d5b 100644 --- a/schemars/tests/integration/main.rs +++ b/schemars/tests/integration/main.rs @@ -24,6 +24,8 @@ mod extend; mod flatten; mod from_value; mod garde; +#[cfg(feature = "indexmap2")] +mod indexmap; mod std_types; mod prelude { @@ -36,6 +38,7 @@ mod prelude { mod test_helper; +#[macro_export] macro_rules! test_name { () => {{ fn f() {} @@ -51,20 +54,18 @@ macro_rules! test_name { }}; } +#[macro_export] macro_rules! test { ($type:ty, $settings:expr) => { - $crate::test_helper::TestHelper::<$type>::new(crate::test_name!(), $settings) + $crate::test_helper::TestHelper::<$type>::new($crate::test_name!(), $settings) }; ($type:ty) => { test!($type, schemars::generate::SchemaSettings::default()) }; (value: $value:expr, $settings:expr) => { - $crate::test_helper::TestHelper::new_for_value(crate::test_name!(), $settings, $value) + $crate::test_helper::TestHelper::new_for_value($crate::test_name!(), $settings, $value) }; (value: $value:expr) => { test!(value: $value, schemars::generate::SchemaSettings::default()) }; } - -use test; -use test_name;