-
-
Notifications
You must be signed in to change notification settings - Fork 221
Description
I have been seeing this a lot recently:
"$ref": "common.json#properties/version"
However, according to the JSON pointer spec, JSON Pointers are supposed to start with /
. According to the JSON Schema spec, if the fragment isn't a JSON Pointer, it is supposed to be treated as a named schema and therefore reference something with $id
set, not a path.
The proper form for a JSON pointer would be:
"$ref": "common.json#/properties/version"
(note the /
after the #
).
The first example would point to a named schema, however according to the spec, schema identifiers are prohibited from container the /
character:
Using JSON Pointer fragments requires knowledge of the structure of
the schema. When writing schema documents with the intention to
provide re-usable schemas, it may be preferable to use a plain name
fragment that is not tied to any particular structural location.
This allows a subschema to be relocated without requiring JSON
Pointer references to be updated.To specify such a subschema identifier, the "$id" keyword is set to a
URI reference with a plain name fragment (not a JSON Pointer
fragment). This value MUST begin with the number sign that specifies
a fragment ("#"), then a letter ([A-Za-z]), followed by any number of
letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons
(":"), or periods (".").The effect of using a fragment in "$id" that isn't blank or doesn't
follow the plain name syntax is undefined. [[CREF3: How should an
"$id" URI reference containing a fragment with other components be
interpreted? There are two cases: when the other components match
the current base URI and when they change the base URI. ]]
Although it would seem like the last paragraph leaves a little room for interpretation.