File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed
Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change 11//! A wrapper around a JSON Schema validator.
22
3- use std:: ops:: Deref ;
3+ use std:: { ops:: Deref , sync :: Arc } ;
44
55use anyhow:: anyhow;
66use jsonschema:: { options, Draft , Validator } ;
@@ -11,7 +11,8 @@ use serde_json::Value;
1111/// Attempts to detect the draft version from the `$schema` field.
1212/// If not specified, it tries Draft2020-12 first, then falls back to Draft7.
1313/// Returns an error if schema is invalid for both.
14- pub struct JsonSchema ( Validator ) ;
14+ #[ derive( Clone ) ]
15+ pub struct JsonSchema ( Arc < Validator > ) ;
1516
1617impl Deref for JsonSchema {
1718 type Target = Validator ;
@@ -43,17 +44,17 @@ impl TryFrom<&Value> for JsonSchema {
4344 . build ( schema)
4445 . map_err ( |e| anyhow ! ( "Invalid JSON Schema: {e}" ) ) ?;
4546
46- Ok ( JsonSchema ( validator) )
47+ Ok ( JsonSchema ( validator. into ( ) ) )
4748 } else {
4849 // if draft not specified or not detectable:
4950 // try draft2020-12
5051 if let Ok ( validator) = options ( ) . with_draft ( Draft :: Draft202012 ) . build ( schema) {
51- return Ok ( JsonSchema ( validator) ) ;
52+ return Ok ( JsonSchema ( validator. into ( ) ) ) ;
5253 }
5354
5455 // fallback to draft7
5556 if let Ok ( validator) = options ( ) . with_draft ( Draft :: Draft7 ) . build ( schema) {
56- return Ok ( JsonSchema ( validator) ) ;
57+ return Ok ( JsonSchema ( validator. into ( ) ) ) ;
5758 }
5859
5960 Err ( anyhow ! (
You can’t perform that action at this time.
0 commit comments