changeset 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 94daf3381338
children 41efa38a39b1
files data_schema/__init__.py docs/schema.txt tests/test_schema.py
diffstat 3 files changed, 108 insertions(+), 108 deletions(-) [+]
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:
--- a/docs/schema.txt	Fri Jul 07 09:27:51 2023 +0200
+++ b/docs/schema.txt	Sat Jul 08 10:05:48 2023 +0200
@@ -62,14 +62,14 @@
   `dict` mit Keys und den Values als zugeordnete Schemata für die Values
   des Dicts
 
-- ``keyNames``
+- ``key-names``
 
-  Wenn vorhanden: ein Schema, dem die *Keys* -- auch die `additionalKeys` --
+  Wenn vorhanden: ein Schema, dem die *Keys* -- auch die `additional-keys` --
   folgen müssen.
 
   Default: entspricht ``{"type": "string"}``
 
-- ``additionalKeys``
+- ``additional-keys``
 
   * bool
 
@@ -94,8 +94,8 @@
 
   Liste von Strings mit Key-Namen, die vorkommen müssen
 
-- ``maxLength``
-- ``minLength``
+- ``max-length``
+- ``min-length``
 
 
 list / array
@@ -109,8 +109,8 @@
 
   Ein Schema für *alle* Items.
 
-- ``maxLength``
-- ``minLength``
+- ``max-length``
+- ``min-length``
 
 
 set / frozenset
@@ -124,8 +124,8 @@
 
   Ein Schema für *alle* Items
 
-- ``maxLength``
-- ``minLength``
+- ``max-length``
+- ``min-length``
 
 
 tuple / record
@@ -140,7 +140,7 @@
 
   Eine Liste: je ein spezielles Schema *pro Item*
 
-- ``additionalItems``
+- ``additional-items``
 
   * bool
 
@@ -154,8 +154,8 @@
 
     Prüfung der "zusätzlichen" Items erfolgt nach gegebenem Schema
 
-- ``maxLength``
-- ``minLength``
+- ``max-length``
+- ``min-length``
 
 
 string / str
@@ -177,8 +177,8 @@
   The string's value must be contained in (Python ``in``) in the referenced
   object (see `Referenzen`_).
 
-- ``maxLength``
-- ``minLength``
+- ``max-length``
+- ``min-length``
 - ``pattern``
 
   * string
@@ -195,8 +195,8 @@
 binary
 ------
 
-- ``maxLength``
-- ``minLength``
+- ``max-length``
+- ``min-length``
 - ``pattern``
 
   * string
@@ -280,8 +280,8 @@
 
   bool (Default: False): allow also a None/null/nil
 
-- ``minValue``
-- ``maxValue``
+- ``min-value``
+- ``max-value``
 - ``value``
 
   A callable to validate the integer value
@@ -291,7 +291,7 @@
   Eine Liste von ganzen Zahlen, von denen genau einer dem vorhandenen
   Wert entsprechen muß.
 
-  Achtung: Alle anderen Prüfungen (`minValue`, `maxValue`, `value`)
+  Achtung: Alle anderen Prüfungen (`min-value`, `max-value`, `value`)
            werden trotzdem auch durchgeführt.
 
 
@@ -302,8 +302,8 @@
 
   bool (Default: False): allow also a None/null/nil
 
-- ``minValue``
-- ``maxValue``
+- ``min-value``
+- ``max-value``
 - ``value``
 
   A callable to validate the float value
@@ -318,8 +318,8 @@
 
 Any numeric value (int or float)
 
-- ``minValue``
-- ``maxValue``
+- ``min-value``
+- ``max-value``
 - ``value``
 
   A callable to validate the number
@@ -329,7 +329,7 @@
   Eine Liste von Zahlen, von denen genau einer dem vorhandenen
   Wert entsprechen muß.
 
-  Achtung: Alle anderen Prüfungen (`minValue`, `maxValue`, `value`)
+  Achtung: Alle anderen Prüfungen (`min-value`, `max-value`, `value`)
            werden trotzdem auch durchgeführt.
 
 
--- a/tests/test_schema.py	Fri Jul 07 09:27:51 2023 +0200
+++ b/tests/test_schema.py	Sat Jul 08 10:05:48 2023 +0200
@@ -1403,7 +1403,7 @@
         x = list(data_schema.validate(
             {"key": "value"},
             {"type": "dict",
-             "additionalKeys": False}))
+             "additional-keys": False}))
         self.assertEqual(1, len(x))
         self.assertEqual(ERRORS.E10004, x[0].code)
         self.assertEqual("key", x[0].hint)
@@ -1412,7 +1412,7 @@
         x = list(data_schema.validate(
             {"key": "value"},
             {"type": "dict",
-             "additionalKeys": False},
+             "additional-keys": False},
             skip_keys=["key"]))
         self.assertEqual(0, len(x))
 
