w3c / json-ld-api

JSON-LD 1.1 Processing Algorithms and API Specification
https://w3c.github.io/json-ld-api/
Other
77 stars 31 forks source link

Nested contexts behavior #590

Closed davidlehn closed 8 months ago

davidlehn commented 9 months ago

How should a nested context behave?

{
  "@context": {
    "@context": {
      "p": "ex:p"
    }
  },
  "@id": "ex:1",
  "p": "value"
}

jsonld.js will expand to:

[
  {
    "@id": "ex:1",
    "ex:p": [
      {
        "@value": "value"
      }
    ]
  }
]

Ruby Distiller errors:

error
JSON::LD::JsonLdError::InvalidTermDefinition
invalid term definition: Term definition for "@context" has unexpected keys: p

Sophia errors:

Source failed: error while expanding: Expansion failed: Invalid context: Invalid term definition

If this isn't undefined behavior, there should be a positive or negative test for this case.

gkellogg commented 9 months ago

It is explicitly not allowed. Specific keywords in @context are called out in the context processing algorithm, everything else is a term definition. For a term definition @type is accounted for and no other keywords are allowed.

I suspect there are some tests for this, but maybe not for @context. I would be fine if such a negative test were added.

davidlehn commented 9 months ago

Added a test in #591. I think 4.2.2.5 is the relevant spec text. Looks like jsonld.js is recursively processing objects, and pulling out the @context data if present. Works well to handle both regular context data and files with a @context key. If this is an error, it does need a test. I'm surprised this wasn't noticed before.

davidlehn commented 8 months ago

Addressed with test for correct behavior: https://github.com/w3c/json-ld-api/pull/591.