diff data_schema/__init__.py @ 31:271ec3abdfa3

Use "$type" as the schema's type specifier instead of "type". THIS IS BACKWARDS INCOMPATIBLE.
author Franz Glasner <f.glasner@feldmann-mg.com>
date Tue, 18 Jul 2023 14:28:52 +0200
parents 2e7c08c356ee
children 9a3da5a008fc
line wrap: on
line diff
--- a/data_schema/__init__.py	Sat Jul 08 20:45:36 2023 +0200
+++ b/data_schema/__init__.py	Tue Jul 18 14:28:52 2023 +0200
@@ -540,21 +540,21 @@
 
     # 3. Real validation
 
-    # check combinator shortcuts without "type" indirection
+    # check combinator shortcuts without "$type" indirection
     combinator, combinator_schema = _get_one_of(
         schema, "not", "all-of", "any-of", "one-of")
     if combinator is None:
         try:
-            t = schema["type"]
+            t = schema["$type"]
         except KeyError:
-            raise SchemaError("Schema has no `type' key: {!r}."
+            raise SchemaError("Schema has no `$type' key: {!r}."
                               " Context: {!s}".format(schema, context))
     else:
         #
         # Construct a temporary schema with the proper indirection for
         # the check below
         #
-        t = {"type": {combinator: combinator_schema}}
+        t = {"$type": {combinator: combinator_schema}}
         if combinator_schema is None:
             raise SchemaError("a combinator requires a child")
     if callable(t):
@@ -758,7 +758,7 @@
     try:
         schema_items = schema.ensure_child_schema(schema["items"])
     except KeyError:
-        schema_items = _Schema(schema, False, {"type": validate_deny})
+        schema_items = _Schema(schema, False, {"$type": validate_deny})
     for idx, o in enumerate(obj):
         new_context = Context(parent=context, index=idx, current_object=o)
         yield from _validate(o, schema_items, new_context)
@@ -782,7 +782,7 @@
     try:
         schema_items = schema.ensure_child_schema(schema["items"])
     except KeyError:
-        schema_items = _Schema(schema, False, {"type": validate_deny})
+        schema_items = _Schema(schema, False, {"$type": validate_deny})
     for o in obj:
         new_context = Context(parent=context, key=o, current_object=o)
         yield from _validate(o, schema_items, new_context)