Skip to content

Commit 9118aba

Browse files
committed
impl JsonSchema for basic camino types
1 parent 386e3d7 commit 9118aba

File tree

5 files changed

+41
-0
lines changed

5 files changed

+41
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ Schemars can implement `JsonSchema` on types from several popular crates, enable
279279
- `rust_decimal` - [rust_decimal](https://crates.io/crates/rust_decimal) (^1.0)
280280
- `bigdecimal` - [bigdecimal](https://crates.io/crates/bigdecimal) (^0.3)
281281
- `smol_str` - [smol_str](https://crates.io/crates/smol_str) (^0.1.17)
282+
- `camino` - [camino](https://crates.io/crates/camino) (^1.1)
282283

283284
For example, to implement `JsonSchema` on types from `chrono`, enable it as a feature in the `schemars` dependency in your `Cargo.toml` like so:
284285

schemars/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ serde = { version = "1.0", features = ["derive"] }
1818
serde_json = "1.0.25"
1919
dyn-clone = "1.0"
2020

21+
camino = { version = "1.1", optional = true }
2122
chrono = { version = "0.4", default-features = false, optional = true }
2223
indexmap = { version = "1.2", features = ["serde-1"], optional = true }
2324
either = { version = "1.3", default-features = false, optional = true }
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use crate::gen::SchemaGenerator;
2+
use crate::schema::*;
3+
use crate::JsonSchema;
4+
use camino::{Utf8Path, Utf8PathBuf};
5+
6+
impl JsonSchema for Utf8Path {
7+
no_ref_schema!();
8+
9+
fn schema_name() -> String {
10+
"String".to_owned()
11+
}
12+
13+
fn json_schema(_: &mut SchemaGenerator) -> Schema {
14+
SchemaObject {
15+
instance_type: Some(InstanceType::String.into()),
16+
..Default::default()
17+
}
18+
.into()
19+
}
20+
}
21+
22+
impl JsonSchema for Utf8PathBuf {
23+
no_ref_schema!();
24+
25+
fn schema_name() -> String {
26+
"String".to_owned()
27+
}
28+
29+
fn json_schema(_: &mut SchemaGenerator) -> Schema {
30+
SchemaObject {
31+
instance_type: Some(InstanceType::String.into()),
32+
..Default::default()
33+
}
34+
.into()
35+
}
36+
}

schemars/src/json_schema_impls/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,5 @@ mod uuid08;
7575
#[cfg(feature = "uuid1")]
7676
mod uuid1;
7777
mod wrapper;
78+
#[cfg(feature = "camino")]
79+
mod camino;

schemars/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ Schemars can implement `JsonSchema` on types from several popular crates, enable
274274
- `rust_decimal` - [rust_decimal](https://crates.io/crates/rust_decimal) (^1.0)
275275
- `bigdecimal` - [bigdecimal](https://crates.io/crates/bigdecimal) (^0.3)
276276
- `smol_str` - [smol_str](https://crates.io/crates/smol_str) (^0.1.17)
277+
- `camino` - [camino](https://crates.io/crates/camino) (^1.1)
277278
278279
For example, to implement `JsonSchema` on types from `chrono`, enable it as a feature in the `schemars` dependency in your `Cargo.toml` like so:
279280

0 commit comments

Comments
 (0)