From 19c5410ef062d787f69e12bb721cdb74eba597d4 Mon Sep 17 00:00:00 2001 From: novacrazy Date: Sun, 18 Dec 2022 20:32:28 -0600 Subject: [PATCH 1/2] Add forward_impl for SmolStr --- schemars/Cargo.toml | 1 + schemars/src/json_schema_impls/mod.rs | 2 ++ schemars/src/json_schema_impls/smol_str.rs | 6 ++++++ 3 files changed, 9 insertions(+) create mode 100644 schemars/src/json_schema_impls/smol_str.rs diff --git a/schemars/Cargo.toml b/schemars/Cargo.toml index 51fd64ce..03d033ef 100644 --- a/schemars/Cargo.toml +++ b/schemars/Cargo.toml @@ -31,6 +31,7 @@ bytes = { version = "1.0", optional = true } rust_decimal = { version = "1", default-features = false, optional = true } bigdecimal = { version = "0.3", default-features = false, optional = true } enumset = { version = "1.0", optional = true } +smol_str = { version = "0.1", optional = true } [dev-dependencies] pretty_assertions = "1.2.1" diff --git a/schemars/src/json_schema_impls/mod.rs b/schemars/src/json_schema_impls/mod.rs index 99254423..490a544e 100644 --- a/schemars/src/json_schema_impls/mod.rs +++ b/schemars/src/json_schema_impls/mod.rs @@ -64,6 +64,8 @@ mod sequences; mod serdejson; #[cfg(feature = "smallvec")] mod smallvec; +#[cfg(feature = "smol_str")] +mod smol_str; mod time; mod tuple; #[cfg(feature = "url")] diff --git a/schemars/src/json_schema_impls/smol_str.rs b/schemars/src/json_schema_impls/smol_str.rs new file mode 100644 index 00000000..7ecc8b20 --- /dev/null +++ b/schemars/src/json_schema_impls/smol_str.rs @@ -0,0 +1,6 @@ +use crate::gen::SchemaGenerator; +use crate::schema::*; +use crate::JsonSchema; +use smol_str::SmolStr; + +forward_impl!((JsonSchema for SmolStr) => String); From ed031707d78480b4ef7130fdaba88e3c960266c1 Mon Sep 17 00:00:00 2001 From: novacrazy Date: Sun, 18 Dec 2022 20:35:03 -0600 Subject: [PATCH 2/2] Document feature --- README.md | 1 + schemars/src/lib.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/README.md b/README.md index a94bf7ff..ae508382 100644 --- a/README.md +++ b/README.md @@ -278,6 +278,7 @@ Schemars can implement `JsonSchema` on types from several popular crates, enable - `enumset` - [enumset](https://crates.io/crates/enumset) (^1.0) - `rust_decimal` - [rust_decimal](https://crates.io/crates/rust_decimal) (^1.0) - `bigdecimal` - [bigdecimal](https://crates.io/crates/bigdecimal) (^0.3) +- `smol_str` - [smol_str](https://crates.io/crates/smol_str) (^0.1) For example, to implement `JsonSchema` on types from `chrono`, enable it as a feature in the `schemars` dependency in your `Cargo.toml` like so: diff --git a/schemars/src/lib.rs b/schemars/src/lib.rs index 2094c428..5c12cf0f 100644 --- a/schemars/src/lib.rs +++ b/schemars/src/lib.rs @@ -273,6 +273,7 @@ Schemars can implement `JsonSchema` on types from several popular crates, enable - `enumset` - [enumset](https://crates.io/crates/enumset) (^1.0) - `rust_decimal` - [rust_decimal](https://crates.io/crates/rust_decimal) (^1.0) - `bigdecimal` - [bigdecimal](https://crates.io/crates/bigdecimal) (^0.3) +- `smol_str` - [smol_str](https://crates.io/crates/smol_str) (^0.1) For example, to implement `JsonSchema` on types from `chrono`, enable it as a feature in the `schemars` dependency in your `Cargo.toml` like so: