1919from abc import ABC
2020from typing import Iterable , List , Optional
2121
22- from pydantic import Field , HttpUrl
22+ from pydantic import Field
2323
24- from .deployment_element import DEFAULT_DEPLOYMENT_ENVIRONMENT , DeploymentElement
24+ from .deployment_element import DeploymentElement , DeploymentElementIO
2525from .http_health_check import HTTPHealthCheck , HTTPHealthCheckIO
26- from .model_item import ModelItem , ModelItemIO
27- from .relationship import Relationship , RelationshipIO
2826from .static_structure_element import StaticStructureElement
2927
3028
3129__all__ = ("StaticStructureElementInstance" , "StaticStructureElementInstanceIO" )
3230
3331
34- class StaticStructureElementInstanceIO (ModelItemIO , ABC ):
35- """
36- Define a superclass for instances of container and software system.
32+ class StaticStructureElementInstanceIO (DeploymentElementIO , ABC ):
33+ """Define a superclass for instances of container and software system."""
3734
38- Implementation note:
39- In this case, the IO does not reflect the same inheritance hierarchy
40- as the main class. This is because instances do not have the `name` field
41- and so we cannot extend `ElementIO` which enforces that `name` is populated.
42- See http://github.com/structurizr/json/blob/master/structurizr.yaml.
43- """
35+ name : Optional [str ] = "" # Name is not serialisable for instances
4436
45- description : str = Field (default = "" )
46- url : Optional [HttpUrl ] = Field (default = None )
47- relationships : List [RelationshipIO ] = Field (default = ())
48-
49- environment : Optional [str ] = DEFAULT_DEPLOYMENT_ENVIRONMENT
5037 instance_id : int = Field (alias = "instanceId" )
5138 health_checks : List [HTTPHealthCheckIO ] = Field (default = (), alias = "healthChecks" )
5239
@@ -65,21 +52,17 @@ def __init__(
6552 """Initialize a StaticStructureElementInstance."""
6653 # The name of the instance comes from element it contains - see
6754 # StaticStructureElementInstance.getName() in the Java API.
68- super ().__init__ (name = element .name , ** kwargs )
55+ kwargs ["name" ] = element .name
56+ super ().__init__ (** kwargs )
6957 self .instance_id = instance_id
7058 self .health_checks = set (health_checks )
7159
7260 @classmethod
7361 def hydrate_arguments (cls , instance_io : StaticStructureElementInstanceIO ) -> dict :
7462 """Build constructor arguments from IO."""
7563
76- # See note in DeploymentInstanceIO on why we're not using super() here.
7764 return {
78- ** ModelItem .hydrate_arguments (instance_io ),
79- "description" : instance_io .description ,
80- "url" : instance_io .url ,
81- "relationships" : map (Relationship .hydrate , instance_io .relationships ),
82- "environment" : instance_io .environment ,
65+ ** super ().hydrate_arguments (instance_io ),
8366 "instance_id" : instance_io .instance_id ,
8467 "health_checks" : map (HTTPHealthCheck .hydrate , instance_io .health_checks ),
8568 }
0 commit comments