Skip to content

Commit

Permalink
chore: Make Debug implementation for SchemaNode opaque
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Dygalo <[email protected]>
  • Loading branch information
Stranger6667 committed Sep 16, 2024
1 parent aa295e7 commit f9bb59f
Show file tree
Hide file tree
Showing 41 changed files with 32 additions and 768 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Changed

- Make `Debug` implementation for `SchemaNode` opaque.

## [0.19.1] - 2024-09-15

### Fixed
Expand Down
17 changes: 1 addition & 16 deletions crates/jsonschema/src/keywords/additional_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
paths::{JSONPointer, JsonPointerNode},
primitive_type::{PrimitiveType, PrimitiveTypesBitMap},
schema_node::SchemaNode,
validator::{format_validators, Validate},
validator::Validate,
};
use serde_json::{Map, Value};

Expand Down Expand Up @@ -59,16 +59,6 @@ impl Validate for AdditionalItemsObjectValidator {
}
}

impl core::fmt::Display for AdditionalItemsObjectValidator {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"additionalItems: {}",
format_validators(self.node.validators())
)
}
}

pub(crate) struct AdditionalItemsBooleanValidator {
items_count: usize,
schema_path: JSONPointer,
Expand Down Expand Up @@ -113,11 +103,6 @@ impl Validate for AdditionalItemsBooleanValidator {
no_error()
}
}
impl core::fmt::Display for AdditionalItemsBooleanValidator {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
"additionalItems: false".fmt(f)
}
}

#[inline]
pub(crate) fn compile<'a>(
Expand Down
54 changes: 1 addition & 53 deletions crates/jsonschema/src/keywords/additional_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
paths::{AbsolutePath, JSONPointer, JsonPointerNode},
properties::*,
schema_node::SchemaNode,
validator::{format_validators, PartialApplication, Validate},
validator::{PartialApplication, Validate},
};
use serde_json::{Map, Value};

Expand Down Expand Up @@ -138,16 +138,6 @@ impl Validate for AdditionalPropertiesValidator {
}
}

impl core::fmt::Display for AdditionalPropertiesValidator {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"additionalProperties: {}",
format_validators(self.node.validators())
)
}
}

/// # Schema example
///
/// ```json
Expand Down Expand Up @@ -196,11 +186,6 @@ impl Validate for AdditionalPropertiesFalseValidator {
no_error()
}
}
impl core::fmt::Display for AdditionalPropertiesFalseValidator {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
"additionalProperties: false".fmt(f)
}
}

/// # Schema example
///
Expand Down Expand Up @@ -445,16 +430,6 @@ impl<M: PropertiesValidatorsMap> Validate for AdditionalPropertiesNotEmptyValida
}
}

impl<M: PropertiesValidatorsMap> core::fmt::Display for AdditionalPropertiesNotEmptyValidator<M> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"additionalProperties: {}",
format_validators(self.node.validators())
)
}
}

/// # Schema example
///
/// ```json
Expand Down Expand Up @@ -595,16 +570,6 @@ impl Validate for AdditionalPropertiesWithPatternsValidator {
}
}

impl core::fmt::Display for AdditionalPropertiesWithPatternsValidator {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"additionalProperties: {}",
format_validators(self.node.validators())
)
}
}

/// # Schema example
///
/// ```json
Expand Down Expand Up @@ -748,12 +713,6 @@ impl Validate for AdditionalPropertiesWithPatternsFalseValidator {
}
}

impl core::fmt::Display for AdditionalPropertiesWithPatternsFalseValidator {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
"additionalProperties: false".fmt(f)
}
}

/// # Schema example
///
/// ```json
Expand Down Expand Up @@ -935,17 +894,6 @@ impl<M: PropertiesValidatorsMap> Validate for AdditionalPropertiesWithPatternsNo
}
}
}
impl<M: PropertiesValidatorsMap> core::fmt::Display
for AdditionalPropertiesWithPatternsNotEmptyValidator<M>
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"additionalProperties: {}",
format_validators(self.node.validators())
)
}
}

/// # Schema example
///
Expand Down
16 changes: 1 addition & 15 deletions crates/jsonschema/src/keywords/all_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
paths::{JSONPointer, JsonPointerNode},
primitive_type::PrimitiveType,
schema_node::SchemaNode,
validator::{format_iter_of_validators, format_validators, PartialApplication, Validate},
validator::{PartialApplication, Validate},
};
use serde_json::{Map, Value};

Expand Down Expand Up @@ -64,15 +64,6 @@ impl Validate for AllOfValidator {
}
}

impl core::fmt::Display for AllOfValidator {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"allOf: [{}]",
format_iter_of_validators(self.schemas.iter().map(SchemaNode::validators))
)
}
}
pub(crate) struct SingleValueAllOfValidator {
node: SchemaNode,
}
Expand Down Expand Up @@ -112,11 +103,6 @@ impl Validate for SingleValueAllOfValidator {
}
}

