Skip to content

Commit 92b6b10

Browse files
authored
Add a JSON Schema implementation for the regex crate (#9)
It's basically just a string anyway. Merge #8 first. See also oxc-project/oxc#15978 Resolves oxc-project/oxc#15203
1 parent fd165bb commit 92b6b10

File tree

5 files changed

+66
-0
lines changed

5 files changed

+66
-0
lines changed

Cargo.lock

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

schemars/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ bigdecimal04 = { version = "0.4", default-features = false, optional = true, pac
4040
enumset = { version = "1.0", optional = true }
4141
smol_str = { version = "0.1.17", optional = true }
4242
semver = { version = "1.0.9", features = ["serde"], optional = true }
43+
regex = { version = "1.12", optional = true }
4344

4445
[dev-dependencies]
4546
pretty_assertions = "1.2.1"
@@ -123,6 +124,10 @@ required-features = ["enumset"]
123124
name = "smol_str"
124125
required-features = ["smol_str"]
125126

127+
[[test]]
128+
name = "regex"
129+
required-features = ["regex"]
130+
126131
[[test]]
127132
name = "semver"
128133
required-features = ["semver"]

schemars/src/json_schema_impls/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,5 @@ mod uuid08;
8787
#[cfg(feature = "uuid1")]
8888
mod uuid1;
8989
mod wrapper;
90+
#[cfg(feature = "regex")]
91+
mod regex;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
use crate::r#gen::SchemaGenerator;
2+
use crate::schema::*;
3+
use crate::JsonSchema;
4+
use regex::Regex;
5+
6+
forward_impl!(Regex => String);

schemars/tests/regex.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
mod util;
2+
use regex::Regex;
3+
use util::*;
4+
5+
#[test]
6+
fn regex() -> TestResult {
7+
test_default_generated_schema::<Regex>("regex")
8+
}

0 commit comments

Comments
 (0)