basyx-python-sdk icon indicating copy to clipboard operation
basyx-python-sdk copied to clipboard

adapter.json: `Entity` serializes an empty `specificAssetIds` array, which the schema rejects

Open leogrox opened this issue 2 months ago • 1 comments

Entity.specific_asset_id is a collection, so it is never None, but the serializer guards it with is not None:

https://github.com/eclipse-basyx/basyx-python-sdk/blob/develop/sdk/basyx/aas/adapter/json/json_serialization.py#L711-L712

An entity without specific asset ids therefore serializes as "specificAssetIds": [], and every array in the AAS JSON schema carries minItems: 1. Since AASd-014 forbids specific asset ids on a co-managed entity, every co-managed Entity this SDK writes is invalid JSON, the example AAS included.

Reproduction against the official schema (aas-specs-metamodel v3.1.2):

import json, jsonschema
from basyx.aas import model
from basyx.aas.adapter.json import AASToJsonEncoder

schema = json.load(open("aas.json"))
entity = model.Entity("MyEntity", model.EntityType.CO_MANAGED_ENTITY)
data = json.loads(json.dumps(entity, cls=AASToJsonEncoder))
# {'idShort': 'MyEntity', 'modelType': 'Entity', 'entityType': 'CoManagedEntity', 'specificAssetIds': []}

jsonschema.validate(data, {"$ref": "#/definitions/Entity", "definitions": schema["definitions"]})
# ValidationError: [] should be non-empty

JsonSerializationSchemaTest.test_full_example_serialization and test_aas_example_serialization both catch this as soon as the schema file is actually present, which it isn't in CI; see the companion issue on the schema path.

The neighbouring attributes in the same method, and AssetInformation at L320, already guard on the collection being non-empty; Entity is the only place that doesn't. I checked the other element types against the schema (Submodel, SubmodelElementCollection, SubmodelElementList, Property, Operation, AnnotatedRelationshipElement, AssetAdministrationShell, ConceptDescription) and they all serialize valid documents.

Happy to send the one-line fix with tests.

leogrox avatar Sep 19 '26 20:09 leogrox

Fixed in #638

zrgt avatar Oct 06 '26 22:10 zrgt