diff data_schema/__init__.py @ 19:c3a0fe8d4587

Consistent casing of schema items: all lowercase with dash as separator
author Franz Glasner <fzglas.hg@dom66.de>
date Sat, 08 Jul 2023 10:05:48 +0200
parents 65f937fb8de7
children 413b344be2d1
line wrap: on
line diff
--- a/data_schema/__init__.py	Fri Jul 07 09:27:51 2023 +0200
+++ b/data_schema/__init__.py	Sat Jul 08 10:05:48 2023 +0200
@@ -77,26 +77,26 @@
     E10018 = NC_("schema-msg", "object is not empty")
     E10019 = NC_("schema-msg", "more than one match in `one-of' detected")
     E10020 = NC_("schema-msg", "int expected")
-    E10021 = NC_("schema-msg", "int value lower than minValue")
-    E10022 = NC_("schema-msg", "int value greater than maxValue")
+    E10021 = NC_("schema-msg", "int value lower than min-value")
+    E10022 = NC_("schema-msg", "int value greater than max-value")
     E10023 = NC_("schema-msg", "float expected")
-    E10024 = NC_("schema-msg", "float value lower than minValue")
-    E10025 = NC_("schema-msg", "float value greater than maxValue")
+    E10024 = NC_("schema-msg", "float value lower than min-value")
+    E10025 = NC_("schema-msg", "float value greater than max-value")
     E10026 = NC_("schema-msg", "boolean value expected")
     E10027 = NC_("schema-msg", "boolean true expected")
     E10028 = NC_("schema-msg", "boolean false expected")
     E10029 = NC_("schema-msg", "`not' expected problems but got none")
     E10030 = NC_("schema-msg", "numeric type (int or float) expected")
-    E10031 = NC_("schema-msg", "numeric value lower than minValue")
-    E10032 = NC_("schema-msg", "numeric value greater than maxValue")
+    E10031 = NC_("schema-msg", "numeric value lower than min-value")
+    E10032 = NC_("schema-msg", "numeric value greater than max-value")
     E10033 = NC_("schema-msg", "a plain scalar value expected")
     E10034 = NC_("schema-msg", "dict key does not match required schema")
     E10035 = NC_("schema-msg", "binary data expected")
-    E10036 = NC_("schema-msg", "length of binary data lower than minValue")
-    E10037 = NC_("schema-msg", "length of binary data exceeds maxValue")
+    E10036 = NC_("schema-msg", "length of binary data lower than min-value")
+    E10037 = NC_("schema-msg", "length of binary data exceeds max-value")
     E10038 = NC_("schema-msg", "a set is expected")
-    E10039 = NC_("schema-msg", "length of set lower than minLength")
-    E10040 = NC_("schema-msg", "length of set greater than maxLength")
+    E10039 = NC_("schema-msg", "length of set lower than min-length")
+    E10040 = NC_("schema-msg", "length of set greater than max-length")
     E10041 = NC_("schema-msg", "timestamp expected")
     E10042 = NC_("schema-msg", "value of timestamp does not validate")
     E10043 = NC_("schema-msg", "enumerated string value expected but not found")
@@ -668,17 +668,17 @@
         yield ValidationProblem(code=ERRORS.E10000, hint="got: {}".format(type(obj).__name__), context=context)
         return
     yield from _validate_index_constraint(obj, schema, context)
-    minlen = schema.get("minLength", None)
+    minlen = schema.get("min-length", None)
     if minlen:
         if len(obj) < minlen:
             yield ValidationProblem(code=ERRORS.E10050, hint=obj, context=context)
-    maxlen = schema.get("maxLength", None)
+    maxlen = schema.get("max-length", None)
     if maxlen is not None:
         if len(obj) > maxlen:
             yield ValidationProblem(code=ERRORS.E10051, hint=obj, context=context)
     schema_keys = schema.get("keys", {}) if schema else {}
     seen_keys = set()
-    schema_keynames = schema.get_child("keyNames", None)
+    schema_keynames = schema.get_child("key-names", None)
     idx = -1
     for key, item in obj.items():
         idx += 1
@@ -704,7 +704,7 @@
             yield from _validate(item, schema.ensure_child_schema(schema_keys[key]), new_context)
         else:
             # check whether additional keys are allowed
-            additional_keys = schema.get_child("additionalKeys", False)
+            additional_keys = schema.get_child("additional-keys", False)
             if isinstance(additional_keys, bool):
                 if not additional_keys:
                     if not _is_in_skip_keys(key, context.settings.skip_keys):
@@ -731,11 +731,11 @@
         yield ValidationProblem(code=ERRORS.E10001, hint="got: {}".format(type(obj).__name__), context=context)
         return
     yield from _validate_index_constraint(obj, schema, context)
-    minlen = schema.get("minLength", None)
+    minlen = schema.get("min-length", None)
     if minlen:
         if len(obj) < minlen:
             yield ValidationProblem(code=ERRORS.E10012, hint=obj, context=context)
-    maxlen = schema.get("maxLength", None)
+    maxlen = schema.get("max-length", None)
     if maxlen is not None:
         if len(obj) > maxlen:
             yield ValidationProblem(code=ERRORS.E10013, hint=obj, context=context)
@@ -755,11 +755,11 @@
         yield ValidationProblem(code=ERRORS.E10038, hint="got: {}".format(type(obj).__name__), context=context)
         return
     yield from _validate_index_constraint(obj, schema, context)
