use alloc::string::String;
use serde_json::Value;
use crate::error::{ErrorIterator, ValidationError};
use crate::node::SchemaNode;
use crate::paths::LazyLocation;
use super::{Validate, ValidationContext};
pub struct RefValidator {
#[allow(dead_code)]
reference: String,
#[allow(dead_code)]
schema_path: crate::paths::Location,
resolved_schema: SchemaNode,
}
impl RefValidator {
#[must_use]
pub fn new(
reference: String,
schema_path: crate::paths::Location,
resolved_schema: SchemaNode,
) -> Self {
Self {
reference,
schema_path,
resolved_schema,
}
}
}
impl Validate for RefValidator {
fn is_valid(&self, instance: &Value, ctx: &mut ValidationContext) -> bool {
self.resolved_schema.is_valid(instance, ctx)
}
fn validate(
&self,
instance: &Value,
instance_path: &LazyLocation<'_>,
ctx: &mut ValidationContext,
) -> Result<(), ValidationError> {
self.resolved_schema.validate(instance, instance_path, ctx)
}
fn iter_errors(
&self,
instance: &Value,
instance_path: &LazyLocation<'_>,
ctx: &mut ValidationContext,
) -> ErrorIterator {
self.resolved_schema
.iter_errors(instance, instance_path, ctx)
}
}
pub struct DynamicRefValidator {
#[allow(dead_code)]
reference: String,
#[allow(dead_code)]
schema_path: crate::paths::Location,
resolved_schema: SchemaNode,
}
impl DynamicRefValidator {
#[must_use]
pub fn new(
reference: String,
schema_path: crate::paths::Location,
resolved_schema: SchemaNode,
) -> Self {
Self {
reference,
schema_path,
resolved_schema,
}
}
}
impl Validate for DynamicRefValidator {
fn is_valid(&self, instance: &Value, ctx: &mut ValidationContext) -> bool {
self.resolved_schema.is_valid(instance, ctx)
}
fn validate(
&self,
instance: &Value,
instance_path: &LazyLocation<'_>,
ctx: &mut ValidationContext,
) -> Result<(), ValidationError> {
self.resolved_schema.validate(instance, instance_path, ctx)
}
fn iter_errors(
&self,
instance: &Value,
instance_path: &LazyLocation<'_>,
ctx: &mut ValidationContext,
) -> ErrorIterator {
self.resolved_schema
.iter_errors(instance, instance_path, ctx)
}
}
pub struct RecursiveRefValidator {
#[allow(dead_code)]
reference: String,
#[allow(dead_code)]
schema_path: crate::paths::Location,
resolved_schema: SchemaNode,
}
impl RecursiveRefValidator {
#[must_use]
pub fn new(
reference: String,
schema_path: crate::paths::Location,
resolved_schema: SchemaNode,
) -> Self {
Self {
reference,
schema_path,
resolved_schema,
}
}
}
impl Validate for RecursiveRefValidator {
fn is_valid(&self, instance: &Value, ctx: &mut ValidationContext) -> bool {
self.resolved_schema.is_valid(instance, ctx)
}
fn validate(
&self,
instance: &Value,
instance_path: &LazyLocation<'_>,
ctx: &mut ValidationContext,
) -> Result<(), ValidationError> {
self.resolved_schema.validate(instance, instance_path, ctx)
}
fn iter_errors(
&self,
instance: &Value,
instance_path: &LazyLocation<'_>,
ctx: &mut ValidationContext,
) -> ErrorIterator {
self.resolved_schema
.iter_errors(instance, instance_path, ctx)
}
}