From f5a322386a6049ed14477de63d1fcd31a7d35490 Mon Sep 17 00:00:00 2001 From: Graham Esau Date: Sun, 27 Aug 2023 22:20:14 +0100 Subject: [PATCH 1/3] Update MSRV to 1.60 --- .github/workflows/ci.yml | 6 +++--- CHANGELOG.md | 2 +- README.md | 2 +- schemars/Cargo.toml | 2 +- schemars_derive/Cargo.toml | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c86e2ab5..d37634e9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,16 +7,16 @@ jobs: runs-on: ubuntu-latest env: # work-around https://github.com/rust-lang/cargo/issues/10303 - CARGO_NET_GIT_FETCH_WITH_CLI: ${{ matrix.rust == '1.56.0' }} + CARGO_NET_GIT_FETCH_WITH_CLI: ${{ matrix.rust == '1.60.0' }} strategy: matrix: rust: - - 1.56.0 + - 1.60.0 - stable - beta - nightly include: - - rust: 1.56.0 + - rust: 1.60.0 test_features: "--features impl_json_schema" allow_failure: false - rust: stable diff --git a/CHANGELOG.md b/CHANGELOG.md index 061a4a57..51f5f112 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ ### Changed: -- Minimum supported rust version is now 1.56.0 +- Minimum supported rust version is now 1.60.0 ## [0.8.12] - 2023-02-26 diff --git a/README.md b/README.md index 8e5a39c4..ed1489f0 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![CI Build](https://img.shields.io/github/actions/workflow/status/GREsau/schemars/ci.yml?branch=master&logo=GitHub)](https://github.com/GREsau/schemars/actions) [![Crates.io](https://img.shields.io/crates/v/schemars)](https://crates.io/crates/schemars) [![Docs](https://docs.rs/schemars/badge.svg)](https://docs.rs/schemars) -[![MSRV 1.56+](https://img.shields.io/badge/schemars-rustc_1.56+-lightgray.svg)](https://blog.rust-lang.org/2021/10/21/Rust-1.56.0.html) +[![MSRV 1.60+](https://img.shields.io/badge/schemars-rustc_1.60+-lightgray.svg)](https://blog.rust-lang.org/2022/04/07/Rust-1.60.0.html) Generate JSON Schema documents from Rust code diff --git a/schemars/Cargo.toml b/schemars/Cargo.toml index aaf7b3d8..de804386 100644 --- a/schemars/Cargo.toml +++ b/schemars/Cargo.toml @@ -11,7 +11,7 @@ readme = "README.md" keywords = ["rust", "json-schema", "serde"] categories = ["encoding"] build = "build.rs" -rust-version = "1.56" +rust-version = "1.60" [dependencies] schemars_derive = { version = "=0.8.12", optional = true, path = "../schemars_derive" } diff --git a/schemars_derive/Cargo.toml b/schemars_derive/Cargo.toml index 8bb235e7..0b34e492 100644 --- a/schemars_derive/Cargo.toml +++ b/schemars_derive/Cargo.toml @@ -9,7 +9,7 @@ edition = "2021" license = "MIT" readme = "README.md" keywords = ["rust", "json-schema", "serde"] -rust-version = "1.56" +rust-version = "1.60" [lib] proc-macro = true From 38b44a4275dfe7ed1d644dd3af3ca4d1f67ef371 Mon Sep 17 00:00:00 2001 From: David Knaack Date: Tue, 27 Jun 2023 15:15:13 +0200 Subject: [PATCH 2/3] Add support for indexmap v2 --- schemars/Cargo.toml | 5 +++++ schemars/src/json_schema_impls/indexmap2.rs | 8 ++++++++ schemars/src/json_schema_impls/mod.rs | 2 ++ schemars/tests/indexmap2.rs | 16 ++++++++++++++++ 4 files changed, 31 insertions(+) create mode 100644 schemars/src/json_schema_impls/indexmap2.rs create mode 100644 schemars/tests/indexmap2.rs 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") +} From 4b0d087a283b6f4f6b5df24fb7dedc9ded180a0a Mon Sep 17 00:00:00 2001 From: Graham Esau Date: Sun, 27 Aug 2023 22:56:27 +0100 Subject: [PATCH 3/3] Update docs and changelog --- CHANGELOG.md | 1 + README.md | 1 + docs/4-features.md | 3 +++ 3 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 51f5f112..8d654449 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Implement `JsonSchema` for `semver::Version` (https://github.com/GREsau/schemars/pull/195 / https://github.com/GREsau/schemars/pull/238) - Include const generics in generated schema names (https://github.com/GREsau/schemars/pull/179 / https://github.com/GREsau/schemars/pull/239) +- Implement `JsonSchema` for types from indexmap v2 (https://github.com/GREsau/schemars/pull/226 / https://github.com/GREsau/schemars/pull/240) ### Changed: diff --git a/README.md b/README.md index ed1489f0..52b368f6 100644 --- a/README.md +++ b/README.md @@ -258,6 +258,7 @@ Schemars can implement `JsonSchema` on types from several popular crates, enable - `chrono` - [chrono](https://crates.io/crates/chrono) (^0.4) - `indexmap1` - [indexmap](https://crates.io/crates/indexmap) (^1.2) +- `indexmap2` - [indexmap](https://crates.io/crates/indexmap) (^2.0) - `either` - [either](https://crates.io/crates/either) (^1.3) - `uuid08` - [uuid](https://crates.io/crates/uuid) (^0.8) - `uuid1` - [uuid](https://crates.io/crates/uuid) (^1.0) diff --git a/docs/4-features.md b/docs/4-features.md index 51127739..9c7e0a5e 100644 --- a/docs/4-features.md +++ b/docs/4-features.md @@ -6,13 +6,16 @@ permalink: /features/ --- # Feature Flags and Optional Dependencies + - `derive` (enabled by default) - provides `#[derive(JsonSchema)]` macro - `impl_json_schema` - implements `JsonSchema` for Schemars types themselves - `preserve_order` - keep the order of struct fields in `Schema` and `SchemaObject` Schemars can implement `JsonSchema` on types from several popular crates, enabled via feature flags (dependency versions are shown in brackets): + - `chrono` - [chrono](https://crates.io/crates/chrono) (^0.4) - `indexmap1` - [indexmap](https://crates.io/crates/indexmap) (^1.2) +- `indexmap2` - [indexmap](https://crates.io/crates/indexmap) (^2.0) - `either` - [either](https://crates.io/crates/either) (^1.3) - `uuid08` - [uuid](https://crates.io/crates/uuid) (^0.8) - `uuid1` - [uuid](https://crates.io/crates/uuid) (^1.0)