Repository: jdkandersson/OpenAlchemy

Issue:
Examine nullability of extension properties
Examine whether nullability of extension properties is a problem sine JSON schema does not support _nullable_.

Discussion:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 311b4b60..baabd64f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,7 @@
 
 - Add support for remote references to a file at a URL.
 - Add support for default values.
+- Add check for whether the value of an extension property is null.
 
 ## Version 0.14.0 - 2020-02-21
 
diff --git a/open_alchemy/helpers/get_ext_prop/__init__.py b/open_alchemy/helpers/get_ext_prop/__init__.py
index 3b694993..d254a3c3 100644
--- a/open_alchemy/helpers/get_ext_prop/__init__.py
+++ b/open_alchemy/helpers/get_ext_prop/__init__.py
@@ -45,9 +45,16 @@ def get_ext_prop(
         The value of the property or the default value if it does not exist.
 
     """
+    # Check for presence of name
+    if name not in source:
+        return default
+
+    # Retrieve value
     value = source.get(name)
     if value is None:
-        return default
+        raise exceptions.MalformedExtensionPropertyError(
+            f"The value of the {name} extension property cannot be null."
+        )
 
     schema = _SCHEMAS.get(name)
     try:


Test patch:
diff --git a/tests/open_alchemy/helpers/test_get_ext_prop.py b/tests/open_alchemy/helpers/test_get_ext_prop.py
index 6f78bf2d..c781c417 100644
--- a/tests/open_alchemy/helpers/test_get_ext_prop.py
+++ b/tests/open_alchemy/helpers/test_get_ext_prop.py
@@ -44,6 +44,7 @@ def test_miss_default():
         ("x-foreign-key", "no column"),
         ("x-foreign-key-column", True),
         ("x-tablename", True),
+        ("x-tablename", None),
         ("x-de-$ref", True),
         ("x-dict-ignore", "True"),
         ("x-generated", "True"),
@@ -60,6 +61,7 @@ def test_miss_default():
         "x-foreign-key invalid format",
         "x-foreign-key-column",
         "x-tablename",
+        "x-tablename None",
         "x-de-$ref",
         "x-dict-ignore",
         "x-generated",
diff --git a/tests/open_alchemy/test_model_factory.py b/tests/open_alchemy/test_model_factory.py
index f9031c15..a0ef659e 100644
--- a/tests/open_alchemy/test_model_factory.py
+++ b/tests/open_alchemy/test_model_factory.py
@@ -36,6 +36,27 @@ def test_missing_tablename():
         )
 
 
+@pytest.mark.model
+def test_tablename_none():
+    """
+    GIVEN schemas with schema that has None for the tablename
+    WHEN model_factory is called with the name of the schema
+    THEN MalformedExtensionPropertyError is raised.
+    """
+    with pytest.raises(exceptions.MalformedExtensionPropertyError):
+        model_factory.model_factory(
+            name="SingleProperty",
+            base=mock.MagicMock,
+            schemas={
+                "SingleProperty": {
+                    "x-tablename": None,
+                    "type": "object",
+                    "properties": {"property_1": {"type": "integer"}},
+                }
+            },
+        )
+
+
 @pytest.mark.model
 def test_not_object():
     """