JSON-LD Context fails to compact
The spdx-context https://spdx.org/rdf/3.0.1/spdx-context.jsonld fails to compact correctly when being processed with standard json-ld tools such as jsonld-cli. Take for example: spdx-examples/example1.json.
curl -LO https://raw.githubusercontent.com/spdx/spdx-examples/refs/heads/master/software/example1/spdx3.0/example1.json
npm install -g jsonld-cli
jsonld expand example1.json | jsonld compact - -c "https://spdx.org/rdf/3.0.1/spdx-context.jsonld" > example1-expandcompact.json
After expanding and compacting the spdx document we obtain example1-expandcompact.json. This file should be equivalent to the original. However I noticed the following issues:
verifiedUsingandexternalIdentifierare compacted incorrectly, e.g.,verifiedUsing-expand->https://spdx.org/rdf/3.0.1/terms/Core/verifiedUsing-compact->spdx:Core/verifiedUsinginstead ofverifiedUsing.- Array values with only one Element get lost, e.g.,
"rootElement": ["https://swinslow.net/spdx-examples/example1/hello-v3-specv3/SPDXRef-gnrtd4"]-expand->"https://spdx.org/rdf/3.0.1/terms/Core/rootElement": [{"@id": "https://swinslow.net/spdx-examples/example1/hello-v3-specv3/SPDXRef-gnrtd4"}]-compact->"rootElement": "https://swinslow.net/spdx-examples/example1/hello-v3-specv3/SPDXRef-gnrtd4". - The
@idproperty ofCreationInfoelements gets replaced byspdxIdproperty.
The first two issues could be fixed by updating the spdx context, from
"rootElement": {
"@id": "https://spdx.org/rdf/3.0.1/terms/Core/rootElement",
"@type": "@vocab"
},
"verifiedUsing": {
"@id": "https://spdx.org/rdf/3.0.1/terms/Core/verifiedUsing",
"@type": "@vocab"
}
to
"rootElement": {
"@id": "https://spdx.org/rdf/3.0.1/terms/Core/rootElement",
"@type": "@vocab",
"@container": "@set"
},
"verifiedUsing": {
"@id": "https://spdx.org/rdf/3.0.1/terms/Core/verifiedUsing",
"@container": "@set"
}
In general that is:
"@container": "@set"should be added to all array properties"@type": "@vocab"should be removed from properties with object values. (I am not sure what the correct@typewould be but@vocabseems to be wrong)
For the third issue I don't know how it could be fixed.
@zvr - Is this something that can be fixed in the spec parser?
@augelu-tng - Do you think this is a high enough priority for the 3.0.2 release or would fixing this in 3.1 be OK?
@goneall as you prefer. From my end, fixing it in 3.1 is totally fine.
"@type": "@vocab"should be removed
I also posted thus yesterday: https://github.com/spdx/spdx-3-model/issues/1167 .
Should be replaced with "@type": "@id"
Joshua thinks that @container: @set wouldn't be too hard. Willing to point at tool for where solution should be applied. We could add test to do compaction and extraction to test equivalence.