Repository: jdkandersson/OpenAlchemy

Issue:
The typed dict cannot have types such as datetime
The typed dict of a models file should only have the basic OpenAPI types, it should not have python types such as `datetime` which currently is the case.

Discussion:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1dc8241c..adf69203 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,7 @@
 ## Version _next_
 
 - Add support for `readOnly`.
+- Fix bug where TypedDIct types for `binary`, `date` and `date-time` string formats mapped to the incorrect python types.
 
 ## Version 1.1.0 - 2020-04-05
 
diff --git a/open_alchemy/models_file/model/type_.py b/open_alchemy/models_file/model/type_.py
index 7bc55cd3..5b4b361d 100644
--- a/open_alchemy/models_file/model/type_.py
+++ b/open_alchemy/models_file/model/type_.py
@@ -72,6 +72,12 @@ def typed_dict(*, artifacts: types.ColumnSchemaArtifacts) -> str:
         model_type = model_type.replace(
             f"T{artifacts.de_ref}", f"{artifacts.de_ref}Dict"
         )
+    if artifacts.format == "binary":
+        model_type = model_type.replace("bytes", "str")
+    if artifacts.format == "date":
+        model_type = model_type.replace("datetime.date", "str")
+    if artifacts.format == "date-time":
+        model_type = model_type.replace("datetime.datetime", "str")
 
     return model_type
 


Test patch:
diff --git a/tests/open_alchemy/models_file/model/test_type.py b/tests/open_alchemy/models_file/model/test_type.py
index caa228af..1b2c0e13 100644
--- a/tests/open_alchemy/models_file/model/test_type.py
+++ b/tests/open_alchemy/models_file/model/test_type.py
@@ -106,23 +106,25 @@ def test_model(
 
 
 @pytest.mark.parametrize(
-    "type_, expected_type",
+    "type_, format_, expected_type",
     [
-        ("integer", "int"),
-        ("object", '"RefModelDict"'),
-        ("array", 'typing.Sequence["RefModelDict"]'),
+        pytest.param("integer", None, "typing.Optional[int]", id="plain"),
+        pytest.param("string", "binary", "typing.Optional[str]", id="binary"),
+        pytest.param("string", "date", "typing.Optional[str]", id="date"),
+        pytest.param("string", "date-time", "typing.Optional[str]", id="date-time"),
+        pytest.param("object", None, 'typing.Optional["RefModelDict"]', id="object"),
+        pytest.param("array", None, 'typing.Sequence["RefModelDict"]', id="array"),
     ],
-    ids=["plain", "object", "array"],
 )
 @pytest.mark.models_file
-def test_dict(type_, expected_type):
+def test_dict(type_, format_, expected_type):
     """
     GIVEN None format and required, False nullable and de_ref and given type
     WHEN typed_dict is called with the type, format, nullable, required and de_ref
     THEN the given expected type is returned.
     """
     artifacts = models_file.types.ColumnSchemaArtifacts(
-        type=type_, nullable=False, de_ref="RefModel"
+        type=type_, format=format_, nullable=True, de_ref="RefModel"
     )
 
     returned_type = models_file._model._type.typed_dict(artifacts=artifacts)