json-schema-ref-parser
json-schema-ref-parser copied to clipboard
Root ref fails to parse
{
"$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 Yes I faced the same issue, it gives 'Circular $ref pointer found ...' error even though this is a valid case.
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.
If this is still an issue please can somebody send a pull request.