Skip to content

Commit

Permalink
model.Extension: Change refers_to to be of type List[Reference]
Browse files Browse the repository at this point in the history
Currently, `Extension.refers_to` is declared as a `Iterable[Reference]`.
This implies, that we can not necessarily check, whether or not the
attribute is empty or not.
This creates a problem with the XML serialization, since the
`<aas.refersTo>` element should only appear if there is at least
one `Reference` inside.

This commit changes the `Extension.refers_to` to be a list of
`Reference`s, as well as adapting a more clear check whether
or not the attribute is empty in `adapter.xml.xml_serialization`.
  • Loading branch information
s-heppner committed Nov 15, 2023
1 parent 6071934 commit 58f4597
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion basyx/aas/adapter/xml/xml_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def extension_to_xml(obj: model.Extension, tag: str = NS_AAS+"extension") -> etr
text=model.datatypes.XSD_TYPE_NAMES[obj.value_type]))
if obj.value:
et_extension.append(_value_to_xml(obj.value, obj.value_type)) # type: ignore # (value_type could be None)
if obj.refers_to:
if len(obj.refers_to) > 0:
refers_to = _generate_element(NS_AAS+"refersTo")
for reference in obj.refers_to:
refers_to.append(reference_to_xml(reference, NS_AAS+"reference"))
Expand Down
4 changes: 2 additions & 2 deletions basyx/aas/examples/data/example_aas.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ def create_example_asset_identification_submodel() -> model.Submodel:
name='ExampleExtension',
value_type=model.datatypes.String,
value="ExampleExtensionValue",
refers_to=(model.ModelReference((model.Key(type_=model.KeyTypes.ASSET_ADMINISTRATION_SHELL,
refers_to=[model.ModelReference((model.Key(type_=model.KeyTypes.ASSET_ADMINISTRATION_SHELL,
value='http://acplt.org/RefersTo/ExampleRefersTo'),),
model.AssetAdministrationShell),))
model.AssetAdministrationShell)],)

# Property-Element conform to 'Verwaltungssschale in der Praxis' page 41 ManufacturerName:
# https://www.plattform-i40.de/PI40/Redaktion/DE/Downloads/Publikation/2019-verwaltungsschale-in-der-praxis.html
Expand Down
7 changes: 5 additions & 2 deletions basyx/aas/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1458,7 +1458,7 @@ def __init__(self,
name: NameType,
value_type: Optional[DataTypeDefXsd] = None,
value: Optional[ValueDataType] = None,
refers_to: Iterable[ModelReference] = (),
refers_to: Optional[List[ModelReference]] = None,
semantic_id: Optional[Reference] = None,
supplemental_semantic_id: Iterable[Reference] = ()):
super().__init__()
Expand All @@ -1468,7 +1468,10 @@ def __init__(self,
self.value_type: Optional[DataTypeDefXsd] = value_type
self._value: Optional[ValueDataType]
self.value = value
self.refers_to: Iterable[ModelReference] = refers_to
if refers_to is None:
self.refers_to: List[ModelReference] = []
else:
self.refers_to = refers_to
self.semantic_id: Optional[Reference] = semantic_id
self.supplemental_semantic_id: ConstrainedList[Reference] = ConstrainedList(supplemental_semantic_id)

Expand Down

0 comments on commit 58f4597

Please sign in to comment.