@@ -1421,7 +1421,7 @@
             {"key": "value",
              "key2": "value"},
             {"type": "dict",
-             "additionalKeys": False},
+             "additional-keys": False},
             skip_keys=[re.compile(r"\Akey\d*\Z")]))
         self.assertEqual(0, len(x))
 
@@ -1430,7 +1430,7 @@
             {"key": "value",
              "key2": "value"},
             {"type": "dict",
-             "additionalKeys": False},
+             "additional-keys": False},
             skip_keys=[re.compile(r"\A__.+"), re.compile(r"\Akey\d+\Z")]))
         self.assertEqual(1, len(x))
         self.assertEqual(ERRORS.E10004, x[0].code)
@@ -1440,14 +1440,14 @@
         x = list(data_schema.validate(
             {"key": "value"},
             {"type": "dict",
-             "additionalKeys": True}))
+             "additional-keys": True}))
         self.assertEqual(0, len(x))
 
     def test_d7(self):
         x = list(data_schema.validate(
             {"key": "value"},
             {"type": "dict",
-             "additionalKeys": {
+             "additional-keys": {
                  "type": "string"}}))
         self.assertEqual(0, len(x))
 
@@ -1455,7 +1455,7 @@
         x = list(data_schema.validate(
             {"key": 1234},
             {"type": "dict",
-             "additionalKeys": {
+             "additional-keys": {
                  "type": "string"}}))
         self.assertEqual(1, len(x))
         self.assertEqual(ERRORS.E10002, x[0].code)
@@ -1465,7 +1465,7 @@
         x = list(data_schema.validate(
             {"key": 1234},
             {"type": "dict",
-             "additionalKeys": {
+             "additional-keys": {
                  "type": "string"}},
             skip_keys=["key"]))
         self.assertEqual(0, len(x))
@@ -1474,7 +1474,7 @@
         pr = list(data_schema.validate(
             {0: "value"},
             {"type": "dict",
-             "additionalKeys": True}))
+             "additional-keys": True}))
         self.assertEqual(1, len(pr))
         self.assertEqual(ERRORS.E10003, pr[0].code)
 
@@ -1484,8 +1484,8 @@
             {"type": "dict",
              "keys": {
                  1: {"type": "string"}},
-             "additionalKeys": True,
-             "keyNames": {"type": "int"}}))
+             "additional-keys": True,
+             "key-names": {"type": "int"}}))
         self.assertEqual(0, len(pr))
 
     def test_error_message(self):
@@ -1527,46 +1527,46 @@
         pr = list(data_schema.validate(
             "",
             {"type": "string",
-             "minLength": 0}))
+             "min-length": 0}))
         self.assertEqual(0, len(pr))
 
         pr = list(data_schema.validate(
             "",
             {"type": "string",
-             "minLength": 1}))
+             "min-length": 1}))
         self.assertEqual(1, len(pr))
         self.assertEqual(ERRORS.E10006, pr[0].code)
 
         pr = list(data_schema.validate(
             "x",
             {"type": "string",
-             "minLength": 1}))
+             "min-length": 1}))
         self.assertEqual(0, len(pr))
 
     def test_str_maxlen(self):
         pr = list(data_schema.validate(
             "",
             {"type": "string",
-             "maxLength": 0}))
+             "max-length": 0}))
         self.assertEqual(0, len(pr))
 
         pr = list(data_schema.validate(
             "x",
             {"type": "string",
-             "maxLength": 0}))
+             "max-length": 0}))
         self.assertEqual(1, len(pr))
         self.assertEqual(ERRORS.E10007, pr[0].code)
 
         pr = list(data_schema.validate(
             "x",
             {"type": "string",
-             "maxLength": 1}))
+             "max-length": 1}))
         self.assertEqual(0, len(pr))
 
         pr = list(data_schema.validate(
             b"x",
             {"type": "string",
-             "maxLength": 1}))
+             "max-length": 1}))
         self.assertEqual(1, len(pr))
         self.assertEqual(ERRORS.E10002, pr[0].code)
 
@@ -1669,14 +1669,14 @@
         pr = list(data_schema.validate(
             b"",
             {"type": "binary",
-             "minLength": 1}))
+             "min-length": 1}))
         self.assertEqual(1, len(pr))
         self.assertEqual(ERRORS.E10036, pr[0].code)
 
         pr = list(data_schema.validate(
             b"1",
             {"type": "binary",
-             "maxLength": 0}))
+             "max-length": 0}))
         self.assertEqual(1, len(pr))
         self.assertEqual(ERRORS.E10037, pr[0].code)
 
@@ -1796,7 +1796,7 @@
              "items": [
                  {"type": "string"},
                  {"type": None}],
