Standardise @context
of Thing Descriptions - closes #2809
#3034
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR makes sure that all Thing Descriptions exposed by the gateway have both the W3C WoT TD 1.1 and WebThings JSON-LD contexts, in order to work towards W3C compliance. It:
@context
is an arrayiot.mozilla.org/schemas
context if usedhttps://www.w3.org/2022/wot/td/v1.1
andhttps://webthings.io/schemas
are present in the array, and if not adds the W3C context to the start and/or adds the WebThings context to the end of the array. E.g.I had written some code to migrate existing Thing Descriptions in the gateway's database, so that they don't have to be modified at runtime every time they are read, but it turned out that code was redundant. Those Thing Descriptions already get updated on startup as a side effect of the
updateFromDescription()
method being called for every existing device when handlingdeviceAdded
messages from adapters. I don't think this is necessarily desirable, so I plan to revisit this in a follow-up and figure out what's going on there.Note: Currently the gateway only supports an array of strings in the
@context
, not maps which define JSON-LD prefixes. That feature is planned for later, when we'll ideally also add prefixes to all non-standard members.TODO:
Migrate old Thing Descriptions