Skip to content

Commit

Permalink
impl JsonSchema for basic camino types
Browse files Browse the repository at this point in the history
  • Loading branch information
dbanty committed Apr 12, 2023
1 parent 386e3d7 commit 9118aba
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
1 change: 1 addition & 0 deletions schemars/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
36 changes: 36 additions & 0 deletions schemars/src/json_schema_impls/camino.rs
Original file line number Diff line number Diff line change
@@ -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()
}
}
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 @@ -75,3 +75,5 @@ mod uuid08;
#[cfg(feature = "uuid1")]
mod uuid1;
mod wrapper;
#[cfg(feature = "camino")]
mod camino;
1 change: 1 addition & 0 deletions schemars/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 9118aba

Please sign in to comment.