json-schema-org / json-schema-spec

The JSON Schema specification

Home Page:http://json-schema.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Evaluation path: relative to $ref resolved schema or resource/document root?

notEthan opened this issue · comments

After traversing a $ref that contains a fragment, does the evaluation path of the resolved schema include the path between the document or resource root and the subschema indicated by the fragment?

Given, for example, this schema:

{
  "$ref": "A#/$defs/B",
  "$defs": {
    "A": {
      "$id": "A",
      "$defs": {
        "B": {
          "allOf": [
            false
          ]
        }
      }
    }
  }
}

For the referenced false schema that ultimately causes any instance to fail validation, is its evaluation path:
/$ref/$defs/A/$defs/B/allOf/0 - with its pointer relative to the referenced schema's document root
or
/$ref/$defs/B/allOf/0 - with its pointer relative to the referenced schema's resource root
or
/$ref/allOf/0 - with its pointer relative to the referenced schema
?

I opened this as an issue rather than a discussion because the spec seems to say nothing on this and, in my opinion, should.

The current text (for the upcoming verion) is:

Evaluation path

The evaluation path is the set of keys, starting from the schema root, through
which evaluation passes to reach the schema object that produced a specific
result. The value MUST be expressed as a JSON Pointer, and it MUST include any
by-reference applicators such as $ref or $dynamicRef.

/properties/width/$ref/allOf/1

Note that this pointer may not be resolvable on the root schema by the normal
JSON Pointer process. It is intended as an indication of the traversal path
only.

When represented in JSON, the key for this information MUST be "evaluationPath".

What's unclear to you?

The evaluation path follows through the $ref and continues at its target. It doesn't contain navigation to the target; it assumes a jump. So here, you'd get the last option you show: /$ref/allOf/0.

The current text

Yes, I did read the spec, thank you.

What's unclear to you?

I don't see anything in the spec addressing whether the evaluation path includes the path between $ref's resolved resource root and the schema resolved from a fragment (or even between document root and schema, though I presume not, included in the question to consider all plausible options). Stated another way, whether evaluating an anchor or pointer fragment of the $ref is considered "evaluation" for the evaluation path. The only evaluation path example using $ref in the spec points to the resource and document root.

The evaluation path follows through the $ref and continues at its target. It doesn't contain navigation to the target; it assumes a jump. So here, you'd get the last option you show: /$ref/allOf/0.

That answer makes the most sense to me, though I can also see the pointer to the fragment being useful information to include, especially for an anchor fragment. I think the spec should be clearer on this.

Yes, I did read the spec, thank you.

I was uncertain whether you were looking at 2020-12 or what's in master.

though I can also see the pointer to the fragment being useful information to include

I think you're wanting the keyword location, which is the dereferenced location and includes the base URI.

Keyword location gives you where you are; evaluation path gives you how you got there.