Skip to main content

rskit_schema/
document.rs

1//! Typed JSON Schema document wrapper.
2
3use rskit_errors::AppResult;
4use serde_json::Value;
5
6use crate::{Json, ValidationLimits, limits::check_json_limits};
7
8/// Owned JSON Schema document that has passed structural limit checks.
9#[derive(Debug, Clone, PartialEq)]
10pub struct SchemaDocument {
11    value: Json,
12}
13
14impl SchemaDocument {
15    /// Create a schema document with default structural limits.
16    pub fn new(value: Json) -> AppResult<Self> {
17        Self::with_limits(value, ValidationLimits::default())
18    }
19
20    /// Create a schema document with custom structural limits.
21    pub fn with_limits(value: Json, limits: ValidationLimits) -> AppResult<Self> {
22        check_json_limits("schema", &value, limits)?;
23        Ok(Self { value })
24    }
25
26    /// Borrow the raw JSON schema value.
27    pub fn as_json(&self) -> &Value {
28        &self.value
29    }
30
31    /// Consume this document and return the raw JSON schema value.
32    #[must_use]
33    pub fn into_json(self) -> Json {
34        self.value
35    }
36}