chore: Pass arena everywhere
This commit is contained in:
parent
bfe69d393a
commit
1b07188a3a
|
@ -4,6 +4,7 @@
|
|||
pub(crate) mod context;
|
||||
pub(crate) mod options;
|
||||
|
||||
use crate::keywords::BoxedValidator;
|
||||
use crate::{
|
||||
error::ErrorIterator,
|
||||
keywords,
|
||||
|
@ -34,6 +35,19 @@ lazy_static::lazy_static! {
|
|||
pub static ref DEFAULT_SCOPE: Url = url::Url::parse(DEFAULT_ROOT_URL).expect("Is a valid URL");
|
||||
}
|
||||
|
||||
pub(crate) struct ValidatorArena(Vec<BoxedValidator>);
|
||||
|
||||
impl ValidatorArena {
|
||||
pub(crate) fn new() -> Self {
|
||||
Self(Vec::new())
|
||||
}
|
||||
pub(crate) fn push(&mut self, validator: impl Validate + 'static) -> usize {
|
||||
let index = self.0.len();
|
||||
self.0.push(Box::new(validator));
|
||||
index
|
||||
}
|
||||
}
|
||||
|
||||
impl JSONSchema {
|
||||
/// Return a default `CompilationOptions` that can configure
|
||||
/// `JSONSchema` compilaton flow.
|
||||
|
@ -139,6 +153,7 @@ impl JSONSchema {
|
|||
pub(crate) fn compile_validators<'a, 'c>(
|
||||
schema: &'a Value,
|
||||
context: &'c CompilationContext,
|
||||
arena: &'c mut ValidatorArena,
|
||||
) -> Result<SchemaNode, ValidationError<'a>> {
|
||||
let context = context.push(schema)?;
|
||||
let relative_path = context.clone().into_pointer();
|
||||
|
@ -202,7 +217,7 @@ pub(crate) fn compile_validators<'a, 'c>(
|
|||
.config
|
||||
.draft()
|
||||
.get_validator(keyword)
|
||||
.and_then(|f| f(object, subschema, &context))
|
||||
.and_then(|f| f(object, subschema, &context, arena))
|
||||
{
|
||||
validators.push((keyword.clone(), validator?));
|
||||
} else {
|
||||
|
@ -243,8 +258,9 @@ pub(crate) fn compile_validators<'a, 'c>(
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::JSONSchema;
|
||||
use super::*;
|
||||
use crate::error::ValidationError;
|
||||
use crate::keywords::boolean::FalseValidator;
|
||||
use serde_json::{from_str, json, Value};
|
||||
use std::{fs::File, io::Read, path::Path};
|
||||
|
||||
|
@ -302,4 +318,13 @@ mod tests {
|
|||
);
|
||||
assert_eq!(errors[1].to_string(), r#""a" is shorter than 3 characters"#);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn arena() {
|
||||
let mut arena = ValidatorArena::new();
|
||||
let idx = arena.push(FalseValidator {
|
||||
schema_path: Default::default(),
|
||||
});
|
||||
assert_eq!(idx, 0)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::compilation::ValidatorArena;
|
||||
use crate::{
|
||||
compilation::{compile_validators, context::CompilationContext, JSONSchema, DEFAULT_SCOPE},
|
||||
content_encoding::{
|
||||
|
@ -294,7 +295,8 @@ impl CompilationOptions {
|
|||
}
|
||||
}
|
||||
|
||||
let node = compile_validators(schema, &context)?;
|
||||
let mut validators = ValidatorArena::new();
|
||||
let node = compile_validators(schema, &context, &mut validators)?;
|
||||
|
||||
Ok(JSONSchema { node, config })
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::compilation::ValidatorArena;
|
||||
use crate::{
|
||||
compilation::{compile_validators, context::CompilationContext},
|
||||
error::{error, no_error, ErrorIterator, ValidationError},
|
||||
|
@ -19,8 +20,9 @@ impl AdditionalItemsObjectValidator {
|
|||
schema: &'a Value,
|
||||
items_count: usize,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> CompilationResult<'a> {
|
||||
let node = compile_validators(schema, context)?;
|
||||
let node = compile_validators(schema, context, arena)?;
|
||||
Ok(Box::new(AdditionalItemsObjectValidator {
|
||||
node,
|
||||
items_count,
|
||||
|
@ -78,6 +80,7 @@ impl AdditionalItemsBooleanValidator {
|
|||
pub(crate) fn compile<'a>(
|
||||
items_count: usize,
|
||||
schema_path: JSONPointer,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> CompilationResult<'a> {
|
||||
Ok(Box::new(AdditionalItemsBooleanValidator {
|
||||
items_count,
|
||||
|
@ -124,6 +127,7 @@ pub(crate) fn compile<'a>(
|
|||
parent: &Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
if let Some(items) = parent.get("items") {
|
||||
match items {
|
||||
|
@ -136,10 +140,12 @@ pub(crate) fn compile<'a>(
|
|||
schema,
|
||||
items_count,
|
||||
&keyword_context,
|
||||
arena,
|
||||
)),
|
||||
Value::Bool(false) => Some(AdditionalItemsBooleanValidator::compile(
|
||||
items_count,
|
||||
keyword_context.into_pointer(),
|
||||
arena,
|
||||
)),
|
||||
_ => None,
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
//! - `patternProperties`
|
||||
//!
|
||||
//! Each valid combination of these keywords has a validator here.
|
||||
use crate::compilation::ValidatorArena;
|
||||
use crate::{
|
||||
compilation::{compile_validators, context::CompilationContext},
|
||||
error::{error, no_error, ErrorIterator, ValidationError},
|
||||
|
@ -127,6 +128,7 @@ macro_rules! validate {
|
|||
fn compile_small_map<'a>(
|
||||
map: &'a Map<String, Value>,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Result<SmallValidatorsMap, ValidationError<'a>> {
|
||||
let mut properties = Vec::with_capacity(map.len());
|
||||
let keyword_context = context.with_path("properties");
|
||||
|
@ -134,7 +136,7 @@ fn compile_small_map<'a>(
|
|||
let property_context = keyword_context.with_path(key.clone());
|
||||
properties.push((
|
||||
key.clone(),
|
||||
compile_validators(subschema, &property_context)?,
|
||||
compile_validators(subschema, &property_context, arena)?,
|
||||
));
|
||||
}
|
||||
Ok(properties)
|
||||
|
@ -142,6 +144,7 @@ fn compile_small_map<'a>(
|
|||
fn compile_big_map<'a>(
|
||||
map: &'a Map<String, Value>,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Result<BigValidatorsMap, ValidationError<'a>> {
|
||||
let mut properties = AHashMap::with_capacity(map.len());
|
||||
let keyword_context = context.with_path("properties");
|
||||
|
@ -149,7 +152,7 @@ fn compile_big_map<'a>(
|
|||
let property_context = keyword_context.with_path(key.clone());
|
||||
properties.insert(
|
||||
key.clone(),
|
||||
compile_validators(subschema, &property_context)?,
|
||||
compile_validators(subschema, &property_context, arena)?,
|
||||
);
|
||||
}
|
||||
Ok(properties)
|
||||
|
@ -178,10 +181,11 @@ impl AdditionalPropertiesValidator {
|
|||
pub(crate) fn compile<'a>(
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> CompilationResult<'a> {
|
||||
let keyword_context = context.with_path("additionalProperties");
|
||||
Ok(Box::new(AdditionalPropertiesValidator {
|
||||
node: compile_validators(schema, &keyword_context)?,
|
||||
node: compile_validators(schema, &keyword_context, arena)?,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
@ -324,9 +328,10 @@ impl AdditionalPropertiesNotEmptyFalseValidator<SmallValidatorsMap> {
|
|||
pub(crate) fn compile<'a>(
|
||||
map: &'a Map<String, Value>,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> CompilationResult<'a> {
|
||||
Ok(Box::new(AdditionalPropertiesNotEmptyFalseValidator {
|
||||
properties: compile_small_map(map, context)?,
|
||||
properties: compile_small_map(map, context, arena)?,
|
||||
schema_path: context.as_pointer_with("additionalProperties"),
|
||||
}))
|
||||
}
|
||||
|
@ -336,9 +341,10 @@ impl AdditionalPropertiesNotEmptyFalseValidator<BigValidatorsMap> {
|
|||
pub(crate) fn compile<'a>(
|
||||
map: &'a Map<String, Value>,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> CompilationResult<'a> {
|
||||
Ok(Box::new(AdditionalPropertiesNotEmptyFalseValidator {
|
||||
properties: compile_big_map(map, context)?,
|
||||
properties: compile_big_map(map, context, arena)?,
|
||||
schema_path: context.as_pointer_with("additionalProperties"),
|
||||
}))
|
||||
}
|
||||
|
@ -460,11 +466,12 @@ impl AdditionalPropertiesNotEmptyValidator<SmallValidatorsMap> {
|
|||
map: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> CompilationResult<'a> {
|
||||
let keyword_context = context.with_path("additionalProperties");
|
||||
Ok(Box::new(AdditionalPropertiesNotEmptyValidator {
|
||||
properties: compile_small_map(map, context)?,
|
||||
node: compile_validators(schema, &keyword_context)?,
|
||||
properties: compile_small_map(map, context, arena)?,
|
||||
node: compile_validators(schema, &keyword_context, arena)?,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
@ -474,11 +481,12 @@ impl AdditionalPropertiesNotEmptyValidator<BigValidatorsMap> {
|
|||
map: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> CompilationResult<'a> {
|
||||
let keyword_context = context.with_path("additionalProperties");
|
||||
Ok(Box::new(AdditionalPropertiesNotEmptyValidator {
|
||||
properties: compile_big_map(map, context)?,
|
||||
node: compile_validators(schema, &keyword_context)?,
|
||||
properties: compile_big_map(map, context, arena)?,
|
||||
node: compile_validators(schema, &keyword_context, arena)?,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
@ -596,9 +604,10 @@ impl AdditionalPropertiesWithPatternsValidator {
|
|||
schema: &'a Value,
|
||||
patterns: PatternedValidators,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> CompilationResult<'a> {
|
||||
Ok(Box::new(AdditionalPropertiesWithPatternsValidator {
|
||||
node: compile_validators(schema, &context.with_path("additionalProperties"))?,
|
||||
node: compile_validators(schema, &context.with_path("additionalProperties"), arena)?,
|
||||
patterns,
|
||||
pattern_keyword_path: context.as_pointer_with("patternProperties"),
|
||||
pattern_keyword_absolute_path: context
|
||||
|
@ -896,12 +905,13 @@ impl AdditionalPropertiesWithPatternsNotEmptyValidator<SmallValidatorsMap> {
|
|||
schema: &'a Value,
|
||||
patterns: PatternedValidators,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> CompilationResult<'a> {
|
||||
let keyword_context = context.with_path("additionalProperties");
|
||||
Ok(Box::new(
|
||||
AdditionalPropertiesWithPatternsNotEmptyValidator {
|
||||
node: compile_validators(schema, &keyword_context)?,
|
||||
properties: compile_small_map(map, context)?,
|
||||
node: compile_validators(schema, &keyword_context, arena)?,
|
||||
properties: compile_small_map(map, context, arena)?,
|
||||
patterns,
|
||||
},
|
||||
))
|
||||
|
@ -914,12 +924,13 @@ impl AdditionalPropertiesWithPatternsNotEmptyValidator<BigValidatorsMap> {
|
|||
schema: &'a Value,
|
||||
patterns: PatternedValidators,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> CompilationResult<'a> {
|
||||
let keyword_context = context.with_path("additionalProperties");
|
||||
Ok(Box::new(
|
||||
AdditionalPropertiesWithPatternsNotEmptyValidator {
|
||||
node: compile_validators(schema, &keyword_context)?,
|
||||
properties: compile_big_map(map, context)?,
|
||||
node: compile_validators(schema, &keyword_context, arena)?,
|
||||
properties: compile_big_map(map, context, arena)?,
|
||||
patterns,
|
||||
},
|
||||
))
|
||||
|
@ -1088,10 +1099,11 @@ impl AdditionalPropertiesWithPatternsNotEmptyFalseValidator<SmallValidatorsMap>
|
|||
map: &'a Map<String, Value>,
|
||||
patterns: PatternedValidators,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> CompilationResult<'a> {
|
||||
Ok(Box::new(
|
||||
AdditionalPropertiesWithPatternsNotEmptyFalseValidator::<SmallValidatorsMap> {
|
||||
properties: compile_small_map(map, context)?,
|
||||
properties: compile_small_map(map, context, arena)?,
|
||||
patterns,
|
||||
schema_path: context.schema_path.push("additionalProperties").into(),
|
||||
},
|
||||
|
@ -1104,10 +1116,11 @@ impl AdditionalPropertiesWithPatternsNotEmptyFalseValidator<BigValidatorsMap> {
|
|||
map: &'a Map<String, Value>,
|
||||
patterns: PatternedValidators,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> CompilationResult<'a> {
|
||||
Ok(Box::new(
|
||||
AdditionalPropertiesWithPatternsNotEmptyFalseValidator {
|
||||
properties: compile_big_map(map, context)?,
|
||||
properties: compile_big_map(map, context, arena)?,
|
||||
patterns,
|
||||
schema_path: context.schema_path.push("additionalProperties").into(),
|
||||
},
|
||||
|
@ -1253,12 +1266,13 @@ pub(crate) fn compile<'a>(
|
|||
parent: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
let properties = parent.get("properties");
|
||||
if let Some(patterns) = parent.get("patternProperties") {
|
||||
if let Value::Object(obj) = patterns {
|
||||
// Compile all patterns & their validators to avoid doing work in the `patternProperties` validator
|
||||
if let Ok(compiled_patterns) = compile_patterns(obj, context) {
|
||||
if let Ok(compiled_patterns) = compile_patterns(obj, context, arena) {
|
||||
match schema {
|
||||
Value::Bool(true) => None, // "additionalProperties" are "true" by default
|
||||
Value::Bool(false) => {
|
||||
|
@ -1267,7 +1281,8 @@ pub(crate) fn compile<'a>(
|
|||
AdditionalPropertiesWithPatternsNotEmptyFalseValidator,
|
||||
properties,
|
||||
compiled_patterns,
|
||||
context
|
||||
context,
|
||||
arena,
|
||||
)
|
||||
} else {
|
||||
Some(AdditionalPropertiesWithPatternsFalseValidator::compile(
|
||||
|
@ -1283,13 +1298,15 @@ pub(crate) fn compile<'a>(
|
|||
properties,
|
||||
schema,
|
||||
compiled_patterns,
|
||||
context
|
||||
context,
|
||||
arena,
|
||||
)
|
||||
} else {
|
||||
Some(AdditionalPropertiesWithPatternsValidator::compile(
|
||||
schema,
|
||||
compiled_patterns,
|
||||
context,
|
||||
arena,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
@ -1308,7 +1325,8 @@ pub(crate) fn compile<'a>(
|
|||
dynamic_map!(
|
||||
AdditionalPropertiesNotEmptyFalseValidator,
|
||||
properties,
|
||||
context
|
||||
context,
|
||||
arena,
|
||||
)
|
||||
} else {
|
||||
let schema_path = context.as_pointer_with("additionalProperties");
|
||||
|
@ -1321,10 +1339,13 @@ pub(crate) fn compile<'a>(
|
|||
AdditionalPropertiesNotEmptyValidator,
|
||||
properties,
|
||||
schema,
|
||||
context
|
||||
context,
|
||||
arena,
|
||||
)
|
||||
} else {
|
||||
Some(AdditionalPropertiesValidator::compile(schema, context))
|
||||
Some(AdditionalPropertiesValidator::compile(
|
||||
schema, context, arena,
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1336,13 +1357,14 @@ pub(crate) fn compile<'a>(
|
|||
fn compile_patterns<'a>(
|
||||
obj: &'a Map<String, Value>,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Result<PatternedValidators, ValidationError<'a>> {
|
||||
let keyword_context = context.with_path("patternProperties");
|
||||
let mut compiled_patterns = Vec::with_capacity(obj.len());
|
||||
for (pattern, subschema) in obj {
|
||||
let pattern_context = keyword_context.with_path(pattern.to_string());
|
||||
if let Ok(compiled_pattern) = Regex::new(pattern) {
|
||||
let node = compile_validators(subschema, &pattern_context)?;
|
||||
let node = compile_validators(subschema, &pattern_context, arena)?;
|
||||
compiled_patterns.push((compiled_pattern, node));
|
||||
} else {
|
||||
return Err(ValidationError::format(
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::compilation::ValidatorArena;
|
||||
use crate::{
|
||||
compilation::{compile_validators, context::CompilationContext},
|
||||
error::{ErrorIterator, ValidationError},
|
||||
|
@ -20,12 +21,13 @@ impl AllOfValidator {
|
|||
pub(crate) fn compile<'a>(
|
||||
items: &'a [Value],
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> CompilationResult<'a> {
|
||||
let keyword_context = context.with_path("allOf");
|
||||
let mut schemas = Vec::with_capacity(items.len());
|
||||
for (idx, item) in items.iter().enumerate() {
|
||||
let item_context = keyword_context.with_path(idx);
|
||||
let validators = compile_validators(item, &item_context)?;
|
||||
let validators = compile_validators(item, &item_context, arena)?;
|
||||
schemas.push(validators)
|
||||
}
|
||||
Ok(Box::new(AllOfValidator { schemas }))
|
||||
|
@ -82,10 +84,11 @@ impl SingleValueAllOfValidator {
|
|||
pub(crate) fn compile<'a>(
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> CompilationResult<'a> {
|
||||
let keyword_context = context.with_path("allOf");
|
||||
let item_context = keyword_context.with_path(0);
|
||||
let node = compile_validators(schema, &item_context)?;
|
||||
let node = compile_validators(schema, &item_context, arena)?;
|
||||
Ok(Box::new(SingleValueAllOfValidator { node }))
|
||||
}
|
||||
}
|
||||
|
@ -122,13 +125,14 @@ pub(crate) fn compile<'a>(
|
|||
_: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
if let Value::Array(items) = schema {
|
||||
if items.len() == 1 {
|
||||
let value = items.iter().next().expect("Vec is not empty");
|
||||
Some(SingleValueAllOfValidator::compile(value, context))
|
||||
Some(SingleValueAllOfValidator::compile(value, context, arena))
|
||||
} else {
|
||||
Some(AllOfValidator::compile(items, context))
|
||||
Some(AllOfValidator::compile(items, context, arena))
|
||||
}
|
||||
} else {
|
||||
Some(Err(ValidationError::single_type_error(
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::compilation::ValidatorArena;
|
||||
use crate::{
|
||||
compilation::{compile_validators, context::CompilationContext},
|
||||
error::{error, no_error, ErrorIterator, ValidationError},
|
||||
|
@ -21,13 +22,14 @@ impl AnyOfValidator {
|
|||
pub(crate) fn compile<'a>(
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> CompilationResult<'a> {
|
||||
if let Value::Array(items) = schema {
|
||||
let keyword_context = context.with_path("anyOf");
|
||||
let mut schemas = Vec::with_capacity(items.len());
|
||||
for (idx, item) in items.iter().enumerate() {
|
||||
let item_context = keyword_context.with_path(idx);
|
||||
let node = compile_validators(item, &item_context)?;
|
||||
let node = compile_validators(item, &item_context, arena)?;
|
||||
schemas.push(node)
|
||||
}
|
||||
Ok(Box::new(AnyOfValidator {
|
||||
|
@ -103,8 +105,9 @@ pub(crate) fn compile<'a>(
|
|||
_: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
Some(AnyOfValidator::compile(schema, context))
|
||||
Some(AnyOfValidator::compile(schema, context, arena))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -8,7 +8,7 @@ use crate::{
|
|||
use serde_json::Value;
|
||||
|
||||
pub(crate) struct FalseValidator {
|
||||
schema_path: JSONPointer,
|
||||
pub(crate) schema_path: JSONPointer,
|
||||
}
|
||||
impl FalseValidator {
|
||||
#[inline]
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::compilation::ValidatorArena;
|
||||
use crate::{
|
||||
compilation::context::CompilationContext,
|
||||
error::{error, no_error, ErrorIterator, ValidationError},
|
||||
|
@ -311,6 +312,7 @@ pub(crate) fn compile<'a>(
|
|||
_: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
let schema_path = context.as_pointer_with("const");
|
||||
match schema {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::compilation::ValidatorArena;
|
||||
use crate::{
|
||||
compilation::{compile_validators, context::CompilationContext},
|
||||
error::{error, no_error, ErrorIterator, ValidationError},
|
||||
|
@ -22,10 +23,11 @@ impl ContainsValidator {
|
|||
pub(crate) fn compile<'a>(
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> CompilationResult<'a> {
|
||||
let keyword_context = context.with_path("contains");
|
||||
Ok(Box::new(ContainsValidator {
|
||||
node: compile_validators(schema, &keyword_context)?,
|
||||
node: compile_validators(schema, &keyword_context, arena)?,
|
||||
schema_path: keyword_context.into_pointer(),
|
||||
}))
|
||||
}
|
||||
|
@ -118,10 +120,11 @@ impl MinContainsValidator {
|
|||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
min_contains: u64,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> CompilationResult<'a> {
|
||||
let keyword_context = context.with_path("minContains");
|
||||
Ok(Box::new(MinContainsValidator {
|
||||
node: compile_validators(schema, context)?,
|
||||
node: compile_validators(schema, context, arena)?,
|
||||
min_contains,
|
||||
schema_path: keyword_context.into_pointer(),
|
||||
}))
|
||||
|
@ -216,10 +219,11 @@ impl MaxContainsValidator {
|
|||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
max_contains: u64,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> CompilationResult<'a> {
|
||||
let keyword_context = context.with_path("maxContains");
|
||||
Ok(Box::new(MaxContainsValidator {
|
||||
node: compile_validators(schema, context)?,
|
||||
node: compile_validators(schema, context, arena)?,
|
||||
max_contains,
|
||||
schema_path: keyword_context.into_pointer(),
|
||||
}))
|
||||
|
@ -324,9 +328,10 @@ impl MinMaxContainsValidator {
|
|||
context: &CompilationContext,
|
||||
min_contains: u64,
|
||||
max_contains: u64,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> CompilationResult<'a> {
|
||||
Ok(Box::new(MinMaxContainsValidator {
|
||||
node: compile_validators(schema, context)?,
|
||||
node: compile_validators(schema, context, arena)?,
|
||||
min_contains,
|
||||
max_contains,
|
||||
schema_path: context.schema_path.clone().into(),
|
||||
|
@ -413,13 +418,14 @@ pub(crate) fn compile<'a>(
|
|||
parent: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
match context.config.draft() {
|
||||
Draft::Draft4 | Draft::Draft6 | Draft::Draft7 => {
|
||||
Some(ContainsValidator::compile(schema, context))
|
||||
Some(ContainsValidator::compile(schema, context, arena))
|
||||
}
|
||||
#[cfg(all(feature = "draft201909", feature = "draft202012"))]
|
||||
Draft::Draft201909 | Draft::Draft202012 => compile_contains(parent, schema, context),
|
||||
Draft::Draft201909 | Draft::Draft202012 => compile_contains(parent, schema, context, arena),
|
||||
#[cfg(all(feature = "draft201909", not(feature = "draft202012")))]
|
||||
Draft::Draft201909 => compile_contains(parent, schema, context),
|
||||
#[cfg(all(feature = "draft202012", not(feature = "draft201909")))]
|
||||
|
@ -433,6 +439,7 @@ fn compile_contains<'a>(
|
|||
parent: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
let min_contains = match map_get_u64(parent, context, "minContains").transpose() {
|
||||
Ok(n) => n,
|
||||
|
@ -444,10 +451,12 @@ fn compile_contains<'a>(
|
|||
};
|
||||
|
||||
match (min_contains, max_contains) {
|
||||
(Some(min), Some(max)) => Some(MinMaxContainsValidator::compile(schema, context, min, max)),
|
||||
(Some(min), None) => Some(MinContainsValidator::compile(schema, context, min)),
|
||||
(None, Some(max)) => Some(MaxContainsValidator::compile(schema, context, max)),
|
||||
(None, None) => Some(ContainsValidator::compile(schema, context)),
|
||||
(Some(min), Some(max)) => Some(MinMaxContainsValidator::compile(
|
||||
schema, context, min, max, arena,
|
||||
)),
|
||||
(Some(min), None) => Some(MinContainsValidator::compile(schema, context, min, arena)),
|
||||
(None, Some(max)) => Some(MaxContainsValidator::compile(schema, context, max, arena)),
|
||||
(None, None) => Some(ContainsValidator::compile(schema, context, arena)),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
//! Validators for `contentMediaType` and `contentEncoding` keywords.
|
||||
use crate::compilation::ValidatorArena;
|
||||
use crate::{
|
||||
compilation::context::CompilationContext,
|
||||
content_encoding::{ContentEncodingCheckType, ContentEncodingConverterType},
|
||||
|
@ -219,6 +220,7 @@ pub(crate) fn compile_media_type<'a>(
|
|||
schema: &'a Map<String, Value>,
|
||||
subschema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
match subschema {
|
||||
Value::String(media_type) => {
|
||||
|
@ -273,6 +275,7 @@ pub(crate) fn compile_content_encoding<'a>(
|
|||
schema: &'a Map<String, Value>,
|
||||
subschema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
// Performed during media type validation
|
||||
if schema.get("contentMediaType").is_some() {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::compilation::ValidatorArena;
|
||||
use crate::{
|
||||
compilation::{compile_validators, context::CompilationContext},
|
||||
error::{no_error, ErrorIterator, ValidationError},
|
||||
|
@ -18,6 +19,7 @@ impl DependenciesValidator {
|
|||
pub(crate) fn compile<'a>(
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> CompilationResult<'a> {
|
||||
if let Value::Object(map) = schema {
|
||||
let keyword_context = context.with_path("dependencies");
|
||||
|
@ -33,7 +35,7 @@ impl DependenciesValidator {
|
|||
.expect("The required validator compilation does not return None")?];
|
||||
SchemaNode::new_from_array(&keyword_context, validators)
|
||||
}
|
||||
_ => compile_validators(subschema, &item_context)?,
|
||||
_ => compile_validators(subschema, &item_context, arena)?,
|
||||
};
|
||||
dependencies.push((key.clone(), s))
|
||||
}
|
||||
|
@ -101,6 +103,7 @@ impl DependentRequiredValidator {
|
|||
pub(crate) fn compile<'a>(
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> CompilationResult<'a> {
|
||||
if let Value::Object(map) = schema {
|
||||
let keyword_context = context.with_path("dependentRequired");
|
||||
|
@ -191,13 +194,14 @@ impl DependentSchemasValidator {
|
|||
pub(crate) fn compile<'a>(
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> CompilationResult<'a> {
|
||||
if let Value::Object(map) = schema {
|
||||
let keyword_context = context.with_path("dependentSchemas");
|
||||
let mut dependencies = Vec::with_capacity(map.len());
|
||||
for (key, subschema) in map {
|
||||
let item_context = keyword_context.with_path(key.to_string());
|
||||
let schema_nodes = compile_validators(subschema, &item_context)?;
|
||||
let schema_nodes = compile_validators(subschema, &item_context, arena)?;
|
||||
dependencies.push((key.clone(), schema_nodes));
|
||||
}
|
||||
Ok(Box::new(DependentSchemasValidator { dependencies }))
|
||||
|
@ -255,24 +259,27 @@ pub(crate) fn compile<'a>(
|
|||
_: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
Some(DependenciesValidator::compile(schema, context))
|
||||
Some(DependenciesValidator::compile(schema, context, arena))
|
||||
}
|
||||
#[inline]
|
||||
pub(crate) fn compile_dependent_required<'a>(
|
||||
_: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
Some(DependentRequiredValidator::compile(schema, context))
|
||||
Some(DependentRequiredValidator::compile(schema, context, arena))
|
||||
}
|
||||
#[inline]
|
||||
pub(crate) fn compile_dependent_schemas<'a>(
|
||||
_: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
Some(DependentSchemasValidator::compile(schema, context))
|
||||
Some(DependentSchemasValidator::compile(schema, context, arena))
|
||||
}
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::compilation::ValidatorArena;
|
||||
use crate::{
|
||||
compilation::context::CompilationContext,
|
||||
error::{error, no_error, ErrorIterator, ValidationError},
|
||||
|
@ -137,6 +138,7 @@ pub(crate) fn compile<'a>(
|
|||
_: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
if let Value::Array(items) = schema {
|
||||
let schema_path = context.as_pointer_with("enum");
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::compilation::ValidatorArena;
|
||||
use crate::{
|
||||
compilation::context::CompilationContext,
|
||||
error::{error, no_error, ErrorIterator, ValidationError},
|
||||
|
@ -115,6 +116,7 @@ pub(crate) fn compile<'a>(
|
|||
_: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
if let Value::Number(limit) = schema {
|
||||
let schema_path = context.as_pointer_with("exclusiveMaximum");
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::compilation::ValidatorArena;
|
||||
use crate::{
|
||||
compilation::context::CompilationContext,
|
||||
error::{error, no_error, ErrorIterator, ValidationError},
|
||||
|
@ -113,6 +114,7 @@ pub(crate) fn compile<'a>(
|
|||
_: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
if let Value::Number(limit) = schema {
|
||||
let schema_path = context.as_pointer_with("exclusiveMinimum");
|
||||
|
|
|
@ -6,6 +6,7 @@ use serde_json::{Map, Value};
|
|||
use url::Url;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::compilation::ValidatorArena;
|
||||
use crate::{
|
||||
compilation::context::CompilationContext,
|
||||
error::{error, no_error, ErrorIterator, ValidationError},
|
||||
|
@ -421,6 +422,7 @@ pub(crate) fn compile<'a>(
|
|||
_: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
if !context.config.validate_formats() {
|
||||
return None;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::compilation::ValidatorArena;
|
||||
use crate::{
|
||||
compilation::{compile_validators, context::CompilationContext},
|
||||
error::{no_error, ErrorIterator},
|
||||
|
@ -19,15 +20,16 @@ impl IfThenValidator {
|
|||
schema: &'a Value,
|
||||
then_schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> CompilationResult<'a> {
|
||||
Ok(Box::new(IfThenValidator {
|
||||
schema: {
|
||||
let if_context = context.with_path("if");
|
||||
compile_validators(schema, &if_context)?
|
||||
compile_validators(schema, &if_context, arena)?
|
||||
},
|
||||
then_schema: {
|
||||
let then_context = context.with_path("then");
|
||||
compile_validators(then_schema, &then_context)?
|
||||
compile_validators(then_schema, &then_context, arena)?
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
@ -94,15 +96,16 @@ impl IfElseValidator {
|
|||
schema: &'a Value,
|
||||
else_schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> CompilationResult<'a> {
|
||||
Ok(Box::new(IfElseValidator {
|
||||
schema: {
|
||||
let if_context = context.with_path("if");
|
||||
compile_validators(schema, &if_context)?
|
||||
compile_validators(schema, &if_context, arena)?
|
||||
},
|
||||
else_schema: {
|
||||
let else_context = context.with_path("else");
|
||||
compile_validators(else_schema, &else_context)?
|
||||
compile_validators(else_schema, &else_context, arena)?
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
@ -171,19 +174,20 @@ impl IfThenElseValidator {
|
|||
then_schema: &'a Value,
|
||||
else_schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> CompilationResult<'a> {
|
||||
Ok(Box::new(IfThenElseValidator {
|
||||
schema: {
|
||||
let if_context = context.with_path("if");
|
||||
compile_validators(schema, &if_context)?
|
||||
compile_validators(schema, &if_context, arena)?
|
||||
},
|
||||
then_schema: {
|
||||
let then_context = context.with_path("then");
|
||||
compile_validators(then_schema, &then_context)?
|
||||
compile_validators(then_schema, &then_context, arena)?
|
||||
},
|
||||
else_schema: {
|
||||
let else_context = context.with_path("else");
|
||||
compile_validators(else_schema, &else_context)?
|
||||
compile_validators(else_schema, &else_context, arena)?
|
||||
},
|
||||
}))
|
||||
}
|
||||
|
@ -247,6 +251,7 @@ pub(crate) fn compile<'a>(
|
|||
parent: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
let then = parent.get("then");
|
||||
let else_ = parent.get("else");
|
||||
|
@ -256,9 +261,20 @@ pub(crate) fn compile<'a>(
|
|||
then_schema,
|
||||
else_schema,
|
||||
context,
|
||||
arena,
|
||||
)),
|
||||
(None, Some(else_schema)) => Some(IfElseValidator::compile(
|
||||
schema,
|
||||
else_schema,
|
||||
context,
|
||||
arena,
|
||||
)),
|
||||
(Some(then_schema), None) => Some(IfThenValidator::compile(
|
||||
schema,
|
||||
then_schema,
|
||||
context,
|
||||
arena,
|
||||
)),
|
||||
(None, Some(else_schema)) => Some(IfElseValidator::compile(schema, else_schema, context)),
|
||||
(Some(then_schema), None) => Some(IfThenValidator::compile(schema, then_schema, context)),
|
||||
(None, None) => None,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::compilation::ValidatorArena;
|
||||
use crate::{
|
||||
compilation::{compile_validators, context::CompilationContext},
|
||||
error::{no_error, ErrorIterator},
|
||||
|
@ -16,12 +17,13 @@ impl ItemsArrayValidator {
|
|||
pub(crate) fn compile<'a>(
|
||||
schemas: &'a [Value],
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> CompilationResult<'a> {
|
||||
let keyword_context = context.with_path("items");
|
||||
let mut items = Vec::with_capacity(schemas.len());
|
||||
for (idx, item) in schemas.iter().enumerate() {
|
||||
let item_context = keyword_context.with_path(idx);
|
||||
let validators = compile_validators(item, &item_context)?;
|
||||
let validators = compile_validators(item, &item_context, arena)?;
|
||||
items.push(validators)
|
||||
}
|
||||
Ok(Box::new(ItemsArrayValidator { items }))
|
||||
|
@ -78,9 +80,10 @@ impl ItemsObjectValidator {
|
|||
pub(crate) fn compile<'a>(
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> CompilationResult<'a> {
|
||||
let keyword_context = context.with_path("items");
|
||||
let node = compile_validators(schema, &keyword_context)?;
|
||||
let node = compile_validators(schema, &keyword_context, arena)?;
|
||||
Ok(Box::new(ItemsObjectValidator { node }))
|
||||
}
|
||||
}
|
||||
|
@ -154,9 +157,10 @@ impl ItemsObjectSkipPrefixValidator {
|
|||
schema: &'a Value,
|
||||
skip_prefix: usize,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> CompilationResult<'a> {
|
||||
let keyword_context = context.with_path("items");
|
||||
let node = compile_validators(schema, &keyword_context)?;
|
||||
let node = compile_validators(schema, &keyword_context, arena)?;
|
||||
Ok(Box::new(ItemsObjectSkipPrefixValidator {
|
||||
node,
|
||||
skip_prefix,
|
||||
|
@ -233,9 +237,10 @@ pub(crate) fn compile<'a>(
|
|||
parent: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
match schema {
|
||||
Value::Array(items) => Some(ItemsArrayValidator::compile(items, context)),
|
||||
Value::Array(items) => Some(ItemsArrayValidator::compile(items, context, arena)),
|
||||
Value::Object(_) | Value::Bool(false) => {
|
||||
#[cfg(feature = "draft202012")]
|
||||
if let Some(Value::Array(prefix_items)) = parent.get("prefixItems") {
|
||||
|
@ -243,9 +248,10 @@ pub(crate) fn compile<'a>(
|
|||
schema,
|
||||
prefix_items.len(),
|
||||
context,
|
||||
arena,
|
||||
));
|
||||
}
|
||||
Some(ItemsObjectValidator::compile(schema, context))
|
||||
Some(ItemsObjectValidator::compile(schema, context, arena))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::compilation::ValidatorArena;
|
||||
use crate::{
|
||||
compilation::context::CompilationContext,
|
||||
keywords::{exclusive_maximum, maximum, CompilationResult},
|
||||
|
@ -9,10 +10,11 @@ pub(crate) fn compile<'a>(
|
|||
parent: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
if let Some(Value::Bool(true)) = parent.get("exclusiveMaximum") {
|
||||
exclusive_maximum::compile(parent, schema, context)
|
||||
exclusive_maximum::compile(parent, schema, context, arena)
|
||||
} else {
|
||||
maximum::compile(parent, schema, context)
|
||||
maximum::compile(parent, schema, context, arena)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::compilation::ValidatorArena;
|
||||
use crate::{
|
||||
compilation::context::CompilationContext,
|
||||
keywords::{exclusive_minimum, minimum, CompilationResult},
|
||||
|
@ -9,10 +10,11 @@ pub(crate) fn compile<'a>(
|
|||
parent: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
if let Some(Value::Bool(true)) = parent.get("exclusiveMinimum") {
|
||||
exclusive_minimum::compile(parent, schema, context)
|
||||
exclusive_minimum::compile(parent, schema, context, arena)
|
||||
} else {
|
||||
minimum::compile(parent, schema, context)
|
||||
minimum::compile(parent, schema, context, arena)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::compilation::ValidatorArena;
|
||||
use crate::{
|
||||
compilation::context::CompilationContext,
|
||||
error::{error, no_error, ErrorIterator, ValidationError},
|
||||
|
@ -147,6 +148,7 @@ pub(crate) fn compile<'a>(
|
|||
_: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
let schema_path = context.as_pointer_with("type");
|
||||
match schema {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::compilation::ValidatorArena;
|
||||
use crate::{
|
||||
compilation::context::CompilationContext,
|
||||
error::{error, no_error, ErrorIterator, ValidationError},
|
||||
|
@ -63,6 +64,7 @@ pub(crate) fn compile<'a>(
|
|||
_: &Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
let schema_path = context.as_pointer_with("maxItems");
|
||||
Some(MaxItemsValidator::compile(schema, schema_path))
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::compilation::ValidatorArena;
|
||||
use crate::{
|
||||
compilation::context::CompilationContext,
|
||||
error::{error, no_error, ErrorIterator, ValidationError},
|
||||
|
@ -63,6 +64,7 @@ pub(crate) fn compile<'a>(
|
|||
_: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
let schema_path = context.as_pointer_with("maxLength");
|
||||
Some(MaxLengthValidator::compile(schema, schema_path))
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::compilation::ValidatorArena;
|
||||
use crate::{
|
||||
compilation::context::CompilationContext,
|
||||
error::{error, no_error, ErrorIterator, ValidationError},
|
||||
|
@ -63,6 +64,7 @@ pub(crate) fn compile<'a>(
|
|||
_: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
let schema_path = context.as_pointer_with("maxProperties");
|
||||
Some(MaxPropertiesValidator::compile(schema, schema_path))
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::compilation::ValidatorArena;
|
||||
use crate::{
|
||||
compilation::context::CompilationContext,
|
||||
error::{error, no_error, ErrorIterator, ValidationError},
|
||||
|
@ -113,6 +114,7 @@ pub(crate) fn compile<'a>(
|
|||
_: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
if let Value::Number(limit) = schema {
|
||||
let schema_path = context.as_pointer_with("maximum");
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::compilation::ValidatorArena;
|
||||
use crate::{
|
||||
compilation::context::CompilationContext,
|
||||
error::{error, no_error, ErrorIterator, ValidationError},
|
||||
|
@ -63,6 +64,7 @@ pub(crate) fn compile<'a>(
|
|||
_: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
let schema_path = context.as_pointer_with("minItems");
|
||||
Some(MinItemsValidator::compile(schema, schema_path))
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::compilation::ValidatorArena;
|
||||
use crate::{
|
||||
compilation::context::CompilationContext,
|
||||
error::{error, no_error, ErrorIterator, ValidationError},
|
||||
|
@ -63,6 +64,7 @@ pub(crate) fn compile<'a>(
|
|||
_: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
let schema_path = context.as_pointer_with("minLength");
|
||||
Some(MinLengthValidator::compile(schema, schema_path))
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::compilation::ValidatorArena;
|
||||
use crate::{
|
||||
compilation::context::CompilationContext,
|
||||
error::{error, no_error, ErrorIterator, ValidationError},
|
||||
|
@ -63,6 +64,7 @@ pub(crate) fn compile<'a>(
|
|||
_: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
let schema_path = context.as_pointer_with("minProperties");
|
||||
Some(MinPropertiesValidator::compile(schema, schema_path))
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::compilation::ValidatorArena;
|
||||
use crate::{
|
||||
compilation::context::CompilationContext,
|
||||
error::{error, no_error, ErrorIterator, ValidationError},
|
||||
|
@ -113,6 +114,7 @@ pub(crate) fn compile<'a>(
|
|||
_: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
if let Value::Number(limit) = schema {
|
||||
let schema_path = context.as_pointer_with("minimum");
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::compilation::ValidatorArena;
|
||||
use crate::{
|
||||
compilation::context::CompilationContext,
|
||||
error::{error, no_error, ErrorIterator, ValidationError},
|
||||
|
@ -123,6 +124,7 @@ pub(crate) fn compile<'a>(
|
|||
_: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
if let Value::Number(multiple_of) = schema {
|
||||
let multiple_of = multiple_of.as_f64().expect("Always valid");
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::compilation::ValidatorArena;
|
||||
use crate::{
|
||||
compilation::{compile_validators, context::CompilationContext},
|
||||
error::{error, no_error, ErrorIterator, ValidationError},
|
||||
|
@ -20,11 +21,12 @@ impl NotValidator {
|
|||
pub(crate) fn compile<'a>(
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> CompilationResult<'a> {
|
||||
let keyword_context = context.with_path("not");
|
||||
Ok(Box::new(NotValidator {
|
||||
original: schema.clone(),
|
||||
node: compile_validators(schema, &keyword_context)?,
|
||||
node: compile_validators(schema, &keyword_context, arena)?,
|
||||
schema_path: keyword_context.into_pointer(),
|
||||
}))
|
||||
}
|
||||
|
@ -64,8 +66,9 @@ pub(crate) fn compile<'a>(
|
|||
_: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
Some(NotValidator::compile(schema, context))
|
||||
Some(NotValidator::compile(schema, context, arena))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::compilation::ValidatorArena;
|
||||
use crate::{
|
||||
compilation::{compile_validators, context::CompilationContext},
|
||||
error::{error, no_error, ErrorIterator, ValidationError},
|
||||
|
@ -20,13 +21,14 @@ impl OneOfValidator {
|
|||
pub(crate) fn compile<'a>(
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> CompilationResult<'a> {
|
||||
if let Value::Array(items) = schema {
|
||||
let keyword_context = context.with_path("oneOf");
|
||||
let mut schemas = Vec::with_capacity(items.len());
|
||||
for (idx, item) in items.iter().enumerate() {
|
||||
let item_context = keyword_context.with_path(idx);
|
||||
let node = compile_validators(item, &item_context)?;
|
||||
let node = compile_validators(item, &item_context, arena)?;
|
||||
schemas.push(node)
|
||||
}
|
||||
Ok(Box::new(OneOfValidator {
|
||||
|
@ -135,8 +137,9 @@ pub(crate) fn compile<'a>(
|
|||
_: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
Some(OneOfValidator::compile(schema, context))
|
||||
Some(OneOfValidator::compile(schema, context, arena))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -8,6 +8,7 @@ use crate::{
|
|||
};
|
||||
use serde_json::{Map, Value};
|
||||
|
||||
use crate::compilation::ValidatorArena;
|
||||
use crate::paths::JSONPointer;
|
||||
use std::ops::Index;
|
||||
|
||||
|
@ -164,6 +165,7 @@ pub(crate) fn compile<'a>(
|
|||
_: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
Some(PatternValidator::compile(schema, context))
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::compilation::ValidatorArena;
|
||||
use crate::{
|
||||
compilation::{compile_validators, context::CompilationContext},
|
||||
error::{no_error, ErrorIterator, ValidationError},
|
||||
|
@ -20,6 +21,7 @@ impl PatternPropertiesValidator {
|
|||
pub(crate) fn compile<'a>(
|
||||
map: &'a Map<String, Value>,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> CompilationResult<'a> {
|
||||
let keyword_context = context.with_path("patternProperties");
|
||||
let mut patterns = Vec::with_capacity(map.len());
|
||||
|
@ -37,7 +39,7 @@ impl PatternPropertiesValidator {
|
|||
))
|
||||
}
|
||||
},
|
||||
compile_validators(subschema, &pattern_context)?,
|
||||
compile_validators(subschema, &pattern_context, arena)?,
|
||||
));
|
||||
}
|
||||
Ok(Box::new(PatternPropertiesValidator { patterns }))
|
||||
|
@ -133,6 +135,7 @@ impl SingleValuePatternPropertiesValidator {
|
|||
pattern: &'a str,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> CompilationResult<'a> {
|
||||
let keyword_context = context.with_path("patternProperties");
|
||||
let pattern_context = keyword_context.with_path(pattern.to_string());
|
||||
|
@ -148,7 +151,7 @@ impl SingleValuePatternPropertiesValidator {
|
|||
))
|
||||
}
|
||||
},
|
||||
node: compile_validators(schema, &pattern_context)?,
|
||||
node: compile_validators(schema, &pattern_context, arena)?,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
@ -225,6 +228,7 @@ pub(crate) fn compile<'a>(
|
|||
parent: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
match parent.get("additionalProperties") {
|
||||
// This type of `additionalProperties` validator handles `patternProperties` logic
|
||||
|
@ -234,10 +238,10 @@ pub(crate) fn compile<'a>(
|
|||
if map.len() == 1 {
|
||||
let (key, value) = map.iter().next().expect("Map is not empty");
|
||||
Some(SingleValuePatternPropertiesValidator::compile(
|
||||
key, value, context,
|
||||
key, value, context, arena,
|
||||
))
|
||||
} else {
|
||||
Some(PatternPropertiesValidator::compile(map, context))
|
||||
Some(PatternPropertiesValidator::compile(map, context, arena))
|
||||
}
|
||||
} else {
|
||||
Some(Err(ValidationError::single_type_error(
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::compilation::ValidatorArena;
|
||||
use crate::{
|
||||
compilation::{compile_validators, context::CompilationContext},
|
||||
error::{no_error, ErrorIterator, ValidationError},
|
||||
|
@ -19,12 +20,13 @@ impl PrefixItemsValidator {
|
|||
pub(crate) fn compile<'a>(
|
||||
items: &'a [Value],
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> CompilationResult<'a> {
|
||||
let keyword_context = context.with_path("prefixItems");
|
||||
let mut schemas = Vec::with_capacity(items.len());
|
||||
for (idx, item) in items.iter().enumerate() {
|
||||
let item_context = keyword_context.with_path(idx);
|
||||
let validators = compile_validators(item, &item_context)?;
|
||||
let validators = compile_validators(item, &item_context, arena)?;
|
||||
schemas.push(validators)
|
||||
}
|
||||
Ok(Box::new(PrefixItemsValidator { schemas }))
|
||||
|
@ -112,9 +114,10 @@ pub(crate) fn compile<'a>(
|
|||
_: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
if let Value::Array(items) = schema {
|
||||
Some(PrefixItemsValidator::compile(items, context))
|
||||
Some(PrefixItemsValidator::compile(items, context, arena))
|
||||
} else {
|
||||
Some(Err(ValidationError::single_type_error(
|
||||
JSONPointer::default(),
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::compilation::ValidatorArena;
|
||||
use crate::{
|
||||
compilation::{compile_validators, context::CompilationContext},
|
||||
error::{no_error, ErrorIterator, ValidationError},
|
||||
|
@ -19,6 +20,7 @@ impl PropertiesValidator {
|
|||
pub(crate) fn compile<'a>(
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> CompilationResult<'a> {
|
||||
match schema {
|
||||
Value::Object(map) => {
|
||||
|
@ -28,7 +30,7 @@ impl PropertiesValidator {
|
|||
let property_context = context.with_path(key.clone());
|
||||
properties.push((
|
||||
key.clone(),
|
||||
compile_validators(subschema, &property_context)?,
|
||||
compile_validators(subschema, &property_context, arena)?,
|
||||
));
|
||||
}
|
||||
Ok(Box::new(PropertiesValidator { properties }))
|
||||
|
@ -118,11 +120,12 @@ pub(crate) fn compile<'a>(
|
|||
parent: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
match parent.get("additionalProperties") {
|
||||
// This type of `additionalProperties` validator handles `properties` logic
|
||||
Some(Value::Bool(false)) | Some(Value::Object(_)) => None,
|
||||
_ => Some(PropertiesValidator::compile(schema, context)),
|
||||
_ => Some(PropertiesValidator::compile(schema, context, arena)),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::compilation::ValidatorArena;
|
||||
use crate::{
|
||||
compilation::{compile_validators, context::CompilationContext},
|
||||
error::{error, no_error, ErrorIterator, ValidationError},
|
||||
|
@ -17,10 +18,11 @@ impl PropertyNamesObjectValidator {
|
|||
pub(crate) fn compile<'a>(
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> CompilationResult<'a> {
|
||||
let keyword_context = context.with_path("propertyNames");
|
||||
Ok(Box::new(PropertyNamesObjectValidator {
|
||||
node: compile_validators(schema, &keyword_context)?,
|
||||
node: compile_validators(schema, &keyword_context, arena)?,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
@ -146,9 +148,12 @@ pub(crate) fn compile<'a>(
|
|||
_: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
match schema {
|
||||
Value::Object(_) => Some(PropertyNamesObjectValidator::compile(schema, context)),
|
||||
Value::Object(_) => Some(PropertyNamesObjectValidator::compile(
|
||||
schema, context, arena,
|
||||
)),
|
||||
Value::Bool(false) => Some(PropertyNamesBooleanValidator::compile(context)),
|
||||
_ => None,
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::compilation::ValidatorArena;
|
||||
use crate::{
|
||||
compilation::{compile_validators, context::CompilationContext},
|
||||
error::{error, ErrorIterator},
|
||||
|
@ -59,7 +60,8 @@ impl Validate for RefValidator {
|
|||
Arc::clone(&self.config),
|
||||
Arc::clone(&self.resolver),
|
||||
);
|
||||
if let Ok(node) = compile_validators(&resolved, &context) {
|
||||
let mut arena = ValidatorArena::new();
|
||||
if let Ok(node) = compile_validators(&resolved, &context, &mut arena) {
|
||||
let result = node.is_valid(instance);
|
||||
*self.sub_nodes.write() = Some(node);
|
||||
return result;
|
||||
|
@ -91,7 +93,8 @@ impl Validate for RefValidator {
|
|||
Arc::clone(&self.config),
|
||||
Arc::clone(&self.resolver),
|
||||
);
|
||||
match compile_validators(&resolved, &context) {
|
||||
let mut arena = ValidatorArena::new();
|
||||
match compile_validators(&resolved, &context, &mut arena) {
|
||||
Ok(node) => {
|
||||
let result = Box::new(
|
||||
node.err_iter(instance, instance_path)
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::compilation::ValidatorArena;
|
||||
use crate::{
|
||||
compilation::context::CompilationContext,
|
||||
error::{error, no_error, ErrorIterator, ValidationError},
|
||||
|
@ -133,6 +134,7 @@ pub(crate) fn compile<'a>(
|
|||
_: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
let schema_path = context.as_pointer_with("required");
|
||||
compile_with_path(schema, schema_path)
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::compilation::ValidatorArena;
|
||||
use crate::{
|
||||
compilation::context::CompilationContext,
|
||||
error::{error, no_error, ErrorIterator, ValidationError},
|
||||
|
@ -380,6 +381,7 @@ pub(crate) fn compile<'a>(
|
|||
_: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
let schema_path = context.as_pointer_with("type");
|
||||
match schema {
|
||||
|
|
|
@ -7,6 +7,7 @@ use crate::{
|
|||
use ahash::{AHashSet, AHasher};
|
||||
use serde_json::{Map, Value};
|
||||
|
||||
use crate::compilation::ValidatorArena;
|
||||
use crate::paths::{InstancePath, JSONPointer};
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
||||
|
@ -138,6 +139,7 @@ pub(crate) fn compile<'a>(
|
|||
_: &'a Map<String, Value>,
|
||||
schema: &'a Value,
|
||||
context: &CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<CompilationResult<'a>> {
|
||||
if let Value::Bool(value) = schema {
|
||||
if *value {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use crate::compilation::ValidatorArena;
|
||||
use crate::{compilation::context::CompilationContext, keywords};
|
||||
use serde_json::{Map, Value};
|
||||
|
||||
|
@ -44,6 +45,7 @@ type CompileFunc<'a> = fn(
|
|||
&'a Map<String, Value>,
|
||||
&'a Value,
|
||||
&CompilationContext,
|
||||
arena: &mut ValidatorArena,
|
||||
) -> Option<keywords::CompilationResult<'a>>;
|
||||
|
||||
impl Draft {
|
||||
|
|
Loading…
Reference in New Issue