Skip to content

Commit f41f38e

Browse files
ilaifMidnighter
andcommitted
feat: add hydrate to configuration
Co-authored-by: Midnighter <[email protected]>
1 parent 60f09ee commit f41f38e

File tree

3 files changed

+56
-6
lines changed

3 files changed

+56
-6
lines changed

src/structurizr/view/configuration.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ class ConfigurationIO(BaseModel):
4545
terminology: Optional[TerminologyIO]
4646
default_view: Optional[str] = Field(None, alias="defaultView")
4747
last_saved_view: Optional[str] = Field(None, alias="lastSavedView")
48-
view_sort_order: Optional[ViewSortOrder] = Field(None, alias="viewSortOrder")
48+
view_sort_order: ViewSortOrder = Field(
49+
default=ViewSortOrder.Default, alias="viewSortOrder",
50+
)
4951

5052

5153
class Configuration(AbstractBase):
@@ -65,7 +67,7 @@ def __init__(
6567
terminology: Optional[Terminology] = None,
6668
default_view: Optional[str] = None,
6769
last_saved_view: Optional[str] = None,
68-
view_sort_order: Optional[ViewSortOrder] = None,
70+
view_sort_order: ViewSortOrder = ViewSortOrder.Default,
6971
**kwargs
7072
) -> None:
7173
"""Initialize an element view."""
@@ -77,3 +79,17 @@ def __init__(
7779
self.default_view = default_view
7880
self.last_saved_view = last_saved_view
7981
self.view_sort_order = view_sort_order
82+
83+
@classmethod
84+
def hydrate(cls, configuration_io: ConfigurationIO) -> "Configuration":
85+
""""""
86+
return cls(
87+
# TODO:
88+
# branding=Branding.hydrate(configuration_io.branding),
89+
styles=Styles.hydrate(configuration_io.styles),
90+
theme=configuration_io.theme,
91+
# terminology=Terminology.hydrate(configuration_io.terminology),
92+
default_view=configuration_io.default_view,
93+
last_saved_view=configuration_io.last_saved_view,
94+
view_sort_order=configuration_io.view_sort_order,
95+
)

src/structurizr/view/element_style.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2020, Moritz E. Beber, Ilai Fallach.
1+
# Copyright (c) 2020, Moritz E. Beber.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -44,7 +44,7 @@ class ElementStyleIO(BaseModel):
4444
background: Optional[Color]
4545
stroke: Optional[str]
4646
color: Optional[Color]
47-
font_size: Optional[int] = Field(None, alias="fontSize")
47+
font_size: Optional[int] = Field(default=None, alias="fontSize")
4848
shape: Optional[Shape]
4949
icon: Optional[str]
5050
border: Optional[Border]
@@ -97,3 +97,22 @@ def __init__(
9797
self.opacity = opacity
9898
self.metadata = metadata
9999
self.description = description
100+
101+
@classmethod
102+
def hydrate(cls, element_style_io: ElementStyleIO) -> "ElementStyle":
103+
""""""
104+
return cls(
105+
tag=element_style_io.tag,
106+
width=element_style_io.width,
107+
height=element_style_io.height,
108+
background=element_style_io.background,
109+
stroke=element_style_io.stroke,
110+
color=element_style_io.color,
111+
font_size=element_style_io.font_size,
112+
shape=element_style_io.shape,
113+
icon=element_style_io.icon,
114+
border=element_style_io.border,
115+
opacity=element_style_io.opacity,
116+
metadata=element_style_io.metadata,
117+
description=element_style_io.description,
118+
)

src/structurizr/view/relationship_style.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2020, Moritz E. Beber, Ilai Fallach.
1+
# Copyright (c) 2020, Moritz E. Beber.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -41,7 +41,7 @@ class RelationshipStyleIO(BaseModel):
4141
thickness: Optional[int]
4242
width: Optional[int]
4343
color: Optional[Color]
44-
font_size: Optional[int] = Field(None, alias="fontSize")
44+
font_size: Optional[int] = Field(default=None, alias="fontSize")
4545
dashed: Optional[bool]
4646
routing: Optional[Routing]
4747
position: Optional[int]
@@ -84,3 +84,18 @@ def __init__(
8484
self.routing = routing
8585
self.position = position
8686
self.opacity = opacity
87+
88+
@classmethod
89+
def hydrate(cls, relationship_style_io: RelationshipStyleIO) -> "RelationshipStyle":
90+
""""""
91+
return cls(
92+
tag=relationship_style_io.tag,
93+
thickness=relationship_style_io.thickness,
94+
color=relationship_style_io.color,
95+
font_size=relationship_style_io.font_size,
96+
width=relationship_style_io.width,
97+
dashed=relationship_style_io.dashed,
98+
routing=relationship_style_io.routing,
99+
position=relationship_style_io.position,
100+
opacity=relationship_style_io.opacity,
101+
)

0 commit comments

Comments
 (0)