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

Open Beginner friendly
#636 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
backend, testing

Research direction

Start in sdk/basyx/aas/adapter/json/json_serialization.py around lines 711-712 and compare Entity with the neighbouring collection guards and AssetInformation at line 320. Run JsonSerializationSchemaTest.test_full_example_serialization and test_aas_example_serialization with the AAS schema available; done means co-managed entities without specific asset IDs pass schema validation without an empty array.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Python
Stars
102
Forks
52
Avg merge
20d 17h
Merged PRs (30d)
1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from eclipse-basyx/basyx-python-sdk

All issues in eclipse-basyx/basyx-python-sdk

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.