impl core::fmt::Display for SingleValueAllOfValidator {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "allOf: [{}]", format_validators(self.node.validators()))
}
}
#[inline]
pub(crate) fn compile<'a>(
_: &'a Map<String, Value>,
Expand Down
11 changes: 1 addition & 10 deletions crates/jsonschema/src/keywords/any_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
paths::JsonPointerNode,
primitive_type::PrimitiveType,
schema_node::SchemaNode,
validator::{format_iter_of_validators, PartialApplication, Validate},
validator::{PartialApplication, Validate},
};
use serde_json::{Map, Value};

Expand Down Expand Up @@ -89,15 +89,6 @@ impl Validate for AnyOfValidator {
}
}

impl core::fmt::Display for AnyOfValidator {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"anyOf: [{}]",
format_iter_of_validators(self.schemas.iter().map(SchemaNode::validators))
)
}
}
#[inline]
pub(crate) fn compile<'a>(
_: &'a Map<String, Value>,
Expand Down
6 changes: 0 additions & 6 deletions crates/jsonschema/src/keywords/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,6 @@ impl Validate for FalseValidator {
}
}

impl core::fmt::Display for FalseValidator {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
"false".fmt(f)
}
}

#[cfg(test)]
mod tests {
use crate::tests_util;
Expand Down
49 changes: 0 additions & 49 deletions crates/jsonschema/src/keywords/const_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,6 @@ impl Validate for ConstArrayValidator {
}
}
}
impl core::fmt::Display for ConstArrayValidator {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"const: [{}]",
self.value
.iter()
.map(ToString::to_string)
.collect::<Vec<_>>()
.join(", ")
)
}
}

struct ConstBooleanValidator {
value: bool,
Expand Down Expand Up @@ -101,11 +88,6 @@ impl Validate for ConstBooleanValidator {
}
}
}
impl core::fmt::Display for ConstBooleanValidator {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "const: {}", self.value)
}
}

struct ConstNullValidator {
schema_path: JSONPointer,
Expand Down Expand Up @@ -139,11 +121,6 @@ impl Validate for ConstNullValidator {
instance.is_null()
}
}
impl core::fmt::Display for ConstNullValidator {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "const: {}", Value::Null)
}
}

struct ConstNumberValidator {
// This is saved in order to ensure that the error message is not altered by precision loss
Expand Down Expand Up @@ -192,12 +169,6 @@ impl Validate for ConstNumberValidator {
}
}

impl core::fmt::Display for ConstNumberValidator {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "const: {}", self.original_value)
}
}

pub(crate) struct ConstObjectValidator {
value: Map<String, Value>,
schema_path: JSONPointer,
Expand Down Expand Up @@ -243,20 +214,6 @@ impl Validate for ConstObjectValidator {
}
}

impl core::fmt::Display for ConstObjectValidator {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"const: {{{}}}",
self.value
.iter()
.map(|(key, value)| format!(r#""{}":{}"#, key, value))
.collect::<Vec<_>>()
.join(", ")
)
}
}

pub(crate) struct ConstStringValidator {
value: String,
schema_path: JSONPointer,
Expand Down Expand Up @@ -299,12 +256,6 @@ impl Validate for ConstStringValidator {
}
}

impl core::fmt::Display for ConstStringValidator {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "const: {}", self.value)
}
}

#[inline]
pub(crate) fn compile<'a>(
_: &'a Map<String, Value>,
Expand Down
42 changes: 1 addition & 41 deletions crates/jsonschema/src/keywords/contains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
keywords::CompilationResult,
paths::{JSONPointer, JsonPointerNode},
schema_node::SchemaNode,
validator::{format_validators, PartialApplication, Validate},
validator::{PartialApplication, Validate},
Draft,
};
use serde_json::{Map, Value};
Expand Down Expand Up @@ -96,12 +96,6 @@ impl Validate for ContainsValidator {
}
}

impl core::fmt::Display for ContainsValidator {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "contains: {}", format_validators(self.node.validators()))
}
}

/// `minContains` validation. Used only if there is no `maxContains` present.
///
/// Docs: <https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.6.4.5>
Expand Down Expand Up @@ -189,17 +183,6 @@ impl Validate for MinContainsValidator {
}
}

impl core::fmt::Display for MinContainsValidator {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"minContains: {}, contains: {}",
self.min_contains,
format_validators(self.node.validators())
)
}
}

/// `maxContains` validation. Used only if there is no `minContains` present.
///
/// Docs: <https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.6.4.4>
Expand Down Expand Up @@ -293,17 +276,6 @@ impl Validate for MaxContainsValidator {
}
}

impl core::fmt::Display for MaxContainsValidator {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"maxContains: {}, contains: {}",
self.max_contains,
format_validators(self.node.validators())
)
}
}

/// `maxContains` & `minContains` validation combined.
///
/// Docs:
Expand Down Expand Up @@ -395,18 +367,6 @@ impl Validate for MinMaxContainsValidator {
}
}

impl core::fmt::Display for MinMaxContainsValidator {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"minContains: {}, maxContains: {}, contains: {}",
self.min_contains,
self.max_contains,
format_validators(self.node.validators())
)
}
}

#[inline]
pub(crate) fn compile<'a>(
parent: &'a Map<String, Value>,
Expand Down
Loading

0 comments on commit f9bb59f

Please sign in to comment.