json-structure 0.1.18__tar.gz → 0.1.20__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: json-structure
3
- Version: 0.1.18
3
+ Version: 0.1.20
4
4
  Summary: Validators for JSON Structure schemas and instances
5
5
  Project-URL: Homepage, https://json-structure.org
6
6
  Project-URL: Documentation, https://github.com/json-structure/sdk
@@ -205,7 +205,7 @@ main_schema = {
205
205
  "type": "object",
206
206
  "properties": {
207
207
  "name": {"type": "string"},
208
- "address": {"$ref": "#/definitions/Imported/Address"}
208
+ "address": {"type": {"$ref": "#/definitions/Imported/Address"}}
209
209
  },
210
210
  "definitions": {
211
211
  "Imported": {
@@ -174,7 +174,7 @@ main_schema = {
174
174
  "type": "object",
175
175
  "properties": {
176
176
  "name": {"type": "string"},
177
- "address": {"$ref": "#/definitions/Imported/Address"}
177
+ "address": {"type": {"$ref": "#/definitions/Imported/Address"}}
178
178
  },
179
179
  "definitions": {
180
180
  "Imported": {
@@ -36,10 +36,10 @@ from json_structure.error_codes import (
36
36
  SCHEMA_REQUIRED_PROPERTY_NOT_DEFINED,
37
37
  SCHEMA_ADDITIONAL_PROPERTIES_INVALID,
38
38
  SCHEMA_ARRAY_MISSING_ITEMS,
39
- SCHEMA_TUPLE_MISSING_PREFIX_ITEMS,
40
- SCHEMA_PREFIX_ITEMS_NOT_ARRAY,
39
+ SCHEMA_TUPLE_MISSING_DEFINITION,
40
+ SCHEMA_TUPLE_ORDER_NOT_ARRAY,
41
41
  SCHEMA_MAP_MISSING_VALUES,
42
- SCHEMA_CHOICE_MISSING_OPTIONS,
42
+ SCHEMA_CHOICE_MISSING_CHOICES,
43
43
  SCHEMA_OPTIONS_NOT_OBJECT,
44
44
  SCHEMA_CHOICES_NOT_OBJECT,
45
45
  SCHEMA_PATTERN_INVALID,
@@ -109,14 +109,15 @@ from json_structure.error_codes import (
109
109
  INSTANCE_MAP_EXPECTED,
110
110
  INSTANCE_MAP_MIN_ENTRIES,
111
111
  INSTANCE_MAP_MAX_ENTRIES,
112
+ INSTANCE_MAP_KEY_INVALID,
112
113
  INSTANCE_TUPLE_EXPECTED,
113
114
  INSTANCE_TUPLE_LENGTH_MISMATCH,
114
115
  INSTANCE_TUPLE_ADDITIONAL_ITEMS,
115
116
  INSTANCE_CHOICE_EXPECTED,
116
- INSTANCE_CHOICE_MISSING_OPTIONS,
117
- INSTANCE_CHOICE_DISCRIMINATOR_MISSING,
118
- INSTANCE_CHOICE_DISCRIMINATOR_NOT_STRING,
119
- INSTANCE_CHOICE_OPTION_UNKNOWN,
117
+ INSTANCE_CHOICE_MISSING_CHOICES,
118
+ INSTANCE_CHOICE_SELECTOR_MISSING,
119
+ INSTANCE_CHOICE_SELECTOR_NOT_STRING,
120
+ INSTANCE_CHOICE_UNKNOWN,
120
121
  INSTANCE_CHOICE_NO_MATCH,
121
122
  INSTANCE_CHOICE_MULTIPLE_MATCHES,
122
123
  INSTANCE_DATE_EXPECTED,
@@ -196,10 +197,10 @@ __all__ = [
196
197
  "SCHEMA_REQUIRED_PROPERTY_NOT_DEFINED",
197
198
  "SCHEMA_ADDITIONAL_PROPERTIES_INVALID",
198
199
  "SCHEMA_ARRAY_MISSING_ITEMS",
199
- "SCHEMA_TUPLE_MISSING_PREFIX_ITEMS",
200
- "SCHEMA_PREFIX_ITEMS_NOT_ARRAY",
200
+ "SCHEMA_TUPLE_MISSING_DEFINITION",
201
+ "SCHEMA_TUPLE_ORDER_NOT_ARRAY",
201
202
  "SCHEMA_MAP_MISSING_VALUES",
202
- "SCHEMA_CHOICE_MISSING_OPTIONS",
203
+ "SCHEMA_CHOICE_MISSING_CHOICES",
203
204
  "SCHEMA_OPTIONS_NOT_OBJECT",
204
205
  "SCHEMA_CHOICES_NOT_OBJECT",
205
206
  "SCHEMA_PATTERN_INVALID",
@@ -269,14 +270,15 @@ __all__ = [
269
270
  "INSTANCE_MAP_EXPECTED",
270
271
  "INSTANCE_MAP_MIN_ENTRIES",
271
272
  "INSTANCE_MAP_MAX_ENTRIES",
273
+ "INSTANCE_MAP_KEY_INVALID",
272
274
  "INSTANCE_TUPLE_EXPECTED",
273
275
  "INSTANCE_TUPLE_LENGTH_MISMATCH",
274
276
  "INSTANCE_TUPLE_ADDITIONAL_ITEMS",
275
277
  "INSTANCE_CHOICE_EXPECTED",
276
- "INSTANCE_CHOICE_MISSING_OPTIONS",
277
- "INSTANCE_CHOICE_DISCRIMINATOR_MISSING",
278
- "INSTANCE_CHOICE_DISCRIMINATOR_NOT_STRING",
279
- "INSTANCE_CHOICE_OPTION_UNKNOWN",
278
+ "INSTANCE_CHOICE_MISSING_CHOICES",
279
+ "INSTANCE_CHOICE_SELECTOR_MISSING",
280
+ "INSTANCE_CHOICE_SELECTOR_NOT_STRING",
281
+ "INSTANCE_CHOICE_UNKNOWN",
280
282
  "INSTANCE_CHOICE_NO_MATCH",
281
283
  "INSTANCE_CHOICE_MULTIPLE_MATCHES",
282
284
  "INSTANCE_DATE_EXPECTED",
@@ -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.1.18'
32
- __version_tuple__ = version_tuple = (0, 1, 18)
31
+ __version__ = version = '0.1.20'
32
+ __version_tuple__ = version_tuple = (0, 1, 20)
33
33
 
34
34
  __commit_id__ = commit_id = None
@@ -114,12 +114,21 @@ SCHEMA_REF_INVALID = "SCHEMA_REF_INVALID"
114
114
  SCHEMA_REF_CIRCULAR = "SCHEMA_REF_CIRCULAR"
115
115
  """Circular reference detected."""
116
116
 
117
+ SCHEMA_REF_NOT_IN_TYPE = "SCHEMA_REF_NOT_IN_TYPE"
118
+ """$ref is only permitted inside the 'type' attribute."""
119
+
117
120
  SCHEMA_MISSING_TYPE = "SCHEMA_MISSING_TYPE"
118
121
  """Schema must have a 'type' keyword."""
119
122
 
120
123
  SCHEMA_ROOT_MISSING_TYPE = "SCHEMA_ROOT_MISSING_TYPE"
121
124
  """Root schema must have 'type', '$root', or other schema-defining keyword."""
122
125
 
126
+ SCHEMA_ROOT_MISSING_ID = "SCHEMA_ROOT_MISSING_ID"
127
+ """Root schema must have an '$id' keyword."""
128
+
129
+ SCHEMA_ROOT_MISSING_NAME = "SCHEMA_ROOT_MISSING_NAME"
130
+ """Root schema with 'type' must have a 'name' property."""
131
+
123
132
  SCHEMA_NAME_INVALID = "SCHEMA_NAME_INVALID"
124
133
  """Name is not a valid identifier."""
125
134
 
@@ -145,19 +154,19 @@ SCHEMA_ADDITIONAL_PROPERTIES_INVALID = "SCHEMA_ADDITIONAL_PROPERTIES_INVALID"
145
154
  """additionalProperties must be a boolean or schema."""
146
155
 
147
156
  SCHEMA_ARRAY_MISSING_ITEMS = "SCHEMA_ARRAY_MISSING_ITEMS"
148
- """Array type requires 'items' or 'contains' schema."""
157
+ """Array type requires 'items' schema."""
149
158
 
150
- SCHEMA_TUPLE_MISSING_PREFIX_ITEMS = "SCHEMA_TUPLE_MISSING_PREFIX_ITEMS"
151
- """Tuple type requires 'prefixItems' or 'tuple'."""
159
+ SCHEMA_TUPLE_MISSING_DEFINITION = "SCHEMA_TUPLE_MISSING_DEFINITION"
160
+ """Tuple type requires 'properties' and 'tuple' keywords."""
152
161
 
153
- SCHEMA_PREFIX_ITEMS_NOT_ARRAY = "SCHEMA_PREFIX_ITEMS_NOT_ARRAY"
154
- """prefixItems must be an array."""
162
+ SCHEMA_TUPLE_ORDER_NOT_ARRAY = "SCHEMA_TUPLE_ORDER_NOT_ARRAY"
163
+ """'tuple' keyword must be an array of property names."""
155
164
 
156
165
  SCHEMA_MAP_MISSING_VALUES = "SCHEMA_MAP_MISSING_VALUES"
157
166
  """Map type requires 'values' schema."""
158
167
 
159
- SCHEMA_CHOICE_MISSING_OPTIONS = "SCHEMA_CHOICE_MISSING_OPTIONS"
160
- """Choice type requires 'options', 'choices', or 'oneOf'."""
168
+ SCHEMA_CHOICE_MISSING_CHOICES = "SCHEMA_CHOICE_MISSING_CHOICES"
169
+ """Choice type requires 'choices' keyword."""
161
170
 
162
171
  SCHEMA_OPTIONS_NOT_OBJECT = "SCHEMA_OPTIONS_NOT_OBJECT"
163
172
  """Options must be an object."""
@@ -216,6 +225,9 @@ SCHEMA_ROOT_CONFLICT = "SCHEMA_ROOT_CONFLICT"
216
225
  SCHEMA_USES_UNKNOWN_EXTENSION = "SCHEMA_USES_UNKNOWN_EXTENSION"
217
226
  """Unknown extension in $uses array."""
218
227
 
228
+ SCHEMA_EXTENSION_KEYWORD_NOT_ENABLED = "SCHEMA_EXTENSION_KEYWORD_NOT_ENABLED"
229
+ """Validation extension keyword is used but validation extensions are not enabled."""
230
+
219
231
  SCHEMA_CONSTRAINT_TYPE_MISMATCH = "SCHEMA_CONSTRAINT_TYPE_MISMATCH"
220
232
  """Constraint is not valid for this type."""
221
233
 
@@ -393,6 +405,9 @@ INSTANCE_MAP_MIN_ENTRIES = "INSTANCE_MAP_MIN_ENTRIES"
393
405
  INSTANCE_MAP_MAX_ENTRIES = "INSTANCE_MAP_MAX_ENTRIES"
394
406
  """Map has more entries than maximum."""
395
407
 
408
+ INSTANCE_MAP_KEY_INVALID = "INSTANCE_MAP_KEY_INVALID"
409
+ """Map key does not match keyNames or patternKeys constraint."""
410
+
396
411
  INSTANCE_TUPLE_EXPECTED = "INSTANCE_TUPLE_EXPECTED"
397
412
  """Value must be an array (tuple)."""
398
413
 
@@ -405,17 +420,17 @@ INSTANCE_TUPLE_ADDITIONAL_ITEMS = "INSTANCE_TUPLE_ADDITIONAL_ITEMS"
405
420
  INSTANCE_CHOICE_EXPECTED = "INSTANCE_CHOICE_EXPECTED"
406
421
  """Value must be an object (choice)."""
407
422
 
408
- INSTANCE_CHOICE_MISSING_OPTIONS = "INSTANCE_CHOICE_MISSING_OPTIONS"
409
- """Choice schema is missing options."""
423
+ INSTANCE_CHOICE_MISSING_CHOICES = "INSTANCE_CHOICE_MISSING_CHOICES"
424
+ """Choice schema is missing choices."""
410
425
 
411
- INSTANCE_CHOICE_DISCRIMINATOR_MISSING = "INSTANCE_CHOICE_DISCRIMINATOR_MISSING"
412
- """Choice discriminator property is missing."""
426
+ INSTANCE_CHOICE_SELECTOR_MISSING = "INSTANCE_CHOICE_SELECTOR_MISSING"
427
+ """Choice selector property is missing."""
413
428
 
414
- INSTANCE_CHOICE_DISCRIMINATOR_NOT_STRING = "INSTANCE_CHOICE_DISCRIMINATOR_NOT_STRING"
415
- """Discriminator value must be a string."""
429
+ INSTANCE_CHOICE_SELECTOR_NOT_STRING = "INSTANCE_CHOICE_SELECTOR_NOT_STRING"
430
+ """Selector value must be a string."""
416
431
 
417
- INSTANCE_CHOICE_OPTION_UNKNOWN = "INSTANCE_CHOICE_OPTION_UNKNOWN"
418
- """Unknown choice option."""
432
+ INSTANCE_CHOICE_UNKNOWN = "INSTANCE_CHOICE_UNKNOWN"
433
+ """Unknown choice."""
419
434
 
420
435
  INSTANCE_CHOICE_NO_MATCH = "INSTANCE_CHOICE_NO_MATCH"
421
436
  """Value does not match any choice option."""
@@ -497,8 +512,11 @@ ERROR_CODES = {
497
512
  "SCHEMA_TYPE_OBJECT_MISSING_REF": SCHEMA_TYPE_OBJECT_MISSING_REF,
498
513
  "SCHEMA_REF_NOT_FOUND": SCHEMA_REF_NOT_FOUND,
499
514
  "SCHEMA_REF_CIRCULAR": SCHEMA_REF_CIRCULAR,
515
+ "SCHEMA_REF_NOT_IN_TYPE": SCHEMA_REF_NOT_IN_TYPE,
500
516
  "SCHEMA_MISSING_TYPE": SCHEMA_MISSING_TYPE,
501
517
  "SCHEMA_ROOT_MISSING_TYPE": SCHEMA_ROOT_MISSING_TYPE,
518
+ "SCHEMA_ROOT_MISSING_ID": SCHEMA_ROOT_MISSING_ID,
519
+ "SCHEMA_ROOT_MISSING_NAME": SCHEMA_ROOT_MISSING_NAME,
502
520
  "SCHEMA_NAME_INVALID": SCHEMA_NAME_INVALID,
503
521
  "SCHEMA_CONSTRAINT_INVALID_FOR_TYPE": SCHEMA_CONSTRAINT_INVALID_FOR_TYPE,
504
522
  "SCHEMA_MIN_GREATER_THAN_MAX": SCHEMA_MIN_GREATER_THAN_MAX,
@@ -508,10 +526,10 @@ ERROR_CODES = {
508
526
  "SCHEMA_REQUIRED_PROPERTY_NOT_DEFINED": SCHEMA_REQUIRED_PROPERTY_NOT_DEFINED,
509
527
  "SCHEMA_ADDITIONAL_PROPERTIES_INVALID": SCHEMA_ADDITIONAL_PROPERTIES_INVALID,
510
528
  "SCHEMA_ARRAY_MISSING_ITEMS": SCHEMA_ARRAY_MISSING_ITEMS,
511
- "SCHEMA_TUPLE_MISSING_PREFIX_ITEMS": SCHEMA_TUPLE_MISSING_PREFIX_ITEMS,
512
- "SCHEMA_PREFIX_ITEMS_NOT_ARRAY": SCHEMA_PREFIX_ITEMS_NOT_ARRAY,
529
+ "SCHEMA_TUPLE_MISSING_DEFINITION": SCHEMA_TUPLE_MISSING_DEFINITION,
530
+ "SCHEMA_TUPLE_ORDER_NOT_ARRAY": SCHEMA_TUPLE_ORDER_NOT_ARRAY,
513
531
  "SCHEMA_MAP_MISSING_VALUES": SCHEMA_MAP_MISSING_VALUES,
514
- "SCHEMA_CHOICE_MISSING_OPTIONS": SCHEMA_CHOICE_MISSING_OPTIONS,
532
+ "SCHEMA_CHOICE_MISSING_CHOICES": SCHEMA_CHOICE_MISSING_CHOICES,
515
533
  "SCHEMA_OPTIONS_NOT_OBJECT": SCHEMA_OPTIONS_NOT_OBJECT,
516
534
  "SCHEMA_CHOICES_NOT_OBJECT": SCHEMA_CHOICES_NOT_OBJECT,
517
535
  "SCHEMA_PATTERN_INVALID": SCHEMA_PATTERN_INVALID,
@@ -582,14 +600,15 @@ ERROR_CODES = {
582
600
  "INSTANCE_MAP_EXPECTED": INSTANCE_MAP_EXPECTED,
583
601
  "INSTANCE_MAP_MIN_ENTRIES": INSTANCE_MAP_MIN_ENTRIES,
584
602
  "INSTANCE_MAP_MAX_ENTRIES": INSTANCE_MAP_MAX_ENTRIES,
603
+ "INSTANCE_MAP_KEY_INVALID": INSTANCE_MAP_KEY_INVALID,
585
604
  "INSTANCE_TUPLE_EXPECTED": INSTANCE_TUPLE_EXPECTED,
586
605
  "INSTANCE_TUPLE_LENGTH_MISMATCH": INSTANCE_TUPLE_LENGTH_MISMATCH,
587
606
  "INSTANCE_TUPLE_ADDITIONAL_ITEMS": INSTANCE_TUPLE_ADDITIONAL_ITEMS,
588
607
  "INSTANCE_CHOICE_EXPECTED": INSTANCE_CHOICE_EXPECTED,
589
- "INSTANCE_CHOICE_MISSING_OPTIONS": INSTANCE_CHOICE_MISSING_OPTIONS,
590
- "INSTANCE_CHOICE_DISCRIMINATOR_MISSING": INSTANCE_CHOICE_DISCRIMINATOR_MISSING,
591
- "INSTANCE_CHOICE_DISCRIMINATOR_NOT_STRING": INSTANCE_CHOICE_DISCRIMINATOR_NOT_STRING,
592
- "INSTANCE_CHOICE_OPTION_UNKNOWN": INSTANCE_CHOICE_OPTION_UNKNOWN,
608
+ "INSTANCE_CHOICE_MISSING_CHOICES": INSTANCE_CHOICE_MISSING_CHOICES,
609
+ "INSTANCE_CHOICE_SELECTOR_MISSING": INSTANCE_CHOICE_SELECTOR_MISSING,
610
+ "INSTANCE_CHOICE_SELECTOR_NOT_STRING": INSTANCE_CHOICE_SELECTOR_NOT_STRING,
611
+ "INSTANCE_CHOICE_UNKNOWN": INSTANCE_CHOICE_UNKNOWN,
593
612
  "INSTANCE_CHOICE_NO_MATCH": INSTANCE_CHOICE_NO_MATCH,
594
613
  "INSTANCE_CHOICE_MULTIPLE_MATCHES": INSTANCE_CHOICE_MULTIPLE_MATCHES,
595
614
  "INSTANCE_DATE_EXPECTED": INSTANCE_DATE_EXPECTED,
@@ -58,7 +58,7 @@ class JSONStructureInstanceValidator:
58
58
  """
59
59
  ABSOLUTE_URI_REGEX = re.compile(r'^[a-zA-Z][a-zA-Z0-9+\-.]*://')
60
60
 
61
- def __init__(self, root_schema, allow_import=False, import_map=None, extended=False, external_schemas=None):
61
+ def __init__(self, root_schema, allow_import=False, import_map=None, extended=False, external_schemas=None, max_validation_depth=64):
62
62
  """
63
63
  Initializes the validator.
64
64
  :param root_schema: The JSON Structure (as dict).
@@ -67,12 +67,14 @@ class JSONStructureInstanceValidator:
67
67
  :param extended: Enable extended validation features.
68
68
  :param external_schemas: List of schema dicts to use for resolving imports by $id.
69
69
  Each schema should have a '$id' field matching the import URI.
70
+ :param max_validation_depth: Maximum depth for validation recursion. Default is 64.
70
71
  """
71
72
  self.root_schema = root_schema
72
73
  self.errors = []
73
74
  self.allow_import = allow_import
74
75
  self.import_map = import_map if import_map is not None else {}
75
76
  self.extended = extended
77
+ self.max_validation_depth = max_validation_depth
76
78
  self.enabled_extensions = set()
77
79
  # Build lookup for external schemas by $id
78
80
  self.external_schemas = {}
@@ -823,17 +825,34 @@ class JSONStructureInstanceValidator:
823
825
  self.errors.append(f"Value at {path} is greater than maximum {schema['maximum']}")
824
826
  except Exception:
825
827
  self.errors.append(f"Cannot compare value at {path} with maximum constraint")
826
- if schema.get("exclusiveMinimum") is True:
828
+ if "exclusiveMinimum" in schema:
827
829
  try:
828
- if instance <= schema.get("minimum", float("-inf")):
829
- self.errors.append(
830
- f"Value at {path} is not greater than exclusive minimum {schema.get('minimum')}")
830
+ excl_min = schema["exclusiveMinimum"]
831
+ if isinstance(excl_min, bool):
832
+ # Draft-04 style: exclusiveMinimum is a boolean modifier for minimum
833
+ if excl_min is True and instance <= schema.get("minimum", float("-inf")):
834
+ self.errors.append(
835
+ f"Value at {path} is not greater than exclusive minimum {schema.get('minimum')}")
836
+ else:
837
+ # Draft-06+ style: exclusiveMinimum is a numeric value
838
+ if instance <= excl_min:
839
+ self.errors.append(
840
+ f"Value at {path} is not greater than exclusive minimum {excl_min}")
831
841
  except Exception:
832
842
  self.errors.append(f"Cannot evaluate exclusiveMinimum constraint at {path}")
833
- if schema.get("exclusiveMaximum") is True:
843
+ if "exclusiveMaximum" in schema:
834
844
  try:
835
- if instance >= schema.get("maximum", float("inf")): self.errors.append(
836
- f"Value at {path} is not less than exclusive maximum {schema.get('maximum')}")
845
+ excl_max = schema["exclusiveMaximum"]
846
+ if isinstance(excl_max, bool):
847
+ # Draft-04 style: exclusiveMaximum is a boolean modifier for maximum
848
+ if excl_max is True and instance >= schema.get("maximum", float("inf")):
849
+ self.errors.append(
850
+ f"Value at {path} is not less than exclusive maximum {schema.get('maximum')}")
851
+ else:
852
+ # Draft-06+ style: exclusiveMaximum is a numeric value
853
+ if instance >= excl_max:
854
+ self.errors.append(
855
+ f"Value at {path} is not less than exclusive maximum {excl_max}")
837
856
  except Exception:
838
857
  self.errors.append(f"Cannot evaluate exclusiveMaximum constraint at {path}")
839
858
  if "multipleOf" in schema:
@@ -911,7 +930,7 @@ class JSONStructureInstanceValidator:
911
930
  contains_schema = schema["contains"]
912
931
  matches = []
913
932
  for i, item in enumerate(instance):
914
- temp_validator = JSONStructureInstanceValidator(contains_schema, import_map=self.import_map, allow_import=self.allow_import, external_schemas=list(self.external_schemas.values()) if self.external_schemas else None)
933
+ temp_validator = JSONStructureInstanceValidator(contains_schema, import_map=self.import_map, allow_import=self.allow_import, extended=self.extended, external_schemas=list(self.external_schemas.values()) if self.external_schemas else None)
915
934
  item_errors = temp_validator.validate_instance(item)
916
935
  if not item_errors:
917
936
  matches.append(i)
@@ -90,7 +90,6 @@ class FieldConstraints:
90
90
  MIN_ITEMS = "min_items"
91
91
  MAX_ITEMS = "max_items"
92
92
  UNIQUE_ITEMS = "unique_items"
93
- DEPRECATED = "deprecated"
94
93
  TITLE = "title"
95
94
  DESCRIPTION = "description"
96
95
  EXAMPLES = "examples"
@@ -108,7 +107,6 @@ def field_constraints(
108
107
  min_items: Optional[int] = None,
109
108
  max_items: Optional[int] = None,
110
109
  unique_items: Optional[bool] = None,
111
- deprecated: Optional[bool] = None,
112
110
  title: Optional[str] = None,
113
111
  description: Optional[str] = None,
114
112
  examples: Optional[List[Any]] = None,
@@ -134,7 +132,6 @@ def field_constraints(
134
132
  min_items: Minimum array length.
135
133
  max_items: Maximum array length.
136
134
  unique_items: Whether array items must be unique.
137
- deprecated: Whether the field is deprecated.
138
135
  title: Title for the field schema.
139
136
  description: Description for the field schema.
140
137
  examples: Example values for the field.
@@ -166,8 +163,6 @@ def field_constraints(
166
163
  result[FieldConstraints.MAX_ITEMS] = max_items
167
164
  if unique_items is not None:
168
165
  result[FieldConstraints.UNIQUE_ITEMS] = unique_items
169
- if deprecated is not None:
170
- result[FieldConstraints.DEPRECATED] = deprecated
171
166
  if title is not None:
172
167
  result[FieldConstraints.TITLE] = title
173
168
  if description is not None:
@@ -227,9 +222,9 @@ class JsonStructureSchemaExporter:
227
222
 
228
223
  schema = self._generate_schema(type_, "", None)
229
224
 
230
- # Add $defs if there are any
225
+ # Add definitions if there are any
231
226
  if self._definitions:
232
- schema["$defs"] = self._definitions
227
+ schema["definitions"] = self._definitions
233
228
 
234
229
  return schema
235
230
 
@@ -262,10 +257,11 @@ class JsonStructureSchemaExporter:
262
257
  origin = get_origin(type_)
263
258
  args = get_args(type_)
264
259
 
265
- # Check for recursion
260
+ # Check for recursion - per JSON Structure spec, $ref must be inside type
266
261
  if self._is_complex_type(type_) and type_ in self._visited_types:
267
262
  type_name = self._get_type_name(type_)
268
- return {"$ref": f"#/$defs/{type_name}"}
263
+ schema["type"] = {"$ref": f"#/definitions/{type_name}"}
264
+ return schema
269
265
 
270
266
  # Map type to JSON Structure type
271
267
  structure_type = self._get_json_structure_type(type_)
@@ -305,13 +301,17 @@ class JsonStructureSchemaExporter:
305
301
  if len(args) == 2 and args[1] is ...:
306
302
  schema["items"] = self._generate_schema(args[0], path + "/items", None)
307
303
  else:
308
- # Fixed length tuple
309
- prefix_items = []
304
+ # Fixed length tuple - JSON Structure uses properties + tuple keyword
305
+ properties = {}
306
+ tuple_order = []
310
307
  for i, arg in enumerate(args):
311
- prefix_items.append(
312
- self._generate_schema(arg, f"{path}/prefixItems/{i}", None)
308
+ prop_name = f"item{i}"
309
+ properties[prop_name] = self._generate_schema(
310
+ arg, f"{path}/properties/{prop_name}", None
313
311
  )
314
- schema["prefixItems"] = prefix_items
312
+ tuple_order.append(prop_name)
313
+ schema["properties"] = properties
314
+ schema["tuple"] = tuple_order
315
315
  return self._apply_transform(schema, type_, field, path)
316
316
 
317
317
  # Handle Union types (choice)
@@ -319,13 +319,13 @@ class JsonStructureSchemaExporter:
319
319
  non_none_args = [a for a in args if a is not type(None)]
320
320
  if len(non_none_args) > 1:
321
321
  schema["type"] = "choice"
322
- options = {}
322
+ choices = {}
323
323
  for i, arg in enumerate(non_none_args):
324
- option_name = self._get_type_name(arg)
325
- options[option_name] = self._generate_schema(
326
- arg, f"{path}/options/{option_name}", None
324
+ choice_name = self._get_type_name(arg)
325
+ choices[choice_name] = self._generate_schema(
326
+ arg, f"{path}/choices/{choice_name}", None
327
327
  )
328
- schema["options"] = options
328
+ schema["choices"] = choices
329
329
  return self._apply_transform(schema, type_, field, path)
330
330
 
331
331
  # Handle dataclasses (objects)
@@ -444,8 +444,6 @@ class JsonStructureSchemaExporter:
444
444
  schema["uniqueItems"] = metadata[FieldConstraints.UNIQUE_ITEMS]
445
445
 
446
446
  # Metadata
447
- if FieldConstraints.DEPRECATED in metadata:
448
- schema["deprecated"] = metadata[FieldConstraints.DEPRECATED]
449
447
  if FieldConstraints.EXAMPLES in metadata:
450
448
  schema["examples"] = metadata[FieldConstraints.EXAMPLES]
451
449
 
@@ -62,11 +62,11 @@ class JSONStructureSchemaCoreValidator:
62
62
 
63
63
  # Extended keywords for validation
64
64
  NUMERIC_VALIDATION_KEYWORDS = {"minimum", "maximum", "exclusiveMinimum", "exclusiveMaximum", "multipleOf"}
65
- STRING_VALIDATION_KEYWORDS = {"minLength", "maxLength", "pattern", "format"}
65
+ STRING_VALIDATION_KEYWORDS = {"minLength", "maxLength", "pattern", "format", "contentEncoding", "contentMediaType"}
66
66
  ARRAY_VALIDATION_KEYWORDS = {"minItems", "maxItems", "uniqueItems", "contains", "minContains", "maxContains"}
67
67
  OBJECT_VALIDATION_KEYWORDS = {"minProperties", "maxProperties", "minEntries", "maxEntries",
68
68
  "dependentRequired", "patternProperties", "patternKeys",
69
- "propertyNames", "keyNames", "has"}
69
+ "propertyNames", "keyNames", "has", "default"}
70
70
 
71
71
  # Valid format values
72
72
  VALID_FORMATS = {
@@ -80,7 +80,7 @@ class JSONStructureSchemaCoreValidator:
80
80
  "JSONStructureConditionalComposition", "JSONStructureValidation"
81
81
  }
82
82
 
83
- def __init__(self, allow_dollar=False, allow_import=False, import_map=None, extended=False, external_schemas=None):
83
+ def __init__(self, allow_dollar=False, allow_import=False, import_map=None, extended=False, external_schemas=None, warn_on_unused_extension_keywords=True, max_validation_depth=64):
84
84
  """
85
85
  Initializes a validator instance.
86
86
  :param allow_dollar: Boolean flag to allow '$' in property names.
@@ -89,14 +89,19 @@ class JSONStructureSchemaCoreValidator:
89
89
  :param extended: Boolean flag to enable extended validation features.
90
90
  :param external_schemas: List of schema dicts to use for resolving imports by $id.
91
91
  Each schema should have a '$id' field matching the import URI.
92
+ :param warn_on_unused_extension_keywords: Boolean flag to emit warnings for extension keywords without $uses.
93
+ :param max_validation_depth: Maximum depth for validation recursion. Default is 64.
92
94
  """
93
95
  self.errors: List[ValidationError] = []
96
+ self.warnings: List[ValidationError] = []
94
97
  self.doc = None
95
98
  self.source_text = None
96
99
  self.source_locator: Optional[JsonSourceLocator] = None
97
100
  self.allow_import = allow_import
98
101
  self.import_map = import_map if import_map is not None else {}
99
102
  self.extended = extended
103
+ self.warn_on_unused_extension_keywords = warn_on_unused_extension_keywords
104
+ self.max_validation_depth = max_validation_depth
100
105
  self.enabled_extensions = set()
101
106
  # Build lookup for external schemas by $id
102
107
  self.external_schemas = {}
@@ -176,6 +181,7 @@ class JSONStructureSchemaCoreValidator:
176
181
  :return: List of ValidationError objects, empty if valid.
177
182
  """
178
183
  self.errors = []
184
+ self.warnings = []
179
185
  self.doc = doc
180
186
  self.source_text = source_text
181
187
 
@@ -220,6 +226,13 @@ class JSONStructureSchemaCoreValidator:
220
226
  # Check for composition keywords at root if no type is present
221
227
  if self.extended and "type" not in doc:
222
228
  self._check_composition_keywords(doc, "#")
229
+
230
+ # Check that document has either 'type', '$root', or composition keywords at root
231
+ has_type = "type" in doc
232
+ has_root = "$root" in doc
233
+ has_composition = self.extended and self._has_composition_keywords(doc)
234
+ if not has_type and not has_root and not has_composition:
235
+ self._err("Document must have 'type', '$root', or composition keywords at root.", "#", ErrorCodes.SCHEMA_ROOT_MISSING_TYPE)
223
236
 
224
237
  return self.errors
225
238
 
@@ -259,12 +272,14 @@ class JSONStructureSchemaCoreValidator:
259
272
 
260
273
  def _check_required_top_level_keywords(self, obj, location):
261
274
  """
262
- Ensures $schema and $id are present at the root level.
275
+ Ensures $id is present at root level, and name is present when type is at root.
263
276
  """
264
- if "$schema" not in obj:
265
- self._err("Missing required '$schema' keyword at root.", location)
266
277
  if "$id" not in obj:
267
- self._err("Missing required '$id' keyword at root.", location)
278
+ self._err("Missing required '$id' keyword at root.", location, ErrorCodes.SCHEMA_ROOT_MISSING_ID)
279
+
280
+ # Root schema with 'type' must have 'name'
281
+ if "type" in obj and "name" not in obj:
282
+ self._err("Root schema with 'type' must have a 'name' property.", location, ErrorCodes.SCHEMA_ROOT_MISSING_NAME)
268
283
 
269
284
  def _check_is_absolute_uri(self, value, keyword_name, location):
270
285
  """
@@ -456,7 +471,8 @@ class JSONStructureSchemaCoreValidator:
456
471
  subpath = f"{path}/{k}"
457
472
  if isinstance(v, dict) and ("type" in v or "$ref" in v or
458
473
  (self.extended and self._has_composition_keywords(v))):
459
- self._validate_schema(v, is_root=False, path=subpath, name_in_namespace=k)
474
+ # Pass the definition path for self-reference detection
475
+ self._validate_schema(v, is_root=False, path=subpath, name_in_namespace=k, definition_path=subpath)
460
476
  else:
461
477
  if not isinstance(v, dict):
462
478
  self._err(f"{subpath} is not a valid namespace or schema object.", subpath)
@@ -469,9 +485,16 @@ class JSONStructureSchemaCoreValidator:
469
485
  """
470
486
  return any(key in obj for key in self.COMPOSITION_KEYWORDS)
471
487
 
472
- def _validate_schema(self, schema_obj, is_root=False, path="", name_in_namespace=None):
488
+ def _validate_schema(self, schema_obj, is_root=False, path="", name_in_namespace=None, definition_path=None):
473
489
  """
474
490
  Validates an individual schema object.
491
+
492
+ Args:
493
+ schema_obj: The schema object to validate
494
+ is_root: Whether this is the root schema
495
+ path: The JSON pointer path to this schema
496
+ name_in_namespace: The name of this definition in the namespace (if any)
497
+ definition_path: The definition path for self-reference detection (e.g., "#/definitions/MyType")
475
498
  """
476
499
  if not isinstance(schema_obj, dict):
477
500
  self._err(f"{path} must be an object to be a schema.", path)
@@ -495,24 +518,24 @@ class JSONStructureSchemaCoreValidator:
495
518
  self._err(f"'abstract' keyword must be boolean.", path + "/abstract")
496
519
  if "$extends" in schema_obj:
497
520
  self._validate_extends_keyword(schema_obj["$extends"], path + "/$extends")
521
+
522
+ # Check for bare $ref - this is NOT permitted per spec Section 3.4.1
523
+ # $ref is ONLY permitted inside the 'type' attribute value
524
+ if "$ref" in schema_obj:
525
+ self._err(
526
+ "'$ref' is only permitted inside the 'type' attribute. "
527
+ "Use { \"type\": { \"$ref\": \"...\" } } instead of { \"$ref\": \"...\" }",
528
+ path + "/$ref",
529
+ ErrorCodes.SCHEMA_REF_NOT_IN_TYPE
530
+ )
531
+ return
498
532
 
499
533
  # Check if this is a non-schema with composition keywords
500
- has_type_or_ref = "type" in schema_obj or "$ref" in schema_obj
534
+ has_type = "type" in schema_obj
501
535
  has_composition = self.extended and self._has_composition_keywords(schema_obj)
502
536
 
503
- if not has_type_or_ref and not has_composition:
504
- self._err("Missing required 'type' or '$ref' in schema object.", path)
505
- return
506
-
507
- if "type" in schema_obj and "$ref" in schema_obj:
508
- self._err("Cannot have both 'type' and '$ref'.", path)
509
- return
510
-
511
- if "$ref" in schema_obj:
512
- if not isinstance(schema_obj["$ref"], str):
513
- self._err("'$ref' must be a string.", path + "/$ref")
514
- else:
515
- self._check_json_pointer(schema_obj["$ref"], self.doc, path + "/$ref")
537
+ if not has_type and not has_composition:
538
+ self._err("Missing required 'type' in schema object.", path)
516
539
  return
517
540
 
518
541
  if "type" in schema_obj:
@@ -530,7 +553,14 @@ class JSONStructureSchemaCoreValidator:
530
553
  else:
531
554
  self._err("Type dict must have '$ref' or be a valid schema object.", path + "/type")
532
555
  else:
533
- self._check_json_pointer(tval["$ref"], self.doc, path + "/type/$ref")
556
+ ref = tval["$ref"]
557
+ self._check_json_pointer(ref, self.doc, path + "/type/$ref")
558
+ # Check for circular self-reference: type: { $ref: ... } pointing to the same definition
559
+ # e.g., "recursive": { "type": { "$ref": "#/definitions/recursive" } }
560
+ if len(schema_obj) == 1 and len(tval) == 1 and definition_path is not None:
561
+ if ref == definition_path:
562
+ self._err(f"Circular reference detected: {ref}", path + "/type/$ref", ErrorCodes.SCHEMA_REF_CIRCULAR)
563
+ return
534
564
  else:
535
565
  if not isinstance(tval, str):
536
566
  self._err("Type must be a string, list, or object with $ref.", path + "/type")
@@ -561,16 +591,45 @@ class JSONStructureSchemaCoreValidator:
561
591
  self._check_extended_validation_keywords(schema_obj, path)
562
592
 
563
593
  if "required" in schema_obj:
594
+ req_val = schema_obj["required"]
564
595
  if "type" in schema_obj and isinstance(schema_obj["type"], str):
565
596
  if schema_obj["type"] != "object":
566
597
  self._err("'required' can only appear in an object schema.", path + "/required")
598
+ if not isinstance(req_val, list):
599
+ self._err("'required' must be an array.", path + "/required")
600
+ else:
601
+ # Check each required property is a string
602
+ for idx, item in enumerate(req_val):
603
+ if not isinstance(item, str):
604
+ self._err(f"'required[{idx}]' must be a string.", f"{path}/required[{idx}]")
605
+ # Check that required properties exist in properties
606
+ if "properties" in schema_obj and isinstance(schema_obj["properties"], dict):
607
+ for idx, item in enumerate(req_val):
608
+ if isinstance(item, str) and item not in schema_obj["properties"]:
609
+ self._err(f"'required' references property '{item}' that is not in 'properties'.", f"{path}/required[{idx}]")
567
610
  if "additionalProperties" in schema_obj:
568
611
  if "type" in schema_obj and isinstance(schema_obj["type"], str):
569
612
  if schema_obj["type"] != "object":
570
613
  self._err("'additionalProperties' can only appear in an object schema.", path + "/additionalProperties")
571
614
  if "enum" in schema_obj:
572
- if not isinstance(schema_obj["enum"], list):
573
- self._err("Enum must be an array.", path + "/enum")
615
+ enum_val = schema_obj["enum"]
616
+ if not isinstance(enum_val, list):
617
+ self._err("'enum' must be an array.", path + "/enum")
618
+ else:
619
+ if len(enum_val) == 0:
620
+ self._err("'enum' array cannot be empty.", path + "/enum")
621
+ # Check for duplicates (using JSON serialization for comparison)
622
+ seen = []
623
+ for idx, item in enumerate(enum_val):
624
+ # Convert to JSON string for comparison (handles objects/arrays)
625
+ import json
626
+ try:
627
+ item_str = json.dumps(item, sort_keys=True)
628
+ if item_str in seen:
629
+ self._err(f"'enum' contains duplicate value at index {idx}.", f"{path}/enum[{idx}]")
630
+ seen.append(item_str)
631
+ except (TypeError, ValueError):
632
+ pass # Can't serialize, skip duplicate check for this item
574
633
  if "type" in schema_obj and isinstance(schema_obj["type"], str):
575
634
  if schema_obj["type"] in self.COMPOUND_TYPES:
576
635
  self._err("'enum' cannot be used with compound types.", path + "/enum")
@@ -628,45 +687,60 @@ class JSONStructureSchemaCoreValidator:
628
687
  def _check_extended_validation_keywords(self, obj, path):
629
688
  """
630
689
  Check extended validation keywords based on type.
690
+ Always validates keyword values (e.g., minLength must be non-negative).
691
+ Emits warnings when validation extension is not enabled.
692
+ Also checks for constraint type mismatches (e.g., minLength on numeric type).
631
693
  """
632
- if "JSONStructureValidation" not in self.enabled_extensions:
633
- # Check if any validation keywords are present without the extension
634
- all_validation_keywords = (self.NUMERIC_VALIDATION_KEYWORDS |
635
- self.STRING_VALIDATION_KEYWORDS |
636
- self.ARRAY_VALIDATION_KEYWORDS |
637
- self.OBJECT_VALIDATION_KEYWORDS |
638
- {"default"})
639
- for key in all_validation_keywords:
640
- if key in obj:
641
- self._err(f"Validation keyword '{key}' requires JSONStructureValidation extension.", f"{path}/{key}")
642
- return
643
-
694
+ validation_enabled = "JSONStructureValidation" in self.enabled_extensions
695
+
644
696
  tval = obj.get("type")
645
697
  if isinstance(tval, str):
646
- # Check numeric validation keywords
647
- if tval in ["number", "integer", "float", "double", "decimal",
648
- "int8", "uint8", "int16", "uint16", "int32", "uint32",
649
- "int64", "uint64", "int128", "uint128", "float8"]:
650
- self._check_numeric_validation(obj, path, tval)
651
-
652
- # Check string validation keywords
698
+ # Define type categories
699
+ numeric_types = ["number", "integer", "float", "double", "decimal",
700
+ "int8", "uint8", "int16", "uint16", "int32", "uint32",
701
+ "int64", "uint64", "int128", "uint128", "float8"]
702
+ array_types = ["array", "set", "tuple"]
703
+ object_types = ["object", "map"]
704
+
705
+ # Check for constraint type mismatches
706
+ string_constraints = ["minLength", "maxLength", "pattern"]
707
+ numeric_constraints = ["minimum", "maximum", "exclusiveMinimum", "exclusiveMaximum", "multipleOf"]
708
+ array_constraints = ["minItems", "maxItems", "uniqueItems", "contains", "minContains", "maxContains"]
709
+
710
+ # Check string constraints on non-string types
711
+ if tval != "string":
712
+ for key in string_constraints:
713
+ if key in obj:
714
+ self._err(f"'{key}' constraint is only valid for string type, not '{tval}'.", f"{path}/{key}")
715
+
716
+ # Check numeric constraints on non-numeric types
717
+ if tval not in numeric_types:
718
+ for key in numeric_constraints:
719
+ if key in obj:
720
+ self._err(f"'{key}' constraint is only valid for numeric types, not '{tval}'.", f"{path}/{key}")
721
+
722
+ # Check array constraints on non-array types
723
+ if tval not in array_types:
724
+ for key in array_constraints:
725
+ if key in obj:
726
+ self._err(f"'{key}' constraint is only valid for array/set/tuple types, not '{tval}'.", f"{path}/{key}")
727
+
728
+ # Now validate the constraint values for matching types
729
+ if tval in numeric_types:
730
+ self._check_numeric_validation(obj, path, tval, validation_enabled)
653
731
  elif tval == "string":
654
- self._check_string_validation(obj, path)
655
-
656
- # Check array/set validation keywords
732
+ self._check_string_validation(obj, path, validation_enabled)
657
733
  elif tval in ["array", "set"]:
658
- self._check_array_validation(obj, path, tval)
659
-
660
- # Check object/map validation keywords
661
- elif tval in ["object", "map"]:
662
- self._check_object_validation(obj, path, tval)
734
+ self._check_array_validation(obj, path, tval, validation_enabled)
735
+ elif tval in object_types:
736
+ self._check_object_validation(obj, path, tval, validation_enabled)
663
737
 
664
738
  # Check default keyword
665
739
  if "default" in obj:
666
- # Default can be any value, just ensure it's present
667
- pass
740
+ if not validation_enabled:
741
+ self._add_extension_keyword_warning("default", path)
668
742
 
669
- def _check_numeric_validation(self, obj, path, type_name):
743
+ def _check_numeric_validation(self, obj, path, type_name, validation_enabled=True):
670
744
  """
671
745
  Check numeric validation keywords.
672
746
  """
@@ -676,6 +750,8 @@ class JSONStructureSchemaCoreValidator:
676
750
 
677
751
  for key in ["minimum", "maximum", "exclusiveMinimum", "exclusiveMaximum", "multipleOf"]:
678
752
  if key in obj:
753
+ if not validation_enabled:
754
+ self._add_extension_keyword_warning(key, path)
679
755
  val = obj[key]
680
756
  if expects_string:
681
757
  if not isinstance(val, str):
@@ -685,22 +761,43 @@ class JSONStructureSchemaCoreValidator:
685
761
  self._err(f"'{key}' must be a number.", f"{path}/{key}")
686
762
  elif key == "multipleOf" and val <= 0:
687
763
  self._err(f"'multipleOf' must be a positive number.", f"{path}/{key}")
764
+
765
+ # Check minimum <= maximum
766
+ if "minimum" in obj and "maximum" in obj:
767
+ min_val = obj["minimum"]
768
+ max_val = obj["maximum"]
769
+ if isinstance(min_val, (int, float)) and isinstance(max_val, (int, float)):
770
+ if min_val > max_val:
771
+ self._err("'minimum' cannot be greater than 'maximum'.", f"{path}")
688
772
 
689
- def _check_string_validation(self, obj, path):
773
+ def _check_string_validation(self, obj, path, validation_enabled=True):
690
774
  """
691
775
  Check string validation keywords.
692
776
  """
693
777
  if "minLength" in obj:
778
+ if not validation_enabled:
779
+ self._add_extension_keyword_warning("minLength", path)
694
780
  val = obj["minLength"]
695
781
  if not isinstance(val, int) or val < 0:
696
782
  self._err("'minLength' must be a non-negative integer.", f"{path}/minLength")
697
783
 
698
784
  if "maxLength" in obj:
785
+ if not validation_enabled:
786
+ self._add_extension_keyword_warning("maxLength", path)
699
787
  val = obj["maxLength"]
700
788
  if not isinstance(val, int) or val < 0:
701
789
  self._err("'maxLength' must be a non-negative integer.", f"{path}/maxLength")
790
+
791
+ # Check minLength <= maxLength
792
+ if "minLength" in obj and "maxLength" in obj:
793
+ min_val = obj["minLength"]
794
+ max_val = obj["maxLength"]
795
+ if isinstance(min_val, int) and isinstance(max_val, int) and min_val > max_val:
796
+ self._err("'minLength' cannot be greater than 'maxLength'.", f"{path}")
702
797
 
703
798
  if "pattern" in obj:
799
+ if not validation_enabled:
800
+ self._add_extension_keyword_warning("pattern", path)
704
801
  val = obj["pattern"]
705
802
  if not isinstance(val, str):
706
803
  self._err("'pattern' must be a string.", f"{path}/pattern")
@@ -712,23 +809,51 @@ class JSONStructureSchemaCoreValidator:
712
809
  self._err(f"'pattern' is not a valid regular expression: {e}", f"{path}/pattern")
713
810
 
714
811
  if "format" in obj:
812
+ if not validation_enabled:
813
+ self._add_extension_keyword_warning("format", path)
715
814
  val = obj["format"]
716
815
  if not isinstance(val, str):
717
816
  self._err("'format' must be a string.", f"{path}/format")
718
817
  elif val not in self.VALID_FORMATS:
719
818
  self._err(f"Unknown format '{val}'.", f"{path}/format")
819
+
820
+ # Content encoding/media type keywords
821
+ if "contentEncoding" in obj:
822
+ if not validation_enabled:
823
+ self._add_extension_keyword_warning("contentEncoding", path)
824
+ val = obj["contentEncoding"]
825
+ if not isinstance(val, str):
826
+ self._err("'contentEncoding' must be a string.", f"{path}/contentEncoding")
827
+
828
+ if "contentMediaType" in obj:
829
+ if not validation_enabled:
830
+ self._add_extension_keyword_warning("contentMediaType", path)
831
+ val = obj["contentMediaType"]
832
+ if not isinstance(val, str):
833
+ self._err("'contentMediaType' must be a string.", f"{path}/contentMediaType")
720
834
 
721
- def _check_array_validation(self, obj, path, type_name):
835
+ def _check_array_validation(self, obj, path, type_name, validation_enabled=True):
722
836
  """
723
837
  Check array/set validation keywords.
724
838
  """
725
839
  for key in ["minItems", "maxItems"]:
726
840
  if key in obj:
841
+ if not validation_enabled:
842
+ self._add_extension_keyword_warning(key, path)
727
843
  val = obj[key]
728
844
  if not isinstance(val, int) or val < 0:
729
845
  self._err(f"'{key}' must be a non-negative integer.", f"{path}/{key}")
846
+
847
+ # Check minItems <= maxItems
848
+ if "minItems" in obj and "maxItems" in obj:
849
+ min_val = obj["minItems"]
850
+ max_val = obj["maxItems"]
851
+ if isinstance(min_val, int) and isinstance(max_val, int) and min_val > max_val:
852
+ self._err("'minItems' cannot be greater than 'maxItems'.", f"{path}")
730
853
 
731
854
  if "uniqueItems" in obj:
855
+ if not validation_enabled:
856
+ self._add_extension_keyword_warning("uniqueItems", path)
732
857
  val = obj["uniqueItems"]
733
858
  if not isinstance(val, bool):
734
859
  self._err("'uniqueItems' must be a boolean.", f"{path}/uniqueItems")
@@ -736,6 +861,8 @@ class JSONStructureSchemaCoreValidator:
736
861
  self._err("'uniqueItems' cannot be false for 'set' type.", f"{path}/uniqueItems")
737
862
 
738
863
  if "contains" in obj:
864
+ if not validation_enabled:
865
+ self._add_extension_keyword_warning("contains", path)
739
866
  val = obj["contains"]
740
867
  if isinstance(val, dict):
741
868
  self._validate_schema(val, is_root=False, path=f"{path}/contains")
@@ -744,6 +871,8 @@ class JSONStructureSchemaCoreValidator:
744
871
 
745
872
  for key in ["minContains", "maxContains"]:
746
873
  if key in obj:
874
+ if not validation_enabled:
875
+ self._add_extension_keyword_warning(key, path)
747
876
  val = obj[key]
748
877
  if not isinstance(val, int) or val < 0:
749
878
  self._err(f"'{key}' must be a non-negative integer.", f"{path}/{key}")
@@ -751,7 +880,7 @@ class JSONStructureSchemaCoreValidator:
751
880
  if "contains" not in obj:
752
881
  self._err(f"'{key}' requires 'contains' to be present.", f"{path}/{key}")
753
882
 
754
- def _check_object_validation(self, obj, path, type_name):
883
+ def _check_object_validation(self, obj, path, type_name, validation_enabled=True):
755
884
  """
756
885
  Check object/map validation keywords.
757
886
  """
@@ -761,6 +890,8 @@ class JSONStructureSchemaCoreValidator:
761
890
 
762
891
  for key in [min_key, max_key, "minProperties", "maxProperties", "minEntries", "maxEntries"]:
763
892
  if key in obj:
893
+ if not validation_enabled:
894
+ self._add_extension_keyword_warning(key, path)
764
895
  # Check if using the right keyword for the type
765
896
  if type_name == "map" and key in ["minProperties", "maxProperties"]:
766
897
  self._err(f"Use '{key.replace('Properties', 'Entries')}' for map type instead of '{key}'.", f"{path}/{key}")
@@ -772,6 +903,8 @@ class JSONStructureSchemaCoreValidator:
772
903
  self._err(f"'{key}' must be a non-negative integer.", f"{path}/{key}")
773
904
 
774
905
  if "dependentRequired" in obj:
906
+ if not validation_enabled:
907
+ self._add_extension_keyword_warning("dependentRequired", path)
775
908
  if type_name != "object":
776
909
  self._err("'dependentRequired' only applies to object type.", f"{path}/dependentRequired")
777
910
  else:
@@ -791,6 +924,8 @@ class JSONStructureSchemaCoreValidator:
791
924
  pattern_key = "patternKeys" if type_name == "map" else "patternProperties"
792
925
  for key in ["patternProperties", "patternKeys"]:
793
926
  if key in obj:
927
+ if not validation_enabled:
928
+ self._add_extension_keyword_warning(key, path)
794
929
  if type_name == "map" and key == "patternProperties":
795
930
  self._err(f"Use 'patternKeys' for map type instead of 'patternProperties'.", f"{path}/{key}")
796
931
  elif type_name == "object" and key == "patternKeys":
@@ -816,6 +951,8 @@ class JSONStructureSchemaCoreValidator:
816
951
  name_key = "keyNames" if type_name == "map" else "propertyNames"
817
952
  for key in ["propertyNames", "keyNames"]:
818
953
  if key in obj:
954
+ if not validation_enabled:
955
+ self._add_extension_keyword_warning(key, path)
819
956
  if type_name == "map" and key == "propertyNames":
820
957
  self._err(f"Use 'keyNames' for map type instead of 'propertyNames'.", f"{path}/{key}")
821
958
  elif type_name == "object" and key == "keyNames":
@@ -831,6 +968,8 @@ class JSONStructureSchemaCoreValidator:
831
968
  self._err(f"'{key}' must be a schema object.", f"{path}/{key}")
832
969
 
833
970
  if "has" in obj:
971
+ if not validation_enabled:
972
+ self._add_extension_keyword_warning("has", path)
834
973
  val = obj["has"]
835
974
  if isinstance(val, dict):
836
975
  self._validate_schema(val, is_root=False, path=f"{path}/has")
@@ -1090,6 +1229,50 @@ class JSONStructureSchemaCoreValidator:
1090
1229
  )
1091
1230
  self.errors.append(error)
1092
1231
 
1232
+ def _warn(self, message: str, location: str = "#", code: str = ErrorCodes.SCHEMA_ERROR):
1233
+ """
1234
+ Appends a ValidationError with WARNING severity.
1235
+ """
1236
+ if self.source_locator:
1237
+ loc = self.source_locator.get_location(location)
1238
+ else:
1239
+ loc = JsonLocation.unknown()
1240
+
1241
+ warning = ValidationError(
1242
+ code=code,
1243
+ message=message,
1244
+ path=location,
1245
+ severity=ValidationSeverity.WARNING,
1246
+ location=loc
1247
+ )
1248
+ self.warnings.append(warning)
1249
+
1250
+ def _add_extension_keyword_warning(self, keyword: str, path: str):
1251
+ """
1252
+ Adds a warning for validation extension keywords used without the extension enabled.
1253
+ """
1254
+ if not self.warn_on_unused_extension_keywords:
1255
+ return
1256
+
1257
+ if "JSONStructureValidation" in self.enabled_extensions:
1258
+ return
1259
+
1260
+ all_validation_keywords = (self.NUMERIC_VALIDATION_KEYWORDS |
1261
+ self.STRING_VALIDATION_KEYWORDS |
1262
+ self.ARRAY_VALIDATION_KEYWORDS |
1263
+ self.OBJECT_VALIDATION_KEYWORDS)
1264
+
1265
+ if keyword not in all_validation_keywords:
1266
+ return
1267
+
1268
+ full_path = f"{path}/{keyword}" if path else keyword
1269
+ self._warn(
1270
+ f"Validation extension keyword '{keyword}' is used but validation extensions are not enabled. "
1271
+ "Add '\"$uses\": [\"JSONStructureValidation\"]' to enable validation, or this keyword will be ignored.",
1272
+ full_path,
1273
+ ErrorCodes.SCHEMA_EXTENSION_KEYWORD_NOT_ENABLED
1274
+ )
1275
+
1093
1276
 
1094
1277
  def validate_json_structure_schema_core(schema_document, source_text=None, allow_dollar=False, allow_import=False, import_map=None, extended=False):
1095
1278
  """