json-schema-ref-parser icon indicating copy to clipboard operation
json-schema-ref-parser copied to clipboard

Root ref fails to parse

Open isaacl opened this issue 4 years ago • 2 comments

{
  "$ref": "#/definitions/EmailConfig",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "EmailConfig": {
      "additionalProperties": false,
      "properties": {
        "adminContact": {
          "type": "string"
        }
      }
    }
  }
}

is valid (in fact is part of the test suite here). But json-schema-to-typescript fails to resolve the ref using this library.


Originally filed at bcherny/json-schema-to-typescript#349

isaacl avatar Dec 17 '20 12:12 isaacl

@isaacl Yes I faced the same issue, it gives 'Circular $ref pointer found ...' error even though this is a valid case.

vinyasns avatar Jul 15 '21 18:07 vinyasns

This also fails for me but just incorrectly resolves the reference instead of failing with a circular ref pointer error. I believe that my issue is due to this check in Pointer::resolve:

if (typeof this.value === "object" && this.value !== null && "$ref" in this.value) {
  return this;
}

This causes any reference at the top level to resolve to a pointer to the root instead of falling through to resolve the reference properly.

Is this check necessary? It seems that this will prevent correct pointer resolution for any schema with a top-level reference.

abrgr avatar Jun 10 '22 14:06 abrgr

If this is still an issue please can somebody send a pull request.

philsturgeon avatar Nov 26 '22 13:11 philsturgeon