Skip to content

Commit

Permalink
add support for object arrays (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshbode authored and koxudaxi committed Oct 15, 2019
1 parent f5b43a6 commit 30ae213
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 2 deletions.
7 changes: 7 additions & 0 deletions datamodel_code_generator/model/pydantic/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@
type='IPv6Address', imports_=[Import(from_='pydantic', import_='IPv6Address')]
),
Types.boolean: DataType(type='bool'),
Types.object: DataType(
type='Dict[str, Any]',
imports_=[
Import(from_='typing', import_='Any'),
Import(from_='typing', import_='Dict'),
],
),
}


Expand Down
1 change: 1 addition & 0 deletions datamodel_code_generator/parser/jsonschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
'ipv6': Types.ipv6,
},
'boolean': {'default': Types.boolean},
'object': {'default': Types.object},
}


Expand Down
1 change: 1 addition & 0 deletions datamodel_code_generator/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@ class Types(Enum):
ipv4 = auto()
ipv6 = auto()
boolean = auto()
object = auto()
6 changes: 6 additions & 0 deletions tests/data/modular.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,9 @@ components:
properties:
attributes:
type: object
foo.bar.Thang:
properties:
attributes:
type: array
items:
type: object
6 changes: 5 additions & 1 deletion tests/parser/test_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1001,13 +1001,17 @@ class apis(BaseModel):
): '''\
from __future__ import annotations
from typing import Any, Dict, Optional
from typing import Any, Dict, List, Optional
from pydantic import BaseModel
class Thing(BaseModel):
attributes: Optional[Dict[str, Any]] = None
class Thang(BaseModel):
attributes: Optional[List[Dict[str, Any]]] = None
''',
},
)
Expand Down
6 changes: 5 additions & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,13 +385,17 @@ class apis(BaseModel):
from __future__ import annotations
from typing import Any, Dict, Optional
from typing import Any, Dict, List, Optional
from pydantic import BaseModel
class Thing(BaseModel):
attributes: Optional[Dict[str, Any]] = None
class Thang(BaseModel):
attributes: Optional[List[Dict[str, Any]]] = None
''',
}
],
Expand Down

0 comments on commit 30ae213

Please sign in to comment.