digitalbazaar / jsonld.js

A JSON-LD Processor and API implementation in JavaScript
https://json-ld.org/
Other
1.66k stars 195 forks source link

Accessing expansionMap when there are no unmapped properties #398

Open gjj opened 4 years ago

gjj commented 4 years ago

Hello! I wanted to check if it's possible to access info in the expansionMap in compact when there are no unmapped properties?

To provide some context: I'm currently working on a W3C Verifiable Credentials-related project and in one of our validations, we had to check for every value in type as shown below, whether it can be mapped to any of the @contexts.

{
    "@context": [
        "https://www.w3.org/2018/credentials/v1",
        "https://link.to/our/DrivingLicenceCredentialContext.jsonld"
    ],
    "type": ["VerifiableCredential", "DrivingLicenceCredential"],
    ...
    // Removed for brevity
}

The catch here is that we found out that expansionMap only shows up when there are unmapped properties, but not values. For example, only in the case below then we can access expansionMap assuming that someRandomProperty cannot be mapped to any of the @contexts.

{
    "@context": [
        "https://www.w3.org/2018/credentials/v1",
        "https://link.to/our/DrivingLicenceCredentialContext.jsonld"
    ],
    "type": ["VerifiableCredential", "DrivingLicenceCredential"],
    "someRandomProperty": "not found in any of the contexts above"
    ...
    // Removed for brevity
}

So... is there an alternative way for us to access activeCtx.mappings that's found in info in this case?

dlongley commented 4 years ago

So, currently, the answer is no. But this is an interesting feature request as this issue has come to bite multiple people in the VC community. We may want the unmapped API to get triggered when a base URI is not set and an undefined base-relative value is found (and perhaps we should also add a flag to forcibly call the API even if a base URI is set in this case).

This should be looked into when implementing a fix for #199.

PRs welcome. @davidlehn - do you know of any workarounds for this at the moment?

gjj commented 4 years ago

@dlongley thank you for the clarifications!

Linking this to https://github.com/w3c/vc-test-suite/issues/96 and https://github.com/w3c/vc-test-suite/issues/97, in case anyone else who implements it this way also encounter the same issue.