Skip to content

Commit

Permalink
Set SpecificAssetId.external_subject_id as optional
Browse files Browse the repository at this point in the history
according to the spec
  • Loading branch information
zrgt authored and s-heppner committed Oct 18, 2023
1 parent 0fb4fb1 commit a91ee0a
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion basyx/aas/adapter/json/json_deserialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def _construct_specific_asset_id(cls, dct: Dict[str, object], object_class=model
return object_class(name=_get_ts(dct, 'name', str),
value=_get_ts(dct, 'value', str),
external_subject_id=cls._construct_external_reference(
_get_ts(dct, 'externalSubjectId', dict)),
_get_ts(dct, 'externalSubjectId', dict)) if 'externalSubjectId' in dct else None,
semantic_id=cls._construct_reference(_get_ts(dct, 'semanticId', dict))
if 'semanticId' in dct else None,
supplemental_semantic_id=[
Expand Down
3 changes: 2 additions & 1 deletion basyx/aas/adapter/json/json_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ def _specific_asset_id_to_json(cls, obj: model.SpecificAssetId) -> Dict[str, obj
data = cls._abstract_classes_to_json(obj)
data['name'] = obj.name
data['value'] = obj.value
data['externalSubjectId'] = obj.external_subject_id
if obj.external_subject_id:
data['externalSubjectId'] = obj.external_subject_id
return data

@classmethod
Expand Down
4 changes: 2 additions & 2 deletions basyx/aas/adapter/xml/xml_deserialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -984,10 +984,10 @@ def construct_specific_asset_id(cls, element: etree.Element, object_class=model.
**_kwargs: Any) -> model.SpecificAssetId:
# semantic_id can't be applied by _amend_abstract_attributes because specificAssetId is immutable
return object_class(
external_subject_id=_child_construct_mandatory(element, NS_AAS + "externalSubjectId",
cls.construct_external_reference),
name=_get_text_or_none(element.find(NS_AAS + "name")),
value=_get_text_or_none(element.find(NS_AAS + "value")),
external_subject_id=_failsafe_construct(element.find(NS_AAS + "externalSubjectId"),
cls.construct_external_reference, cls.failsafe),
semantic_id=_failsafe_construct(element.find(NS_AAS + "semanticId"), cls.construct_reference, cls.failsafe)
)

Expand Down
3 changes: 2 additions & 1 deletion basyx/aas/adapter/xml/xml_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ def specific_asset_id_to_xml(obj: model.SpecificAssetId, tag: str = NS_AAS + "sp
et_asset_information = abstract_classes_to_xml(tag, obj)
et_asset_information.append(_generate_element(name=NS_AAS + "name", text=obj.name))
et_asset_information.append(_generate_element(name=NS_AAS + "value", text=obj.value))
et_asset_information.append(reference_to_xml(obj.external_subject_id, NS_AAS + "externalSubjectId"))
if obj.external_subject_id:
et_asset_information.append(reference_to_xml(obj.external_subject_id, NS_AAS + "externalSubjectId"))

return et_asset_information

Expand Down
2 changes: 1 addition & 1 deletion basyx/aas/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2159,7 +2159,7 @@ class SpecificAssetId(HasSemantics):
def __init__(self,
name: LabelType,
value: Identifier,
external_subject_id: ExternalReference,
external_subject_id: Optional[ExternalReference] = None,
semantic_id: Optional[Reference] = None,
supplemental_semantic_id: Iterable[Reference] = ()):
super().__init__()
Expand Down

0 comments on commit a91ee0a

Please sign in to comment.