digitalbazaar / jsonld.js

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

Mapping id to urn:uuid #385

Open about-code opened 4 years ago

about-code commented 4 years ago

RFC 2141 specifies the URN syntax as

<URN> ::= "urn:" <NID> ":" <NSS>

where NID is the namespace identifier and NSS is the namespace string. RFC 4122 specifies a URN for UUIDs where NID for UUIDs is uuid. So a Universal Resource Name for uuids looks like

urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6

The following example in json-ld Playground should produce above UUID URN as the subject URN. Yet it only produces a URN missing the namespace identifier:

urn:f81d4fae-7dec-11d0-a765-00a0c91e6bf6

{
  "@context": {
    "@base": "urn:uuid:",
    "@vocab": "http://schema.org/"
  },
  "@type": "Person",
  "@id": "f81d4fae-7dec-11d0-a765-00a0c91e6bf6",
  "name": "Jane Doe",
  "jobTitle": "Professor",
  "telephone": "(425) 123-4567",
  "url": "http://www.janedoe.com"
}
about-code commented 4 years ago

Might be a duplicate of https://github.com/digitalbazaar/jsonld.js/issues/305

about-code commented 4 years ago

Appendix A of the URN spec tells how URL resolvers are supposed to handle URNs. From a layman's perspective I tend to think the appendix shouldn't be of relevance to jsonld.js, yet I could be wrong and wonder whether this might be part of the reasoning behind the current implementation.

https://tools.ietf.org/html/rfc2141.html#appendix-A

Appendix A. Handling of URNs by URL resolvers/browsers.

The URN syntax has been defined so that URNs can be used in places where URLs are expected. A resolver that conforms to the current URL syntax specification [3] will extract a scheme value of "urn:" rather than a scheme value of "urn:<nid>".

An URN MUST be considered an opaque URL by URL resolvers and passed (with the "urn:" tag) to an URN resolver for resolution. The URN resolver can either be an external resolver that the URL resolver knows of, or it can be functionality built-in to the URL resolver.

To avoid confusion of users, an URL browser SHOULD display the complete URN (including the "urn:" tag) to ensure that there is no confusion between URN namespace identifiers and URL scheme identifiers.