json-structure 0.4.1__tar.gz → 0.5.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {json_structure-0.4.1 → json_structure-0.5.1}/PKG-INFO +1 -1
- {json_structure-0.4.1 → json_structure-0.5.1}/src/json_structure/_version.py +2 -2
- {json_structure-0.4.1 → json_structure-0.5.1}/src/json_structure/instance_validator.py +27 -10
- {json_structure-0.4.1 → json_structure-0.5.1}/.gitignore +0 -0
- {json_structure-0.4.1 → json_structure-0.5.1}/README.md +0 -0
- {json_structure-0.4.1 → json_structure-0.5.1}/pyproject.toml +0 -0
- {json_structure-0.4.1 → json_structure-0.5.1}/src/json_structure/__init__.py +0 -0
- {json_structure-0.4.1 → json_structure-0.5.1}/src/json_structure/error_codes.py +0 -0
- {json_structure-0.4.1 → json_structure-0.5.1}/src/json_structure/json_source_locator.py +0 -0
- {json_structure-0.4.1 → json_structure-0.5.1}/src/json_structure/schema_exporter.py +0 -0
- {json_structure-0.4.1 → json_structure-0.5.1}/src/json_structure/schema_validator.py +0 -0
|
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
|
|
|
28
28
|
commit_id: COMMIT_ID
|
|
29
29
|
__commit_id__: COMMIT_ID
|
|
30
30
|
|
|
31
|
-
__version__ = version = '0.
|
|
32
|
-
__version_tuple__ = version_tuple = (0,
|
|
31
|
+
__version__ = version = '0.5.1'
|
|
32
|
+
__version_tuple__ = version_tuple = (0, 5, 1)
|
|
33
33
|
|
|
34
34
|
__commit_id__ = commit_id = None
|
|
@@ -32,6 +32,7 @@ The code sections are annotated with references to the metaschema constructs.
|
|
|
32
32
|
import sys
|
|
33
33
|
import json
|
|
34
34
|
import re
|
|
35
|
+
import copy
|
|
35
36
|
import datetime
|
|
36
37
|
import uuid
|
|
37
38
|
from urllib.parse import urlparse
|
|
@@ -605,9 +606,12 @@ class JSONStructureInstanceValidator:
|
|
|
605
606
|
# - self.extended is set (CLI override)
|
|
606
607
|
# - validation metaschema (enables both addins by default)
|
|
607
608
|
# - $uses in schema explicitly enables the addin
|
|
609
|
+
# - enabled_extensions includes the addin (detected from root schema)
|
|
608
610
|
enable_conditional = (
|
|
609
611
|
self.extended or
|
|
610
612
|
is_validation or
|
|
613
|
+
("JSONStructureConditionalComposition" in self.enabled_extensions) or
|
|
614
|
+
("JSONStructureValidation" in self.enabled_extensions) or
|
|
611
615
|
(isinstance(schema, dict) and "$uses" in schema and (
|
|
612
616
|
"JSONStructureConditionalComposition" in schema["$uses"] or "JSONStructureValidation" in schema["$uses"]
|
|
613
617
|
))
|
|
@@ -640,14 +644,27 @@ class JSONStructureInstanceValidator:
|
|
|
640
644
|
return self.errors
|
|
641
645
|
|
|
642
646
|
def validate(self, instance, schema=None):
|
|
647
|
+
"""
|
|
648
|
+
Validates an instance against a schema.
|
|
649
|
+
|
|
650
|
+
This method is thread-safe - each call uses isolated state.
|
|
651
|
+
|
|
652
|
+
:param instance: The JSON instance to validate.
|
|
653
|
+
:param schema: Optional schema override (defaults to root_schema).
|
|
654
|
+
:return: List of error messages, empty if valid.
|
|
655
|
+
"""
|
|
643
656
|
if schema is None:
|
|
644
657
|
schema = self.root_schema
|
|
645
658
|
|
|
659
|
+
# Create isolated state for this validation to ensure thread-safety
|
|
660
|
+
# and reentrancy (nested validate() calls don't interfere)
|
|
661
|
+
validator = copy.copy(self)
|
|
662
|
+
validator.errors = []
|
|
663
|
+
|
|
646
664
|
# First, run the core validation (handles $root, types, required, etc.)
|
|
647
665
|
# Pass None for schema to trigger $root handling if this is the root schema
|
|
648
|
-
self.
|
|
649
|
-
|
|
650
|
-
errors = list(self.errors)
|
|
666
|
+
validator.validate_instance(instance, None if schema is self.root_schema else schema, "#")
|
|
667
|
+
errors = list(validator.errors)
|
|
651
668
|
|
|
652
669
|
# Extended: conditional composition
|
|
653
670
|
if self.extended and "JSONStructureConditionalComposition" in self.enabled_extensions:
|
|
@@ -656,24 +673,24 @@ class JSONStructureInstanceValidator:
|
|
|
656
673
|
subschemas = schema[key]
|
|
657
674
|
if key == "allOf":
|
|
658
675
|
for idx, subschema in enumerate(subschemas):
|
|
659
|
-
errors +=
|
|
676
|
+
errors += validator.validate(instance, subschema)
|
|
660
677
|
elif key == "anyOf":
|
|
661
|
-
if not any(not
|
|
678
|
+
if not any(not validator.validate(instance, subschema) for subschema in subschemas):
|
|
662
679
|
errors.append(f"Instance does not match anyOf at {key}")
|
|
663
680
|
elif key == "oneOf":
|
|
664
|
-
matches = sum(1 for subschema in subschemas if not
|
|
681
|
+
matches = sum(1 for subschema in subschemas if not validator.validate(instance, subschema))
|
|
665
682
|
if matches != 1:
|
|
666
683
|
errors.append(f"Instance does not match exactly one subschema in oneOf at {key}")
|
|
667
684
|
if "not" in schema:
|
|
668
|
-
if not
|
|
685
|
+
if not validator.validate(instance, schema["not"]):
|
|
669
686
|
errors.append("Instance must not match 'not' subschema")
|
|
670
687
|
if "if" in schema:
|
|
671
|
-
if not
|
|
688
|
+
if not validator.validate(instance, schema["if"]):
|
|
672
689
|
if "else" in schema:
|
|
673
|
-
errors +=
|
|
690
|
+
errors += validator.validate(instance, schema["else"])
|
|
674
691
|
else:
|
|
675
692
|
if "then" in schema:
|
|
676
|
-
errors +=
|
|
693
|
+
errors += validator.validate(instance, schema["then"])
|
|
677
694
|
# Extended: validation keywords
|
|
678
695
|
if self.extended and "JSONStructureValidation" in self.enabled_extensions:
|
|
679
696
|
t = schema.get("type")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|