Skip to content

Commit c2a342b

Browse files
committed
fix schema doc tests
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
1 parent 48b51ed commit c2a342b

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

src/engine.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,10 +510,11 @@ impl Engine {
510510
/// engine.enable_type_checking();
511511
///
512512
/// // Set input schema
513+
/// # #[cfg(feature = "jsonschema")]
513514
/// if let Some(checker) = engine.get_type_checker_mut() {
514515
/// let schema = Schema::from_json_str(
515516
/// r#"{"type": "object", "properties": {"value": {"type": "integer"}}}"#
516-
/// )?;
517+
/// ).map_err(|e| anyhow::anyhow!("{e}"))?;
517518
/// checker.set_input_schema(schema);
518519
/// }
519520
///

src/schema.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ pub mod validate;
214214
/// Schemas are typically created by deserializing from JSON Schema format:
215215
///
216216
/// ```rust
217+
/// use regorus::schema::Schema;
217218
/// use serde_json::json;
218219
///
219220
/// // Create a schema from JSON
@@ -253,12 +254,16 @@ pub mod validate;
253254
///
254255
/// ## Simple String Schema
255256
/// ```rust
257+
/// # use regorus::schema::Schema;
258+
/// # use serde_json::json;
256259
/// let schema = json!({ "type": "string", "minLength": 1 });
257260
/// let parsed: Schema = serde_json::from_value(schema).unwrap();
258261
/// ```
259262
///
260263
/// ## Complex Object Schema
261264
/// ```rust
265+
/// # use regorus::schema::Schema;
266+
/// # use serde_json::json;
262267
/// let schema = json!({
263268
/// "type": "object",
264269
/// "properties": {
@@ -280,6 +285,8 @@ pub mod validate;
280285
///
281286
/// ## Union Types with anyOf
282287
/// ```rust
288+
/// # use regorus::schema::Schema;
289+
/// # use serde_json::json;
283290
/// let schema = json!({
284291
/// "anyOf": [
285292
/// { "type": "string" },

src/type_checker.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,17 @@ use anyhow::Result;
3939
/// )?;
4040
///
4141
/// let modules = engine.get_modules();
42+
/// let modules = Rc::new(modules.clone());
4243
/// let mut type_checker = TypeChecker::new(modules);
4344
///
4445
/// // Optionally set input schema
45-
/// let input_schema = Schema::from_json_str(r#"{"type": "object", "properties": {"user": {"type": "string"}}}"#)?;
46-
/// type_checker.set_input_schema(input_schema);
46+
/// #[cfg(feature = "jsonschema")]
47+
/// {
48+
/// let input_schema = Schema::from_json_str(
49+
/// r#"{"type": "object", "properties": {"user": {"type": "string"}}}"#
50+
/// ).map_err(|e| anyhow::anyhow!("{e}"))?;
51+
/// type_checker.set_input_schema(input_schema);
52+
/// }
4753
///
4854
/// // Run type analysis
4955
/// type_checker.check()?;

0 commit comments

Comments
 (0)