-    minlen = schema.get("minLength", None)
+    minlen = schema.get("min-length", None)
     if minlen:
         if len(obj) < minlen:
             yield ValidationProblem(code=ERRORS.E10039, hint=obj, context=context)
-    maxlen = schema.get("maxLength", None)
+    maxlen = schema.get("max-length", None)
     if maxlen is not None:
         if len(obj) > maxlen:
             yield ValidationProblem(code=ERRORS.E10040, hint=obj, context=context)
@@ -779,11 +779,11 @@
         yield ValidationProblem(code=ERRORS.E10014, hint="got: {}".format(type(obj).__name__), context=context)
         return
     yield from _validate_index_constraint(obj, schema, context)
-    minlen = schema.get("minLength", None)
+    minlen = schema.get("min-length", None)
     if minlen:
         if len(obj) < minlen:
             yield ValidationProblem(code=ERRORS.E10015, hint=obj, context=context)
-    maxlen = schema.get("maxLength", None)
+    maxlen = schema.get("max-length", None)
     if maxlen is not None:
         if len(obj) > maxlen:
             yield ValidationProblem(code=ERRORS.E10016, hint=obj, context=context)
@@ -798,7 +798,7 @@
         try:
             schema_index = schema.ensure_child_schema(schema_items[idx])
         except IndexError:
-            additional_items = schema.get_child("additionalItems", False)
+            additional_items = schema.get_child("additional-items", False)
             if isinstance(additional_items, bool):
                 if not additional_items:
                     yield ValidationProblem(code=ERRORS.E10017, context=new_context)
@@ -822,11 +822,11 @@
                     break
             else:
                 yield ValidationProblem(code=ERRORS.E10043, hint=obj, context=context)
-        minlen = schema.get("minLength", None)
+        minlen = schema.get("min-length", None)
         if minlen:
             if len(obj) < minlen:
                 yield ValidationProblem(code=ERRORS.E10006, hint=obj, context=context)
-        maxlen = schema.get("maxLength", None)
+        maxlen = schema.get("max-length", None)
         if maxlen is not None:
             if len(obj) > maxlen:
                 yield ValidationProblem(code=ERRORS.E10007, hint=obj, context=context)
@@ -865,11 +865,11 @@
         yield ValidationProblem(code=ERRORS.E10035, hint=obj, context=context)
     else:
         yield from _validate_index_constraint(obj, schema, context)
-        minlen = schema.get("minLength", None)
+        minlen = schema.get("min-length", None)
         if minlen:
             if len(obj) < minlen:
                 yield ValidationProblem(code=ERRORS.E10036, hint=obj, context=context)
-        maxlen = schema.get("maxLength", None)
+        maxlen = schema.get("max-length", None)
         if maxlen is not None:
             if len(obj) > maxlen:
                 yield ValidationProblem(code=ERRORS.E10037, hint=obj, context=context)
@@ -920,11 +920,11 @@
         yield ValidationProblem(code=ERRORS.E10020, hint=obj, context=context)
     else:
         yield from _validate_index_constraint(obj, schema, context)
-        minValue = schema.get("minValue", None)
-        if minValue is not None and obj < minValue:
+        min_value = schema.get("min-value", None)
+        if min_value is not None and obj < min_value:
             yield ValidationProblem(code=ERRORS.E10021, hint=obj, context=context)
-        maxValue = schema.get("maxValue", None)
-        if maxValue is not None and obj > maxValue:
+        max_value = schema.get("max-value", None)
+        if max_value is not None and obj > max_value:
             yield ValidationProblem(code=ERRORS.E10022, hint=obj, context=context)
         enumvalues = schema.get("enum", None)
         if enumvalues is not None:
@@ -948,11 +948,11 @@
         yield ValidationProblem(code=ERRORS.E10023, hint=obj, context=context)
     else:
         yield from _validate_index_constraint(obj, schema, context)
-        minValue = schema.get("minValue", None)
-        if minValue is not None and obj < minValue:
+        min_value = schema.get("min-value", None)
+        if min_value is not None and obj < min_value:
             yield ValidationProblem(code=ERRORS.E10024, hint=obj, context=context)
-        maxValue = schema.get("maxValue", None)
-        if maxValue is not None and obj > maxValue:
+        max_value = schema.get("max-value", None)
+        if max_value is not None and obj > max_value:
             yield ValidationProblem(code=ERRORS.E10025, hint=obj, context=context)
         value = schema.get("value", None)
         if value is not None:
@@ -969,15 +969,15 @@
         yield ValidationProblem(code=ERRORS.E10030, hint=obj, context=context)
     else:
         yield from _validate_index_constraint(obj, schema, context)
-        minValue = schema.get("minValue", None)
-        if minValue is not None and isinstance(obj, float):
-            minValue *= 1.0
-        if minValue is not None and obj < minValue:
+        min_value = schema.get("min-value", None)
+        if min_value is not None and isinstance(obj, float):
+            min_value *= 1.0
+        if min_value is not None and obj < min_value:
             yield ValidationProblem(code=ERRORS.E10031, hint=obj, context=context)
-        maxValue = schema.get("maxValue", None)
-        if maxValue is not None and isinstance(obj, float):
-            maxValue *= 1.0
-        if maxValue is not None and obj > maxValue:
+        max_value = schema.get("max-value", None)
+        if max_value is not None and isinstance(obj, float):
+            max_value *= 1.0
+        if max_value is not None and obj > max_value:
             yield ValidationProblem(code=ERRORS.E10032, hint=obj, context=context)
         enumvalues = schema.get("enum", None)
         if enumvalues is not None: