Skip to content

Commit 023cb9e

Browse files
committed
wip
1 parent 17286ee commit 023cb9e

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

rust/catalyst-types/src/json_schema.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! A wrapper around a JSON Schema validator.
22
3-
use std::ops::Deref;
3+
use std::{ops::Deref, sync::Arc};
44

55
use anyhow::anyhow;
66
use 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

1617
impl 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!(

0 commit comments

Comments
 (0)