Description
Simplest reproducible example (it may have other errors after simplifying): AShape
defines the position
term (which in turn defines the x
and y
terms). CBox
tries to re-use the position
term without any modification:
{
"type": ["VerifiableCredential"],
"@context": [
"https://www.w3.org/ns/credentials/v2",
{
"shapes": "https://example.com/imaginary/shapes/",
"@protected": true,
"@version": 1.1,
"AShape": {
"@protected": true,
"@id": "shapes:Shape",
"@context": {
"position": {
"@protected": true,
"@id": "shapes:position",
"@context": {
"x": "xsd:string",
"y": "xsd:string"
}
}
}
},
"CBox": {
"@protected": true,
"@id": "shapes:Box",
"@context": {
"position": "shapes:position"
}
}
}
],
"credentialSubject": {
"type": ["CBox", "AShape"]
}
}
If the type is both ["CBox", "AShape"]
as it is for the credentialSubject
property above, then lint complains with the following:
$ jsonld lint -l test-file.jsonld
jsonld.SyntaxError: Invalid JSON-LD syntax; tried to redefine a protected term.
at api.createTermDefinition (/home/michael/.nvm/versions/node/v20.13.1/lib/node_modules/jsonld-cli/node_modules/jsonld/lib/context.js:988:13)
at api.process (/home/michael/.nvm/versions/node/v20.13.1/lib/node_modules/jsonld-cli/node_modules/jsonld/lib/context.js:399:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async api.expand (/home/michael/.nvm/versions/node/v20.13.1/lib/node_modules/jsonld-cli/node_modules/jsonld/lib/expand.js:238:23)
at async _expandObject (/home/michael/.nvm/versions/node/v20.13.1/lib/node_modules/jsonld-cli/node_modules/jsonld/lib/expand.js:926:25)
at async api.expand (/home/michael/.nvm/versions/node/v20.13.1/lib/node_modules/jsonld-cli/node_modules/jsonld/lib/expand.js:251:3)
at async jsonld.expand (/home/michael/.nvm/versions/node/v20.13.1/lib/node_modules/jsonld-cli/node_modules/jsonld/lib/jsonld.js:322:18)
at async Command.lint (file:///home/michael/.nvm/versions/node/v20.13.1/lib/node_modules/jsonld-cli/bin/jsonld.js:304:5)
at async Command.parseAsync (/home/michael/.nvm/versions/node/v20.13.1/lib/node_modules/jsonld-cli/node_modules/commander/lib/command.js:936:5)
Error: {
name: 'jsonld.SyntaxError',
details: {
code: 'protected term redefinition',
context: { position: 'shapes:position' },
term: 'position'
}
}
When debugging, I can see it's failing when comparing the properties of the two terms which should be equal, but instead, it finds the lengths different at:
Lines 1589 to 1591 in 7165607
If I print the two terms there with
console.log(`not equal: ${JSON.stringify(x1)} and ${JSON.stringify(x2)}`);
I see that the two differ because one has an @context
key, the other doesn't:
not equal: {"reverse":false,"_termHasColon":false,"@id":"https://example.com/imaginary/shapes/position","_prefix":false,"protected":true,"@context":{"x":"xsd:string","y":"xsd:string"}} and {"reverse":false,"_termHasColon":false,"@id":"https://example.com/imaginary/shapes/position","_prefix":false,"protected":true}
which looks like the context isn't included when aliasing (or shouldn't be included in the comparison - not sure which).