From 3bde935c5f25a70f006562091e92a6fbc66c303b Mon Sep 17 00:00:00 2001 From: Vasyl Ratushniuk <93404796+VasylRatushniuk@users.noreply.github.com> Date: Thu, 18 Jul 2024 18:24:44 +0300 Subject: [PATCH] Fix map handler (#6) Co-authored-by: Vasyl Ratushniuk --- pydantic_glue/handler.py | 2 +- pyproject.toml | 2 +- tests/unit/test_convert.py | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/pydantic_glue/handler.py b/pydantic_glue/handler.py index 16b1895..5ea3c89 100644 --- a/pydantic_glue/handler.py +++ b/pydantic_glue/handler.py @@ -39,7 +39,7 @@ def dispatch(v: dict[str, Any]) -> str: def handle_map(o: dict[str, Any]) -> str: t = o["additionalProperties"] res = dispatch(t) - return f"map<{res}, {res}>" + return f"map" def handle_union(o: dict[str, Any]) -> str: diff --git a/pyproject.toml b/pyproject.toml index 45ff550..1cb0cb1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "pydantic-glue" keywords = ["pydantic", "glue", "athena", "types", "convert"] -version = "0.4.0" +version = "0.5.0" description = "Convert pydantic model to aws glue schema for terraform" authors = ["Serhii Dimchenko "] readme = "README.md" diff --git a/tests/unit/test_convert.py b/tests/unit/test_convert.py index 3dfee22..a588e9e 100644 --- a/tests/unit/test_convert.py +++ b/tests/unit/test_convert.py @@ -189,3 +189,25 @@ class A(BaseModel): expected = [("name", "string")] actual = json.dumps(A.model_json_schema()) assert convert(actual) == expected + + +def test_map_object(): + + class A(BaseModel): + some_a: dict[str, int] + + expected = [("some_a", "map")] + assert convert(json.dumps(A.model_json_schema())) == expected + + +def test_nested_map_object(): + + class A(BaseModel): + hey: str + ho: str + + class B(BaseModel): + some_b: dict[str, dict[str, A]] + + expected = [("some_b", "map>>")] + assert convert(json.dumps(B.model_json_schema())) == expected