Description
Given the following malformed reference:
"$ref": "common.json#properties/version"
jsonschema is resolving it as if it were a JSON Pointer. However, it is not, since according to section 3 of RFC 6901, JSON Pointers always begin with a leading /
:
A JSON Pointer is a Unicode string (see [RFC4627], Section 3)
containing a sequence of zero or more reference tokens, each prefixed
by a '/' (%x2F) character.
However, it can't be resolved as a subschema identifier either because subschema identifiers use plain-named fragments and don't allow /
in the fragment.
See section 8.2.3 of the draft 7 spec of JSON Schema:
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 (".").
As well as section 5:
Per the W3C's best practices for fragment identifiers
[W3C.WD-fragid-best-practices-20121025], plain name fragment
identifiers in "application/schema+json" are reserved for referencing
locally named schemas. All fragment identifiers that do not match
the JSON Pointer syntax MUST be interpreted as plain name fragment
identifiers.
The syntactically correct form of the first example would be:
"$ref": "common.json#/properties/version"
(notice the /
after the #
)
or
"$ref": "common.json#properties"
where some subschema has "$id": "#properties"
.
If I understand the code correctly, some changes are needed in the ref
function in _validators.py
, so to parse the value and determine if it s a JSON Pointer, a subschema identifier, or a URI reference.
Section 8.2.4 of the JSON Schema spec has some good examples.