diff --git a/schemars/Cargo.toml b/schemars/Cargo.toml index 51fd64c..bf5d6b9 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.17", optional = true } [dev-dependencies] pretty_assertions = "1.2.1" @@ -102,5 +103,9 @@ required-features = ["url"] name = "enumset" required-features = ["enumset"] +[[test]] +name = "smol_str" +required-features = ["smol_str"] + [package.metadata.docs.rs] all-features = true diff --git a/schemars/src/json_schema_impls/mod.rs b/schemars/src/json_schema_impls/mod.rs index 9925442..490a544 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 0000000..cbca4a1 --- /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!(SmolStr => String); diff --git a/schemars/tests/expected/smol_str.json b/schemars/tests/expected/smol_str.json new file mode 100644 index 0000000..42f099a --- /dev/null +++ b/schemars/tests/expected/smol_str.json @@ -0,0 +1,5 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "String", + "type": "string" +} \ No newline at end of file diff --git a/schemars/tests/smol_str.rs b/schemars/tests/smol_str.rs new file mode 100644 index 0000000..1e48196 --- /dev/null +++ b/schemars/tests/smol_str.rs @@ -0,0 +1,8 @@ +mod util; +use smol_str::SmolStr; +use util::*; + +#[test] +fn smol_str() -> TestResult { + test_default_generated_schema::("smol_str") +}