json-structure 0.3.0__tar.gz → 0.4.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.3.0 → json_structure-0.4.1}/PKG-INFO +1 -1
- {json_structure-0.3.0 → json_structure-0.4.1}/src/json_structure/_version.py +2 -2
- {json_structure-0.3.0 → json_structure-0.4.1}/src/json_structure/error_codes.py +8 -0
- {json_structure-0.3.0 → json_structure-0.4.1}/src/json_structure/schema_validator.py +49 -3
- {json_structure-0.3.0 → json_structure-0.4.1}/.gitignore +0 -0
- {json_structure-0.3.0 → json_structure-0.4.1}/README.md +0 -0
- {json_structure-0.3.0 → json_structure-0.4.1}/pyproject.toml +0 -0
- {json_structure-0.3.0 → json_structure-0.4.1}/src/json_structure/__init__.py +0 -0
- {json_structure-0.3.0 → json_structure-0.4.1}/src/json_structure/instance_validator.py +0 -0
- {json_structure-0.3.0 → json_structure-0.4.1}/src/json_structure/json_source_locator.py +0 -0
- {json_structure-0.3.0 → json_structure-0.4.1}/src/json_structure/schema_exporter.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.4.1'
|
|
32
|
+
__version_tuple__ = version_tuple = (0, 4, 1)
|
|
33
33
|
|
|
34
34
|
__commit_id__ = commit_id = None
|
|
@@ -114,6 +114,12 @@ SCHEMA_REF_INVALID = "SCHEMA_REF_INVALID"
|
|
|
114
114
|
SCHEMA_REF_CIRCULAR = "SCHEMA_REF_CIRCULAR"
|
|
115
115
|
"""Circular reference detected."""
|
|
116
116
|
|
|
117
|
+
SCHEMA_EXTENDS_CIRCULAR = "SCHEMA_EXTENDS_CIRCULAR"
|
|
118
|
+
"""Circular $extends reference detected."""
|
|
119
|
+
|
|
120
|
+
SCHEMA_EXTENDS_NOT_FOUND = "SCHEMA_EXTENDS_NOT_FOUND"
|
|
121
|
+
"""$extends reference not found."""
|
|
122
|
+
|
|
117
123
|
SCHEMA_REF_NOT_IN_TYPE = "SCHEMA_REF_NOT_IN_TYPE"
|
|
118
124
|
"""$ref is only permitted inside the 'type' attribute."""
|
|
119
125
|
|
|
@@ -509,6 +515,8 @@ ERROR_CODES = {
|
|
|
509
515
|
"SCHEMA_TYPE_OBJECT_MISSING_REF": SCHEMA_TYPE_OBJECT_MISSING_REF,
|
|
510
516
|
"SCHEMA_REF_NOT_FOUND": SCHEMA_REF_NOT_FOUND,
|
|
511
517
|
"SCHEMA_REF_CIRCULAR": SCHEMA_REF_CIRCULAR,
|
|
518
|
+
"SCHEMA_EXTENDS_CIRCULAR": SCHEMA_EXTENDS_CIRCULAR,
|
|
519
|
+
"SCHEMA_EXTENDS_NOT_FOUND": SCHEMA_EXTENDS_NOT_FOUND,
|
|
512
520
|
"SCHEMA_REF_NOT_IN_TYPE": SCHEMA_REF_NOT_IN_TYPE,
|
|
513
521
|
"SCHEMA_MISSING_TYPE": SCHEMA_MISSING_TYPE,
|
|
514
522
|
"SCHEMA_ROOT_MISSING_TYPE": SCHEMA_ROOT_MISSING_TYPE,
|
|
@@ -184,6 +184,7 @@ class JSONStructureSchemaCoreValidator:
|
|
|
184
184
|
self.warnings = []
|
|
185
185
|
self.doc = doc
|
|
186
186
|
self.source_text = source_text
|
|
187
|
+
self._seen_extends = set() # Track visited $extends references for cycle detection
|
|
187
188
|
|
|
188
189
|
# Initialize source locator for location tracking
|
|
189
190
|
if source_text:
|
|
@@ -1156,17 +1157,62 @@ class JSONStructureSchemaCoreValidator:
|
|
|
1156
1157
|
"""
|
|
1157
1158
|
Validates the $extends keyword value.
|
|
1158
1159
|
$extends can be either a single JSON Pointer string or an array of JSON Pointer strings.
|
|
1160
|
+
Detects circular $extends references.
|
|
1159
1161
|
"""
|
|
1162
|
+
refs = []
|
|
1160
1163
|
if isinstance(extends_value, str):
|
|
1161
|
-
|
|
1164
|
+
refs.append((extends_value, path))
|
|
1162
1165
|
elif isinstance(extends_value, list):
|
|
1163
1166
|
for i, item in enumerate(extends_value):
|
|
1164
1167
|
if not isinstance(item, str):
|
|
1165
|
-
self._err(f"'$extends' array element must be a JSON pointer string.", f"{path}
|
|
1168
|
+
self._err(f"'$extends' array element must be a JSON pointer string.", f"{path}[{i}]")
|
|
1166
1169
|
else:
|
|
1167
|
-
|
|
1170
|
+
refs.append((item, f"{path}[{i}]"))
|
|
1168
1171
|
else:
|
|
1169
1172
|
self._err("'$extends' must be a JSON pointer string or an array of JSON pointer strings.", path)
|
|
1173
|
+
return
|
|
1174
|
+
|
|
1175
|
+
for ref, ref_path in refs:
|
|
1176
|
+
if not ref.startswith("#"):
|
|
1177
|
+
continue # External references handled elsewhere
|
|
1178
|
+
|
|
1179
|
+
# Check for circular $extends
|
|
1180
|
+
if ref in self._seen_extends:
|
|
1181
|
+
self._err(f"Circular $extends reference detected: {ref}", ref_path, ErrorCodes.SCHEMA_EXTENDS_CIRCULAR)
|
|
1182
|
+
continue
|
|
1183
|
+
|
|
1184
|
+
self._seen_extends.add(ref)
|
|
1185
|
+
|
|
1186
|
+
# Resolve the reference and check if it has $extends
|
|
1187
|
+
resolved = self._resolve_json_pointer(ref)
|
|
1188
|
+
if resolved is None:
|
|
1189
|
+
self._err(f"$extends reference '{ref}' not found.", ref_path, ErrorCodes.SCHEMA_EXTENDS_NOT_FOUND)
|
|
1190
|
+
elif isinstance(resolved, dict) and "$extends" in resolved:
|
|
1191
|
+
# Recursively validate the extended schema's $extends
|
|
1192
|
+
self._validate_extends_keyword(resolved["$extends"], ref_path)
|
|
1193
|
+
|
|
1194
|
+
self._seen_extends.discard(ref)
|
|
1195
|
+
|
|
1196
|
+
def _resolve_json_pointer(self, pointer):
|
|
1197
|
+
"""
|
|
1198
|
+
Resolves a JSON Pointer within the document.
|
|
1199
|
+
Returns the resolved value or None if not found.
|
|
1200
|
+
"""
|
|
1201
|
+
if not isinstance(pointer, str) or not pointer.startswith("#"):
|
|
1202
|
+
return None
|
|
1203
|
+
if pointer == "#":
|
|
1204
|
+
return self.doc
|
|
1205
|
+
parts = pointer.split("/")
|
|
1206
|
+
cur = self.doc
|
|
1207
|
+
for i, p in enumerate(parts):
|
|
1208
|
+
if i == 0:
|
|
1209
|
+
continue
|
|
1210
|
+
p = p.replace("~1", "/").replace("~0", "~")
|
|
1211
|
+
if isinstance(cur, dict) and p in cur:
|
|
1212
|
+
cur = cur[p]
|
|
1213
|
+
else:
|
|
1214
|
+
return None
|
|
1215
|
+
return cur
|
|
1170
1216
|
|
|
1171
1217
|
def _check_offers(self, offers, path):
|
|
1172
1218
|
"""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|