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 346522e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 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/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: List[ModelReference] = (),
semantic_id: Optional[Reference] = None,
supplemental_semantic_id: Iterable[Reference] = ()):
super().__init__()
Expand All @@ -1468,7 +1468,7 @@ def __init__(self,
self.value_type: Optional[DataTypeDefXsd] = value_type
self._value: Optional[ValueDataType]
self.value = value
self.refers_to: Iterable[ModelReference] = refers_to
self.refers_to: List[ModelReference] = 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 346522e

Please sign in to comment.