Skip to content

Commit 3bde935

Browse files
VasylRatushniukVasyl Ratushniuk
and
Vasyl Ratushniuk
authored
Fix map handler (#6)
Co-authored-by: Vasyl Ratushniuk <[email protected]>
1 parent 49a377f commit 3bde935

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

pydantic_glue/handler.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def dispatch(v: dict[str, Any]) -> str:
3939
def handle_map(o: dict[str, Any]) -> str:
4040
t = o["additionalProperties"]
4141
res = dispatch(t)
42-
return f"map<{res}, {res}>"
42+
return f"map<string,{res}>"
4343

4444

4545
def handle_union(o: dict[str, Any]) -> str:

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tool.poetry]
22
name = "pydantic-glue"
33
keywords = ["pydantic", "glue", "athena", "types", "convert"]
4-
version = "0.4.0"
4+
version = "0.5.0"
55
description = "Convert pydantic model to aws glue schema for terraform"
66
authors = ["Serhii Dimchenko <[email protected]>"]
77
readme = "README.md"

tests/unit/test_convert.py

+22
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,25 @@ class A(BaseModel):
189189
expected = [("name", "string")]
190190
actual = json.dumps(A.model_json_schema())
191191
assert convert(actual) == expected
192+
193+
194+
def test_map_object():
195+
196+
class A(BaseModel):
197+
some_a: dict[str, int]
198+
199+
expected = [("some_a", "map<string,int>")]
200+
assert convert(json.dumps(A.model_json_schema())) == expected
201+
202+
203+
def test_nested_map_object():
204+
205+
class A(BaseModel):
206+
hey: str
207+
ho: str
208+
209+
class B(BaseModel):
210+
some_b: dict[str, dict[str, A]]
211+
212+
expected = [("some_b", "map<string,map<string,struct<hey:string,ho:string>>>")]
213+
assert convert(json.dumps(B.model_json_schema())) == expected

0 commit comments

Comments
 (0)