Skip to content

Commit

Permalink
Fix map handler (#6)
Browse files Browse the repository at this point in the history
Co-authored-by: Vasyl Ratushniuk <[email protected]>
  • Loading branch information
VasylRatushniuk and Vasyl Ratushniuk authored Jul 18, 2024
1 parent 49a377f commit 3bde935
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pydantic_glue/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<string,{res}>"


def handle_union(o: dict[str, Any]) -> str:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
readme = "README.md"
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<string,int>")]
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<string,map<string,struct<hey:string,ho:string>>>")]
assert convert(json.dumps(B.model_json_schema())) == expected

0 comments on commit 3bde935

Please sign in to comment.