diff --git a/README.md b/README.md index 7ff05e0f..f83649b2 100644 --- a/README.md +++ b/README.md @@ -279,6 +279,7 @@ Schemars can implement `JsonSchema` on types from several popular crates, enable - `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.17) +- `camino` - [camino](https://crates.io/crates/camino) (^1.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/Cargo.toml b/schemars/Cargo.toml index ad972dd9..967fe00a 100644 --- a/schemars/Cargo.toml +++ b/schemars/Cargo.toml @@ -18,6 +18,7 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "1.0.25" dyn-clone = "1.0" +camino = { version = "1.1", optional = true } chrono = { version = "0.4", default-features = false, optional = true } indexmap = { version = "1.2", features = ["serde-1"], optional = true } either = { version = "1.3", default-features = false, optional = true } diff --git a/schemars/src/json_schema_impls/camino.rs b/schemars/src/json_schema_impls/camino.rs new file mode 100644 index 00000000..3fdfe583 --- /dev/null +++ b/schemars/src/json_schema_impls/camino.rs @@ -0,0 +1,36 @@ +use crate::gen::SchemaGenerator; +use crate::schema::*; +use crate::JsonSchema; +use camino::{Utf8Path, Utf8PathBuf}; + +impl JsonSchema for Utf8Path { + no_ref_schema!(); + + fn schema_name() -> String { + "String".to_owned() + } + + fn json_schema(_: &mut SchemaGenerator) -> Schema { + SchemaObject { + instance_type: Some(InstanceType::String.into()), + ..Default::default() + } + .into() + } +} + +impl JsonSchema for Utf8PathBuf { + no_ref_schema!(); + + fn schema_name() -> String { + "String".to_owned() + } + + fn json_schema(_: &mut SchemaGenerator) -> Schema { + SchemaObject { + instance_type: Some(InstanceType::String.into()), + ..Default::default() + } + .into() + } +} diff --git a/schemars/src/json_schema_impls/mod.rs b/schemars/src/json_schema_impls/mod.rs index 490a544e..4952c242 100644 --- a/schemars/src/json_schema_impls/mod.rs +++ b/schemars/src/json_schema_impls/mod.rs @@ -75,3 +75,5 @@ mod uuid08; #[cfg(feature = "uuid1")] mod uuid1; mod wrapper; +#[cfg(feature = "camino")] +mod camino; diff --git a/schemars/src/lib.rs b/schemars/src/lib.rs index 796ec272..31532979 100644 --- a/schemars/src/lib.rs +++ b/schemars/src/lib.rs @@ -274,6 +274,7 @@ Schemars can implement `JsonSchema` on types from several popular crates, enable - `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.17) +- `camino` - [camino](https://crates.io/crates/camino) (^1.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: