chore: Add unreachable_pub lint

This commit is contained in:
Samuele Maci 2020-07-18 13:26:27 +01:00 committed by Dmitry Dygalo
parent 7b3978f83b
commit bc04d70ae3
46 changed files with 168 additions and 167 deletions

View File

@ -12,7 +12,7 @@ use serde_json::Value;
use std::borrow::Cow;
use url::{ParseError, Url};
pub const DEFAULT_ROOT_URL: &str = "json-schema:///";
pub(crate) const DEFAULT_ROOT_URL: &str = "json-schema:///";
/// The structure that holds a JSON Schema compiled into a validation tree
#[derive(Debug)]
@ -87,7 +87,7 @@ impl<'a> JSONSchema<'a> {
/// Context holds information about used draft and current scope.
#[derive(Debug)]
pub struct CompilationContext<'a> {
pub(crate) struct CompilationContext<'a> {
pub(crate) scope: Cow<'a, Url>,
pub(crate) draft: schemas::Draft,
}
@ -134,7 +134,7 @@ impl<'a> CompilationContext<'a> {
/// Compile JSON schema into a tree of validators.
#[inline]
pub fn compile_validators(
pub(crate) fn compile_validators(
schema: &Value,
context: &CompilationContext,
) -> Result<Validators, CompilationError> {

View File

@ -72,17 +72,17 @@ pub struct ValidationError<'a> {
pub type ErrorIterator<'a> = Box<dyn Iterator<Item = ValidationError<'a>> + Sync + Send + 'a>;
// Empty iterator means no error happened
pub fn no_error<'a>() -> ErrorIterator<'a> {
pub(crate) fn no_error<'a>() -> ErrorIterator<'a> {
Box::new(empty())
}
// A wrapper for one error
pub fn error(instance: ValidationError) -> ErrorIterator {
pub(crate) fn error(instance: ValidationError) -> ErrorIterator {
Box::new(once(instance))
}
/// Kinds of errors that may happen during validation
#[derive(Debug)]
pub enum ValidationErrorKind {
pub(crate) enum ValidationErrorKind {
/// The input array contain more items than expected.
AdditionalItems { limit: usize },
/// The input value is not valid under any of the given schemas.
@ -157,7 +157,7 @@ pub enum ValidationErrorKind {
}
#[derive(Debug)]
pub enum TypeKind {
pub(crate) enum TypeKind {
Single(PrimitiveType),
Multiple(PrimitiveTypesBitMap),
}

View File

@ -9,7 +9,7 @@ use crate::{
};
use serde_json::{Map, Value};
pub struct AdditionalItemsObjectValidator {
pub(crate) struct AdditionalItemsObjectValidator {
validators: Validators,
items_count: usize,
}
@ -80,7 +80,7 @@ impl ToString for AdditionalItemsObjectValidator {
}
}
pub struct AdditionalItemsBooleanValidator {
pub(crate) struct AdditionalItemsBooleanValidator {
items_count: usize,
}
impl AdditionalItemsBooleanValidator {
@ -115,7 +115,7 @@ impl ToString for AdditionalItemsBooleanValidator {
}
#[inline]
pub fn compile(
pub(crate) fn compile(
parent: &Map<String, Value>,
schema: &Value,
context: &CompilationContext,

View File

@ -8,7 +8,7 @@ use regex::Regex;
use serde_json::{Map, Value};
use std::{collections::BTreeSet, iter::FromIterator};
pub struct AdditionalPropertiesValidator {
pub(crate) struct AdditionalPropertiesValidator {
validators: Validators,
}
impl AdditionalPropertiesValidator {
@ -79,7 +79,7 @@ impl ToString for AdditionalPropertiesValidator {
}
}
pub struct AdditionalPropertiesFalseValidator {}
pub(crate) struct AdditionalPropertiesFalseValidator {}
impl AdditionalPropertiesFalseValidator {
#[inline]
pub(crate) fn compile() -> CompilationResult {
@ -116,7 +116,7 @@ impl ToString for AdditionalPropertiesFalseValidator {
}
}
pub struct AdditionalPropertiesNotEmptyFalseValidator {
pub(crate) struct AdditionalPropertiesNotEmptyFalseValidator {
properties: BTreeSet<String>,
}
impl AdditionalPropertiesNotEmptyFalseValidator {
@ -182,7 +182,7 @@ impl ToString for AdditionalPropertiesNotEmptyFalseValidator {
}
}
pub struct AdditionalPropertiesNotEmptyValidator {
pub(crate) struct AdditionalPropertiesNotEmptyValidator {
validators: Validators,
properties: BTreeSet<String>,
}
@ -264,7 +264,7 @@ impl ToString for AdditionalPropertiesNotEmptyValidator {
}
}
pub struct AdditionalPropertiesWithPatternsValidator {
pub(crate) struct AdditionalPropertiesWithPatternsValidator {
validators: Validators,
pattern: Regex,
}
@ -343,7 +343,7 @@ impl ToString for AdditionalPropertiesWithPatternsValidator {
}
}
pub struct AdditionalPropertiesWithPatternsFalseValidator {
pub(crate) struct AdditionalPropertiesWithPatternsFalseValidator {
pattern: Regex,
}
impl AdditionalPropertiesWithPatternsFalseValidator {
@ -407,7 +407,7 @@ impl ToString for AdditionalPropertiesWithPatternsFalseValidator {
}
}
pub struct AdditionalPropertiesWithPatternsNotEmptyValidator {
pub(crate) struct AdditionalPropertiesWithPatternsNotEmptyValidator {
validators: Validators,
properties: BTreeSet<String>,
pattern: Regex,
@ -499,7 +499,7 @@ impl ToString for AdditionalPropertiesWithPatternsNotEmptyValidator {
}
}
pub struct AdditionalPropertiesWithPatternsNotEmptyFalseValidator {
pub(crate) struct AdditionalPropertiesWithPatternsNotEmptyFalseValidator {
properties: BTreeSet<String>,
pattern: Regex,
}
@ -573,7 +573,7 @@ impl ToString for AdditionalPropertiesWithPatternsNotEmptyFalseValidator {
}
#[inline]
pub fn compile(
pub(crate) fn compile(
parent: &Map<String, Value>,
schema: &Value,
context: &CompilationContext,

View File

@ -6,7 +6,7 @@ use crate::{
};
use serde_json::{Map, Value};
pub struct AllOfValidator {
pub(crate) struct AllOfValidator {
schemas: Vec<Validators>,
}
@ -96,7 +96,7 @@ impl ToString for AllOfValidator {
}
#[inline]
pub fn compile(
pub(crate) fn compile(
_: &Map<String, Value>,
schema: &Value,
context: &CompilationContext,

View File

@ -6,7 +6,7 @@ use crate::{
};
use serde_json::{Map, Value};
pub struct AnyOfValidator {
pub(crate) struct AnyOfValidator {
schemas: Vec<Validators>,
}
@ -67,7 +67,7 @@ impl ToString for AnyOfValidator {
}
#[inline]
pub fn compile(
pub(crate) fn compile(
_: &Map<String, Value>,
schema: &Value,
context: &CompilationContext,

View File

@ -6,7 +6,7 @@ use crate::{
};
use serde_json::{Map, Value};
pub struct TrueValidator {}
pub(crate) struct TrueValidator {}
impl TrueValidator {
#[inline]
pub(crate) fn compile() -> CompilationResult {
@ -30,7 +30,7 @@ impl ToString for TrueValidator {
}
}
pub struct FalseValidator {}
pub(crate) struct FalseValidator {}
impl FalseValidator {
#[inline]
pub(crate) fn compile() -> CompilationResult {
@ -92,7 +92,7 @@ impl ToString for FalseValidator {
}
#[inline]
pub fn compile(value: bool) -> Option<CompilationResult> {
pub(crate) fn compile(value: bool) -> Option<CompilationResult> {
if value {
Some(TrueValidator::compile())
} else {

View File

@ -476,7 +476,7 @@ impl ToString for ConstStringValidator {
}
#[inline]
pub fn compile(
pub(crate) fn compile(
_: &Map<String, Value>,
schema: &Value,
_: &CompilationContext,

View File

@ -6,7 +6,7 @@ use crate::{
};
use serde_json::{Map, Value};
pub struct ContainsValidator {
pub(crate) struct ContainsValidator {
validators: Validators,
}
@ -63,7 +63,7 @@ impl ToString for ContainsValidator {
}
#[inline]
pub fn compile(
pub(crate) fn compile(
_: &Map<String, Value>,
schema: &Value,
context: &CompilationContext,

View File

@ -8,7 +8,7 @@ use crate::{
use serde_json::{from_str, Map, Value};
/// Validator for `contentMediaType` keyword.
pub struct ContentMediaTypeValidator {
pub(crate) struct ContentMediaTypeValidator {
media_type: String,
func: for<'a> fn(&'a Value, &str) -> ErrorIterator<'a>,
}
@ -66,7 +66,7 @@ impl ToString for ContentMediaTypeValidator {
}
/// Validator for `contentEncoding` keyword.
pub struct ContentEncodingValidator {
pub(crate) struct ContentEncodingValidator {
encoding: String,
func: for<'a> fn(&'a Value, &str) -> ErrorIterator<'a>,
}
@ -123,7 +123,7 @@ impl ToString for ContentEncodingValidator {
}
/// Combined validator for both `contentEncoding` and `contentMediaType` keywords.
pub struct ContentMediaTypeAndEncodingValidator {
pub(crate) struct ContentMediaTypeAndEncodingValidator {
media_type: String,
encoding: String,
func: for<'a> fn(&'a Value, &str) -> ErrorIterator<'a>,
@ -200,21 +200,21 @@ impl ToString for ContentMediaTypeAndEncodingValidator {
}
}
pub fn is_json<'a>(instance: &'a Value, instance_string: &str) -> ErrorIterator<'a> {
pub(crate) fn is_json<'a>(instance: &'a Value, instance_string: &str) -> ErrorIterator<'a> {
if from_str::<Value>(instance_string).is_err() {
return error(ValidationError::format(instance, "application/json"));
}
no_error()
}
pub fn is_base64<'a>(instance: &'a Value, instance_string: &str) -> ErrorIterator<'a> {
pub(crate) fn is_base64<'a>(instance: &'a Value, instance_string: &str) -> ErrorIterator<'a> {
if base64::decode(instance_string).is_err() {
return error(ValidationError::format(instance, "base64"));
}
no_error()
}
pub fn from_base64<'a>(
pub(crate) fn from_base64<'a>(
instance: &'a Value,
instance_string: &str,
) -> Result<String, ValidationError<'a>> {
@ -225,7 +225,7 @@ pub fn from_base64<'a>(
}
#[inline]
pub fn compile_media_type(
pub(crate) fn compile_media_type(
schema: &Map<String, Value>,
subschema: &Value,
_: &CompilationContext,
@ -261,7 +261,7 @@ pub fn compile_media_type(
}
#[inline]
pub fn compile_content_encoding(
pub(crate) fn compile_content_encoding(
schema: &Map<String, Value>,
subschema: &Value,
_: &CompilationContext,

View File

@ -8,7 +8,7 @@ use crate::{
};
use serde_json::{Map, Value};
pub struct DependenciesValidator {
pub(crate) struct DependenciesValidator {
dependencies: Vec<(String, Validators)>,
}
@ -96,7 +96,7 @@ impl ToString for DependenciesValidator {
}
#[inline]
pub fn compile(
pub(crate) fn compile(
_: &Map<String, Value>,
schema: &Value,
context: &CompilationContext,

View File

@ -8,7 +8,7 @@ use serde_json::{Map, Value};
use std::f64::EPSILON;
#[derive(Debug)]
pub struct EnumValidator {
pub(crate) struct EnumValidator {
options: Value,
items: Vec<Value>,
}
@ -117,7 +117,7 @@ impl ToString for EnumValidator {
}
#[inline]
pub fn compile(
pub(crate) fn compile(
_: &Map<String, Value>,
schema: &Value,
_: &CompilationContext,

View File

@ -7,13 +7,13 @@ use crate::{
use num_cmp::NumCmp;
use serde_json::{Map, Value};
pub struct ExclusiveMaximumU64Validator {
pub(crate) struct ExclusiveMaximumU64Validator {
limit: u64,
}
pub struct ExclusiveMaximumI64Validator {
pub(crate) struct ExclusiveMaximumI64Validator {
limit: i64,
}
pub struct ExclusiveMaximumF64Validator {
pub(crate) struct ExclusiveMaximumF64Validator {
limit: f64,
}
@ -99,7 +99,7 @@ validate!(ExclusiveMaximumI64Validator);
validate!(ExclusiveMaximumF64Validator);
#[inline]
pub fn compile(
pub(crate) fn compile(
_: &Map<String, Value>,
schema: &Value,
_: &CompilationContext,

View File

@ -7,13 +7,13 @@ use crate::{
use num_cmp::NumCmp;
use serde_json::{Map, Value};
pub struct ExclusiveMinimumU64Validator {
pub(crate) struct ExclusiveMinimumU64Validator {
limit: u64,
}
pub struct ExclusiveMinimumI64Validator {
pub(crate) struct ExclusiveMinimumI64Validator {
limit: i64,
}
pub struct ExclusiveMinimumF64Validator {
pub(crate) struct ExclusiveMinimumF64Validator {
limit: f64,
}
@ -99,7 +99,7 @@ validate!(ExclusiveMinimumI64Validator);
validate!(ExclusiveMinimumF64Validator);
#[inline]
pub fn compile(
pub(crate) fn compile(
_: &Map<String, Value>,
schema: &Value,
_: &CompilationContext,

View File

@ -157,7 +157,7 @@ string_format_validator!(URITemplateValidator, "uri-template", |instance_value|
});
#[inline]
pub fn compile(
pub(crate) fn compile(
_: &Map<String, Value>,
schema: &Value,
context: &CompilationContext,

View File

@ -6,7 +6,7 @@ use crate::{
};
use serde_json::{Map, Value};
pub struct IfThenValidator {
pub(crate) struct IfThenValidator {
schema: Validators,
then_schema: Validators,
}
@ -110,7 +110,7 @@ impl ToString for IfThenValidator {
}
}
pub struct IfElseValidator {
pub(crate) struct IfElseValidator {
schema: Validators,
else_schema: Validators,
}
@ -214,7 +214,7 @@ impl ToString for IfElseValidator {
}
}
pub struct IfThenElseValidator {
pub(crate) struct IfThenElseValidator {
schema: Validators,
then_schema: Validators,
else_schema: Validators,
@ -332,7 +332,7 @@ impl ToString for IfThenElseValidator {
}
#[inline]
pub fn compile(
pub(crate) fn compile(
parent: &Map<String, Value>,
schema: &Value,
context: &CompilationContext,

View File

@ -10,7 +10,7 @@ use crate::{
use rayon::prelude::*;
use serde_json::{Map, Value};
pub struct ItemsArrayValidator {
pub(crate) struct ItemsArrayValidator {
items: Vec<Validators>,
}
impl ItemsArrayValidator {
@ -80,7 +80,7 @@ impl ToString for ItemsArrayValidator {
}
}
pub struct ItemsObjectValidator {
pub(crate) struct ItemsObjectValidator {
validators: Validators,
}
impl ItemsObjectValidator {
@ -161,7 +161,7 @@ impl ToString for ItemsObjectValidator {
}
#[inline]
pub fn compile(
pub(crate) fn compile(
_: &Map<String, Value>,
schema: &Value,
context: &CompilationContext,

View File

@ -5,7 +5,7 @@ use crate::{
use serde_json::{Map, Value};
#[inline]
pub fn compile(
pub(crate) fn compile(
parent: &Map<String, Value>,
schema: &Value,
context: &CompilationContext,

View File

@ -5,7 +5,7 @@ use crate::{
use serde_json::{Map, Value};
#[inline]
pub fn compile(
pub(crate) fn compile(
parent: &Map<String, Value>,
schema: &Value,
context: &CompilationContext,

View File

@ -1,3 +1,3 @@
pub mod maximum_draft_4;
pub mod minimum_draft_4;
pub mod type_draft_4;
pub(crate) mod maximum_draft_4;
pub(crate) mod minimum_draft_4;
pub(crate) mod type_draft_4;

View File

@ -8,7 +8,7 @@ use crate::{
use serde_json::{Map, Value};
use std::convert::TryFrom;
pub struct MultipleTypesValidator {
pub(crate) struct MultipleTypesValidator {
types: PrimitiveTypesBitMap,
}
@ -83,7 +83,7 @@ impl ToString for MultipleTypesValidator {
)
}
}
pub struct IntegerTypeValidator {}
pub(crate) struct IntegerTypeValidator {}
impl IntegerTypeValidator {
#[inline]
@ -151,7 +151,7 @@ impl ToString for IntegerTypeValidator {
}
#[inline]
pub fn compile(
pub(crate) fn compile(
_: &Map<String, Value>,
schema: &Value,
_: &CompilationContext,

View File

@ -6,7 +6,7 @@ use crate::{
};
use serde_json::{Map, Value};
pub struct MaxItemsValidator {
pub(crate) struct MaxItemsValidator {
limit: u64,
}
@ -55,7 +55,7 @@ impl ToString for MaxItemsValidator {
}
#[inline]
pub fn compile(
pub(crate) fn compile(
_: &Map<String, Value>,
schema: &Value,
_: &CompilationContext,

View File

@ -6,7 +6,7 @@ use crate::{
};
use serde_json::{Map, Value};
pub struct MaxLengthValidator {
pub(crate) struct MaxLengthValidator {
limit: u64,
}
@ -55,7 +55,7 @@ impl ToString for MaxLengthValidator {
}
#[inline]
pub fn compile(
pub(crate) fn compile(
_: &Map<String, Value>,
schema: &Value,
_: &CompilationContext,

View File

@ -6,7 +6,7 @@ use crate::{
};
use serde_json::{Map, Value};
pub struct MaxPropertiesValidator {
pub(crate) struct MaxPropertiesValidator {
limit: u64,
}
@ -60,7 +60,7 @@ impl ToString for MaxPropertiesValidator {
}
#[inline]
pub fn compile(
pub(crate) fn compile(
_: &Map<String, Value>,
schema: &Value,
_: &CompilationContext,

View File

@ -7,13 +7,13 @@ use crate::{
use num_cmp::NumCmp;
use serde_json::{Map, Value};
pub struct MaximumU64Validator {
pub(crate) struct MaximumU64Validator {
limit: u64,
}
pub struct MaximumI64Validator {
pub(crate) struct MaximumI64Validator {
limit: i64,
}
pub struct MaximumF64Validator {
pub(crate) struct MaximumF64Validator {
limit: f64,
}
@ -99,7 +99,7 @@ validate!(MaximumI64Validator);
validate!(MaximumF64Validator);
#[inline]
pub fn compile(
pub(crate) fn compile(
_: &Map<String, Value>,
schema: &Value,
_: &CompilationContext,

View File

@ -6,7 +6,7 @@ use crate::{
};
use serde_json::{Map, Value};
pub struct MinItemsValidator {
pub(crate) struct MinItemsValidator {
limit: u64,
}
@ -55,7 +55,7 @@ impl ToString for MinItemsValidator {
}
#[inline]
pub fn compile(
pub(crate) fn compile(
_: &Map<String, Value>,
schema: &Value,
_: &CompilationContext,

View File

@ -6,7 +6,7 @@ use crate::{
};
use serde_json::{Map, Value};
pub struct MinLengthValidator {
pub(crate) struct MinLengthValidator {
limit: u64,
}
@ -55,7 +55,7 @@ impl ToString for MinLengthValidator {
}
#[inline]
pub fn compile(
pub(crate) fn compile(
_: &Map<String, Value>,
schema: &Value,
_: &CompilationContext,

View File

@ -6,7 +6,7 @@ use crate::{
};
use serde_json::{Map, Value};
pub struct MinPropertiesValidator {
pub(crate) struct MinPropertiesValidator {
limit: u64,
}
@ -60,7 +60,7 @@ impl ToString for MinPropertiesValidator {
}
#[inline]
pub fn compile(
pub(crate) fn compile(
_: &Map<String, Value>,
schema: &Value,
_: &CompilationContext,

View File

@ -7,13 +7,13 @@ use crate::{
use num_cmp::NumCmp;
use serde_json::{Map, Value};
pub struct MinimumU64Validator {
pub(crate) struct MinimumU64Validator {
limit: u64,
}
pub struct MinimumI64Validator {
pub(crate) struct MinimumI64Validator {
limit: i64,
}
pub struct MinimumF64Validator {
pub(crate) struct MinimumF64Validator {
limit: f64,
}
@ -99,7 +99,7 @@ validate!(MinimumI64Validator);
validate!(MinimumF64Validator);
#[inline]
pub fn compile(
pub(crate) fn compile(
_: &Map<String, Value>,
schema: &Value,
_: &CompilationContext,

View File

@ -1,43 +1,43 @@
pub mod additional_items;
pub mod additional_properties;
pub mod all_of;
pub mod any_of;
pub mod boolean;
pub mod const_;
pub mod contains;
pub mod content;
pub mod dependencies;
pub mod enum_;
pub mod exclusive_maximum;
pub mod exclusive_minimum;
pub mod format;
pub mod if_;
pub mod items;
pub mod legacy;
pub mod max_items;
pub mod max_length;
pub mod max_properties;
pub mod maximum;
pub mod min_items;
pub mod min_length;
pub mod min_properties;
pub mod minimum;
pub mod multiple_of;
pub mod not;
pub mod one_of;
pub mod pattern;
pub mod pattern_properties;
pub mod properties;
pub mod property_names;
pub mod ref_;
pub mod required;
pub mod type_;
pub mod unique_items;
pub(crate) mod additional_items;
pub(crate) mod additional_properties;
pub(crate) mod all_of;
pub(crate) mod any_of;
pub(crate) mod boolean;
pub(crate) mod const_;
pub(crate) mod contains;
pub(crate) mod content;
pub(crate) mod dependencies;
pub(crate) mod enum_;
pub(crate) mod exclusive_maximum;
pub(crate) mod exclusive_minimum;
pub(crate) mod format;
pub(crate) mod if_;
pub(crate) mod items;
pub(crate) mod legacy;
pub(crate) mod max_items;
pub(crate) mod max_length;
pub(crate) mod max_properties;
pub(crate) mod maximum;
pub(crate) mod min_items;
pub(crate) mod min_length;
pub(crate) mod min_properties;
pub(crate) mod minimum;
pub(crate) mod multiple_of;
pub(crate) mod not;
pub(crate) mod one_of;
pub(crate) mod pattern;
pub(crate) mod pattern_properties;
pub(crate) mod properties;
pub(crate) mod property_names;
pub(crate) mod ref_;
pub(crate) mod required;
pub(crate) mod type_;
pub(crate) mod unique_items;
use crate::{error, validator::Validate};
pub type CompilationResult = Result<BoxedValidator, error::CompilationError>;
pub type BoxedValidator = Box<dyn Validate + Send + Sync>;
pub type Validators = Vec<BoxedValidator>;
pub(crate) type CompilationResult = Result<BoxedValidator, error::CompilationError>;
pub(crate) type BoxedValidator = Box<dyn Validate + Send + Sync>;
pub(crate) type Validators = Vec<BoxedValidator>;
fn format_validators(validators: &[BoxedValidator]) -> String {
match validators.len() {

View File

@ -7,7 +7,7 @@ use crate::{
use serde_json::{Map, Value};
use std::f64::EPSILON;
pub struct MultipleOfFloatValidator {
pub(crate) struct MultipleOfFloatValidator {
multiple_of: f64,
}
@ -73,7 +73,7 @@ impl ToString for MultipleOfFloatValidator {
}
}
pub struct MultipleOfIntegerValidator {
pub(crate) struct MultipleOfIntegerValidator {
multiple_of: f64,
}
@ -144,7 +144,7 @@ impl ToString for MultipleOfIntegerValidator {
}
#[inline]
pub fn compile(
pub(crate) fn compile(
_: &Map<String, Value>,
schema: &Value,
_: &CompilationContext,

View File

@ -6,7 +6,7 @@ use crate::{
};
use serde_json::{Map, Value};
pub struct NotValidator {
pub(crate) struct NotValidator {
// needed only for error representation
original: Value,
validators: Validators,
@ -62,7 +62,7 @@ impl ToString for NotValidator {
}
#[inline]
pub fn compile(
pub(crate) fn compile(
_: &Map<String, Value>,
schema: &Value,
context: &CompilationContext,

View File

@ -6,7 +6,7 @@ use crate::{
};
use serde_json::{Map, Value};
pub struct OneOfValidator {
pub(crate) struct OneOfValidator {
schemas: Vec<Validators>,
}
@ -110,7 +110,7 @@ impl ToString for OneOfValidator {
}
#[inline]
pub fn compile(
pub(crate) fn compile(
_: &Map<String, Value>,
schema: &Value,
context: &CompilationContext,

View File

@ -13,7 +13,7 @@ lazy_static::lazy_static! {
static ref CONTROL_GROUPS_RE: Regex = Regex::new(r"\\c[A-Za-z]").expect("Is a valid regex");
}
pub struct PatternValidator {
pub(crate) struct PatternValidator {
original: String,
pattern: Regex,
}
@ -104,7 +104,7 @@ fn replace_control_group(captures: &Captures) -> String {
}
#[inline]
pub fn compile(
pub(crate) fn compile(
_: &Map<String, Value>,
schema: &Value,
_: &CompilationContext,

View File

@ -7,7 +7,7 @@ use crate::{
use regex::Regex;
use serde_json::{Map, Value};
pub struct PatternPropertiesValidator {
pub(crate) struct PatternPropertiesValidator {
patterns: Vec<(Regex, Validators)>,
}
@ -103,7 +103,7 @@ impl ToString for PatternPropertiesValidator {
}
#[inline]
pub fn compile(
pub(crate) fn compile(
_: &Map<String, Value>,
schema: &Value,
context: &CompilationContext,

View File

@ -6,7 +6,7 @@ use crate::{
};
use serde_json::{Map, Value};
pub struct PropertiesValidator {
pub(crate) struct PropertiesValidator {
properties: Vec<(String, Validators)>,
}
@ -94,7 +94,7 @@ impl ToString for PropertiesValidator {
}
#[inline]
pub fn compile(
pub(crate) fn compile(
_: &Map<String, Value>,
schema: &Value,
context: &CompilationContext,

View File

@ -6,7 +6,7 @@ use crate::{
};
use serde_json::{Map, Value};
pub struct PropertyNamesObjectValidator {
pub(crate) struct PropertyNamesObjectValidator {
validators: Validators,
}
@ -81,7 +81,7 @@ impl ToString for PropertyNamesObjectValidator {
}
}
pub struct PropertyNamesBooleanValidator {}
pub(crate) struct PropertyNamesBooleanValidator {}
impl PropertyNamesBooleanValidator {
#[inline]
@ -121,7 +121,7 @@ impl ToString for PropertyNamesBooleanValidator {
}
#[inline]
pub fn compile(
pub(crate) fn compile(
_: &Map<String, Value>,
schema: &Value,
context: &CompilationContext,

View File

@ -8,7 +8,7 @@ use parking_lot::RwLock;
use serde_json::{Map, Value};
use url::Url;
pub struct RefValidator {
pub(crate) struct RefValidator {
reference: Url,
/// Precomputed validators.
/// They are behind a RwLock as is not possible to compute them
@ -129,7 +129,7 @@ impl ToString for RefValidator {
}
#[inline]
pub fn compile(
pub(crate) fn compile(
_: &Value,
reference: &str,
context: &CompilationContext,

View File

@ -6,7 +6,7 @@ use crate::{
};
use serde_json::{Map, Value};
pub struct RequiredValidator {
pub(crate) struct RequiredValidator {
required: Vec<String>,
}
@ -80,7 +80,7 @@ impl ToString for RequiredValidator {
}
#[inline]
pub fn compile(
pub(crate) fn compile(
_: &Map<String, Value>,
schema: &Value,
_: &CompilationContext,

View File

@ -8,7 +8,7 @@ use crate::{
use serde_json::{Map, Value};
use std::convert::TryFrom;
pub struct MultipleTypesValidator {
pub(crate) struct MultipleTypesValidator {
types: PrimitiveTypesBitMap,
}
@ -85,7 +85,7 @@ impl ToString for MultipleTypesValidator {
}
}
pub struct NullTypeValidator {}
pub(crate) struct NullTypeValidator {}
impl NullTypeValidator {
#[inline]
@ -152,7 +152,7 @@ impl ToString for NullTypeValidator {
}
}
pub struct BooleanTypeValidator {}
pub(crate) struct BooleanTypeValidator {}
impl BooleanTypeValidator {
#[inline]
@ -219,7 +219,7 @@ impl ToString for BooleanTypeValidator {
}
}
pub struct StringTypeValidator {}
pub(crate) struct StringTypeValidator {}
impl StringTypeValidator {
#[inline]
@ -286,7 +286,7 @@ impl ToString for StringTypeValidator {
}
}
pub struct ArrayTypeValidator {}
pub(crate) struct ArrayTypeValidator {}
impl ArrayTypeValidator {
#[inline]
@ -353,7 +353,7 @@ impl ToString for ArrayTypeValidator {
}
}
pub struct ObjectTypeValidator {}
pub(crate) struct ObjectTypeValidator {}
impl ObjectTypeValidator {
#[inline]
@ -420,7 +420,7 @@ impl ToString for ObjectTypeValidator {
}
}
pub struct NumberTypeValidator {}
pub(crate) struct NumberTypeValidator {}
impl NumberTypeValidator {
#[inline]
@ -478,7 +478,7 @@ impl ToString for NumberTypeValidator {
"type: number".to_string()
}
}
pub struct IntegerTypeValidator {}
pub(crate) struct IntegerTypeValidator {}
impl IntegerTypeValidator {
#[inline]
@ -549,7 +549,7 @@ impl ToString for IntegerTypeValidator {
}
#[inline]
pub fn compile(
pub(crate) fn compile(
_: &Map<String, Value>,
schema: &Value,
_: &CompilationContext,

View File

@ -13,7 +13,7 @@ use std::{
// Based on implementation proposed by Sven Marnach:
// https://stackoverflow.com/questions/60882381/what-is-the-fastest-correct-way-to-detect-that-there-are-no-duplicates-in-a-json
#[derive(PartialEq)]
pub struct HashedValue<'a>(&'a Value);
pub(crate) struct HashedValue<'a>(&'a Value);
impl Eq for HashedValue<'_> {}
@ -54,12 +54,12 @@ impl Hash for HashedValue<'_> {
}
#[inline]
pub fn is_unique(items: &[Value]) -> bool {
pub(crate) fn is_unique(items: &[Value]) -> bool {
let mut seen = HashSet::with_capacity(items.len());
items.iter().map(HashedValue).all(move |x| seen.insert(x))
}
pub struct UniqueItemsValidator {}
pub(crate) struct UniqueItemsValidator {}
impl UniqueItemsValidator {
#[inline]
@ -102,7 +102,7 @@ impl ToString for UniqueItemsValidator {
}
}
#[inline]
pub fn compile(
pub(crate) fn compile(
_: &Map<String, Value>,
schema: &Value,
_: &CompilationContext,

View File

@ -47,6 +47,7 @@
unused_extern_crates,
unused_import_braces,
unused_qualifications,
unreachable_pub,
variant_size_differences
)]
mod compilation;
@ -84,7 +85,7 @@ mod tests_util {
use super::JSONSchema;
use serde_json::Value;
pub fn is_not_valid(schema: Value, instance: Value) {
pub(crate) fn is_not_valid(schema: Value, instance: Value) {
let compiled = JSONSchema::compile(&schema, None).unwrap();
assert!(!compiled.is_valid(&instance), "{} should not be valid");
assert!(

View File

@ -3,7 +3,7 @@ use std::{convert::TryFrom, fmt, ops::BitOrAssign};
/// For faster error handling in "type" keyword validator we have this enum, to match
/// with it instead of a string.
#[derive(Debug, Clone, Copy)]
pub enum PrimitiveType {
pub(crate) enum PrimitiveType {
Array,
Boolean,
Integer,
@ -73,7 +73,7 @@ fn bit_map_representation_primitive_type(bit_representation: u8) -> PrimitiveTyp
}
#[derive(Clone, Copy, Debug)]
pub struct PrimitiveTypesBitMap {
pub(crate) struct PrimitiveTypesBitMap {
inner: u8,
}
impl PrimitiveTypesBitMap {
@ -119,7 +119,7 @@ impl From<Vec<PrimitiveType>> for PrimitiveTypesBitMap {
}
}
pub struct PrimitiveTypesBitMapIterator {
pub(crate) struct PrimitiveTypesBitMapIterator {
range: std::ops::Range<u8>,
bit_map: PrimitiveTypesBitMap,
}

View File

@ -10,7 +10,7 @@ use std::{borrow::Cow, collections::HashMap};
use url::Url;
#[derive(Debug)]
pub struct Resolver<'a> {
pub(crate) struct Resolver<'a> {
// canonical_id: sub-schema mapping to resolve documents by their ID
// canonical_id is composed with the root document id
// (if not specified, then `DEFAULT_ROOT_URL` is used for this purpose)
@ -108,7 +108,7 @@ fn join_folders(mut resource: Url, folders: &[&str]) -> Result<Url, url::ParseEr
/// Find all sub-schemas in the document and execute callback on each of them.
#[inline]
pub fn find_schemas<'a, F>(
pub(crate) fn find_schemas<'a, F>(
draft: Draft,
schema: &'a Value,
base_url: &Url,
@ -153,7 +153,7 @@ where
}
/// Based on `serde_json`, but tracks folders in the traversed documents.
pub fn pointer<'a>(
pub(crate) fn pointer<'a>(
draft: Draft,
document: &'a Value,
pointer: &str,

View File

@ -97,7 +97,7 @@ impl Draft {
/// Get the `Draft` from a JSON Schema URL.
#[inline]
pub fn draft_from_url(url: &str) -> Option<Draft> {
pub(crate) fn draft_from_url(url: &str) -> Option<Draft> {
match url {
"http://json-schema.org/draft-07/schema#" => Some(Draft::Draft7),
"http://json-schema.org/draft-06/schema#" => Some(Draft::Draft6),
@ -108,7 +108,7 @@ pub fn draft_from_url(url: &str) -> Option<Draft> {
/// Get the `Draft` from a JSON Schema.
#[inline]
pub fn draft_from_schema(schema: &Value) -> Option<Draft> {
pub(crate) fn draft_from_schema(schema: &Value) -> Option<Draft> {
schema
.get("$schema")
.and_then(Value::as_str)
@ -116,7 +116,7 @@ pub fn draft_from_schema(schema: &Value) -> Option<Draft> {
}
#[inline]
pub fn id_of(draft: Draft, schema: &Value) -> Option<&str> {
pub(crate) fn id_of(draft: Draft, schema: &Value) -> Option<&str> {
if let Value::Object(object) = schema {
if draft == Draft::Draft4 {
object.get("id")

View File

@ -5,7 +5,7 @@ use crate::{
use serde_json::{Map, Value};
use std::fmt;
pub trait Validate: Send + Sync + ToString {
pub(crate) trait Validate: Send + Sync + ToString {
#[inline]
fn build_validation_error<'a>(&self, instance: &'a Value) -> ValidationError<'a> {
ValidationError::unexpected(instance, &self.to_string())