Skip to content

Commit a1fe6df

Browse files
ilaifMidnighter
andcommitted
feat: add hydration to component model
Co-authored-by: Midnighter <[email protected]>
1 parent 7b480e0 commit a1fe6df

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/structurizr/model/component.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
from pydantic import Field
2222

23-
from .code_element import CodeElement
23+
from .code_element import CodeElement, CodeElementIO
2424
from .static_structure_element import StaticStructureElement, StaticStructureElementIO
2525

2626

@@ -53,7 +53,7 @@ class ComponentIO(StaticStructureElementIO):
5353
"""
5454

5555
technology: str = ""
56-
code_elements: List[CodeElement] = Field([], alias="codeElements")
56+
code_elements: List[CodeElementIO] = Field([], alias="codeElements")
5757
size: Optional[int] = None
5858

5959

@@ -81,7 +81,7 @@ class Component(StaticStructureElement):
8181
def __init__(
8282
self,
8383
*,
84-
parent: Container,
84+
parent: "Container",
8585
technology: str = "",
8686
code_elements: Iterable[CodeElement] = (),
8787
size: Optional[int] = None,
@@ -103,3 +103,14 @@ def __init__(
103103
self.technology = technology
104104
self.code_elements = set(code_elements)
105105
self.size = size
106+
107+
@classmethod
108+
def hydrate(cls, component_io: ComponentIO) -> "Component":
109+
""""""
110+
# TODO (midnighter): Initialization requires `parent`.
111+
return cls(
112+
name=component_io.name,
113+
description=component_io.description,
114+
technology=component_io.technology,
115+
# code_elements=map(CodeElement.hydrate, component_io.components),
116+
)

0 commit comments

Comments
 (0)