aas-core-works / aas-core3.0-python

Manipulate, verify and de/serialize asset administration shells in Python.
Other
4 stars 0 forks source link

SubmodelElementList value validation #9

Closed alexgordtop closed 10 months ago

alexgordtop commented 10 months ago

In a first implementation of SubmodelElementList I violated more or less all constraints of SubmodelElementList.

Is this a bug or am I missing something?

"Constraint AASd-120: idShort of submodel elements being a direct child of a SubmodelElementList shall not be specified."

"Constraint AASd-107: If a first level child element in a SubmodelElementList has a semanticId, it shall be identical to ubmodelElementList/semanticIdListElement. Constraint AASd-114: If two first level child elements in a SubmodelElementList have a semanticId, they shall be identical."

"Constraint AASd-115: If a first level child element in a SubmodelElementList does not specify a semanticId, the value is assumed to be identical to SubmodelElementList/semanticIdListElement."

"Constraint AASd-108: All first level child elements in a SubmodelElementList shall have the same submodel element type as specified in SubmodelElementList/typeValueListElement."

"Constraint AASd-109: If SubmodelElementList/typeValueListElement is equal to Property or Range, SubmodelElementList/valueTypeListElement shall be set and all first level child elements in the SubmodelElementList shall have the value type as specified in SubmodelElementList/valueTypeListElement."

from unittest import TestCase

from aas_core3.types import (
    AASSubmodelElements,
    DataTypeDefXSD,
    File,
    Property,
    SubmodelElementCollection,
    SubmodelElementList,
)
from aas_core3.verification import verify

class SubmodelElementListValidationTest(TestCase):
    def build_invalid_object(self) -> SubmodelElementList:
        invalid_list = SubmodelElementList(id_short="InvalidList", type_value_list_element=AASSubmodelElements.FILE)
        invalid_list.value = [
            File(id_short="FileWithIdShort", content_type="application/json"),
            Property(id_short="PropertyWithIdShort", value_type=DataTypeDefXSD.STRING),
            SubmodelElementCollection(id_short="SubmodelElementCollectionWithIdShort"),
        ]
        return invalid_list

    def test_verification(self) -> None:
        verify(self.build_invalid_object())
        self.fail("There are several violations...")
mristin commented 10 months ago

@alexgordtop thanks for creating the issue!

Mind that aas_core3.verification.verify returns an Iterator: https://github.com/aas-core-works/aas-core3.0-python/blob/4c35b97d78ff56e9189f9619c7a0269c0caf90e4/aas_core3/verification.py#L5812

Hence, you have to check that it returns something. This is by design, please see https://aas-core30-python.readthedocs.io/en/latest/getting_started/verify.html#verify. Usually, you want to report to the user a certain number of errors, and then stop if there are too many.

Just for reference, we do check for Constraint AASd-120: https://github.com/aas-core-works/aas-core-meta/blob/396c850c18ca9a7abc9d512ca13c54a287b3f8c0/aas_core_meta/v3.py#L2648-L2657

For AASd-107: https://github.com/aas-core-works/aas-core-meta/blob/396c850c18ca9a7abc9d512ca13c54a287b3f8c0/aas_core_meta/v3.py#L2695-L2711

AASd-115 is not really a constraint, so we did not implement it.

For AASd-108: https://github.com/aas-core-works/aas-core-meta/blob/396c850c18ca9a7abc9d512ca13c54a287b3f8c0/aas_core_meta/v3.py#L2678-L2687

For AASd-109: https://github.com/aas-core-works/aas-core-meta/blob/396c850c18ca9a7abc9d512ca13c54a287b3f8c0/aas_core_meta/v3.py#L2658-L2677

Could you please check if these constraints are still ignored when you iterate over the errors returned by the verify method?

alexgordtop commented 10 months ago

@mristin Sorry - validation issues have led in my previous use cases so obvious to an exception, that I didn't read the method signature.

Now I receive the expected errors :)