-             "additionalItems": True}))
+             "additional-items": True}))
         self.assertEqual(0, len(pr))
 
     def test_t6(self):
@@ -1806,22 +1806,22 @@
              "items": [
                  {"type": "string"},
                  {"type": None}],
-             "additionalItems": {
+             "additional-items": {
                  "type": "dict",
                  "keys": {"key": {"type": "string"}}
              }}))
         self.assertEqual(0, len(pr))
 
     def test_t7(self):
-        # do not check anything that exceeds maxLength
+        # do not check anything that exceeds max-length
         pr = list(data_schema.validate(
             ["a", None, {"key": "value"}, {"key": "value"}, {"key2": "value"}],
             {"type": "tuple",
-             "maxLength": 4,
+             "max-length": 4,
              "items": [
                  {"type": "string"},
                  {"type": None}],
-             "additionalItems": {
+             "additional-items": {
                  "type": "dict",
                  "keys": {"key": {"type": "string"}}
              }}))
@@ -1829,16 +1829,16 @@
         self.assertEqual(ERRORS.E10016, pr[0].code)
 
     def test_t8(self):
-        # do not check anything that exceeds maxLength
+        # do not check anything that exceeds max-length
         pr = list(data_schema.validate(
             ["a", None, {"key": "value"}, {"key": "value"}, {"key2": "value"}],
             {"type": "tuple",
-             "minLength": 6,
-             "maxLength": 4,
+             "min-length": 6,
+             "max-length": 4,
              "items": [
                  {"type": "string"},
                  {"type": None}],
-             "additionalItems": {
+             "additional-items": {
                  "type": "dict",
                  "keys": {"key": {"type": "string"}}
              }}))
@@ -1847,11 +1847,11 @@
         self.assertEqual(ERRORS.E10016, pr[1].code)
 
     def test_set1(self):
-        # do not check anything that exceeds maxLength
+        # do not check anything that exceeds max-length
         pr = list(data_schema.validate(
             set(["a", None, "b"]),
             {"type": "set",
-             "minLength": 3,
+             "min-length": 3,
              "items": {"any-of": [
                  {"type": "string"},
                  {"type": None}]}}
@@ -1859,7 +1859,7 @@
         self.assertEqual(0, len(pr))
 
     def test_set1_not_nullable(self):
-        # do not check anything that exceeds maxLength
+        # do not check anything that exceeds max-length
         pr = list(data_schema.validate(
             None,
             {"type": "set"}))
@@ -1867,18 +1867,18 @@
         self.assertEqual(ERRORS.E10038, pr[0].code)
 
     def test_set1_nullable(self):
-        # do not check anything that exceeds maxLength
+        # do not check anything that exceeds max-length
         pr = list(data_schema.validate(
             None,
             {"type": "set", "nullable": True}))
         self.assertEqual(0, len(pr))
 
     def test_set2(self):
-        # do not check anything that exceeds maxLength
+        # do not check anything that exceeds max-length
         pr = list(data_schema.validate(
             set(["a", None, "b"]),
             {"type": "set",
-             "minLength": 4,
+             "min-length": 4,
              "items": {"any-of": [
                  {"type": "string"},
                  {"type": None}]}}
@@ -1887,11 +1887,11 @@
         self.assertEqual(ERRORS.E10039, pr[0].code)
 
     def test_set3(self):
-        # do not check anything that exceeds maxLength
+        # do not check anything that exceeds max-length
         pr = list(data_schema.validate(
             set(["a", None, "b"]),
             {"type": "set",
-             "maxLength": 2,
+             "max-length": 2,
              "items": {"any-of": [
                  {"type": "string"},
                  {"type": None}]}}
@@ -2167,8 +2167,8 @@
         pr = list(data_schema.validate(
             2,
             {"type": "int",
-             "minValue": 3,
-             "maxValue": 1}))
+             "min-value": 3,
+             "max-value": 1}))
 
         self.assertEqual(2, len(pr))
         self.assertEqual(ERRORS.E10021, pr[0].code)
@@ -2185,8 +2185,8 @@
         pr = list(data_schema.validate(
             2.0,
             {"type": "real",
-             "minValue": 2.1,
-             "maxValue": 1.9}))
+             "min-value": 2.1,
+             "max-value": 1.9}))
 
         self.assertEqual(2, len(pr))
         self.assertEqual(ERRORS.E10024, pr[0].code)
@@ -2201,8 +2201,8 @@
         pr = list(data_schema.validate(
             2.0,
             {"type": "number",
-             "minValue": 3,
-             "maxValue": 1.3}))
+             "min-value": 3,
+             "max-value": 1.3}))
 
         self.assertEqual(2, len(pr))
         self.assertEqual(ERRORS.E10031, pr[0].code)