Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for indexmap v2 #240

Merged
merged 3 commits into from
Aug 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

- 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:

- Minimum supported rust version is now 1.56.0
- Minimum supported rust version is now 1.60.0

## [0.8.12] - 2023-02-26

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions docs/4-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion schemars/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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")
}
2 changes: 1 addition & 1 deletion schemars_derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down