Skip to content

Syntax erro - Pointers must begin with "#/" #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MrRoyce opened this issue Jul 17, 2017 · 10 comments
Closed

Syntax erro - Pointers must begin with "#/" #42

MrRoyce opened this issue Jul 17, 2017 · 10 comments

Comments

@MrRoyce
Copy link

MrRoyce commented Jul 17, 2017

Hi there, I just started getting this error today. Not sure what changed or how to fix it.

json-schema-ref-parser-syntax-error

Any ideas?

@JamesMessinger
Copy link
Member

This error means that you have an invalid $ref somewhere in your schema. Without actually seeing your schema, I can't get any more specific than that.

@n1ywb
Copy link

n1ywb commented Jul 28, 2017

This is a valid bug; it violates the spec WRT internal links. Internal links are not necessarily JSON pointers.

$ node -e 'require("json-schema-ref-parser").dereference({"$ref": "#bar", "definitions": {"bar": {"$id": "#bar"}}}).then(s=>console.log(s))'
(node:17237) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): 
SyntaxError: Invalid $ref pointer "bar". Pointers must begin with "#/"

$ ajv -d <(echo null) -s <(echo '{"$ref": "#bar", "definitions": {"bar": {"$id": "#bar"}}}')
/dev/fd/63 valid

ajv gets it right

see also

http://json-schema.org/latest/json-schema-core.html#rfc.section.9.2 $id

"To name subschemas in a JSON Schema document, subschemas can use "$id" to give themselves a document-local identifier. This is done by setting "$id" to a URI reference consisting only of a fragment. The fragment identifier MUST begin with a letter ([A-Za-z]), followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), or periods (".")."

http://json-schema.org/latest/json-schema-core.html#rfc.section.9.2.1 Internal links

"Schemas can be identified by any URI that has been given to them, including a JSON Pointer or their URI given directly by "$id".

Tools SHOULD take note of the URIs that schemas, including subschemas, provide for themselves using "$id". This is known as "Internal referencing"."

http://json-schema.org/latest/json-schema-core.html#rfc.section.5 Fragment identifiers

"plain name fragment identifiers 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."

@n1ywb
Copy link

n1ywb commented Jul 31, 2017

as a stopgap the program could simply ignore internal refs. Not ideal but better than crashing.

@n1ywb
Copy link

n1ywb commented Aug 1, 2017

Example dereferencing local refs

      _walkSchema(schema, accum) {
        return _.reduce(Object.entries(schema), (a, [k, v])=>{
          if (k === '$id') a.ids[v] = a.parent;
          k === '$ref' && a.refs.push(a.parent);
          if (v && typeof v == "object") {
            let oldParent = a.parent;
            a.parent = v;
            let r = this._walkSchema(v, a)
            a.parent = oldParent;
            return r;
          }
          return a;
        }, accum);
      }

      _derefLocal(schema) {
        let stuff = this._walkSchema(
          schema,
          {parent: schema, ids: {}, refs: []}
        );
        stuff.refs.forEach(ref=>{
          if (ref.$ref[0] === '#' && ref.$ref[1] !== '/') {
            _.assign(ref, stuff.ids[ref.$ref]);
            delete ref.$id;
            delete ref.$ref;
          }
        })
        console.log(stuff);
        return schema;
      }

@n1ywb
Copy link

n1ywb commented Aug 2, 2017

this seems to duplicate #17

@JamesMessinger
Copy link
Member

I intend to support inline references in the next version of JSON Schema $Ref Parser, which I have already begun working on. 👍

In the meantime, I will implement @n1ywb's stopgap recommendation of ignoring these references.

JamesMessinger added a commit that referenced this issue Aug 9, 2017
@JamesMessinger
Copy link
Member

I just published version 3.3.1, which includes the stopgap fix that @n1ywb suggested

@iilei
Copy link

iilei commented Feb 27, 2019

6.1.0 has the same bug

@jrnail23
Copy link

I think this might also be related to #136

@Envek
Copy link

Envek commented Oct 28, 2020

Faced it today in 9.0.6 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants