Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardise @context of Thing Descriptions - closes #2809 #3034

Merged
merged 1 commit into from
Mar 17, 2023

Conversation

benfrancis
Copy link
Member

@benfrancis benfrancis commented Dec 8, 2022

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:

  1. Makes sure the @context is an array
  2. Removes the legacy iot.mozilla.org/schemas context if used
  3. Makes sure both https://www.w3.org/2022/wot/td/v1.1 and https://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.
"@context": [
  "https://www.w3.org/2022/wot/td/v1.1",
  "https://webthings.io/schemas",
]

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 handling deviceAdded 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:

  • Remove legacy context
  • Add W3C context
  • Add WebThings context
  • Migrate old Thing Descriptions
  • Fix integration tests

@benfrancis
Copy link
Member Author

Note that we should also update the default used by gateway-addon-node and gateway-addon-python.

Copy link
Collaborator

@relu91 relu91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good, I have a minor question about the business logic of the standardizeContext function.

src/utils.ts Outdated Show resolved Hide resolved
@benfrancis benfrancis merged commit 0817eec into WebThingsIO:master Mar 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants