Repository navigation
Report a root $ref onto a keyword value as not a JSON Schema, not as a missing pointer - #883
Draft
claude[bot] wants to merge 1 commit into
Draft
claude[bot] wants to merge 1 commit into
claude[bot] wants to merge 1 commit into
Conversation
…s a missing pointer A schema whose root `$ref` is a pointer onto a keyword's value in the same document (`#/definitions/unit/default`) used to fail with the ref-parser's `MissingPointerError: … Token "definitions" does not exist`, which is wrong: `definitions` exists. The ref-parser (16 on) follows the root's own `$ref` while walking that very pointer's tokens, lands on the string and fails the next token, so the non-schema-target guard in `dereference` never saw the value. It now judges the root's pointer itself before either dereferencing route, with the same message every other position gets: $ref "#/definitions/unit/default" at the root resolves to the string "metres", which is not a JSON Schema. A root pointer that leads nowhere still reports the ref-parser's MissingPointerError. The pointer walk `resolveRootRef` already used moves to `inDocumentPointerValue` so both callers read the same value.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A schema whose root
$refis a JSON Pointer onto a keyword's value in the same document now fails with the message every other position already gets, instead of a wrong "missing pointer". The schema is still rejected; only the error changes. No generated output changes.Before (master, since the ref-parser 16 upgrade in #842):
definitionsexists; the pointer leads to the string"metres".After:
for
{"$ref": "#/definitions/unit/default", "definitions": {"unit": {"type": "string", "default": "metres"}}}A root pointer that leads nowhere (
#/definitions/nope) still reports the ref-parser'sMissingPointerError, as before.Why
resolveRootRef(prenormalizer) merges a root$refinto the root when it leads to a schema in the same document, and leaves anything else to the ref-parser. Ref-parser 16 follows the root's own$refwhile walking that very pointer's tokens, lands on the string, and fails on the next token inside its own resolution, so the non-schema-target guard added in #877 never sees the value. Ref-parser 11 handed the string to the guard, which is why master before #842 printed the right message.How
dereference()(resolver) now looks the root's#/…pointer up itself before either dereferencing route. A defined target that is not an object or boolean is rejected through the existingrejectNonSchemaTargets, so the wording, the second line and theReferenceErrortype are the same as for a property. An undefined target is still left to the ref-parser (MissingPointerError).resolveRootRefalready had (own keys only,~0/~1and percent decoding) moves to an exportedinDocumentPointerValue, so both callers read the same value; no behaviour change there.refToNonSchemaValue.root.tsbesiderefToNonSchemaValue.ts; it fails on master and passes here.External files and non-root
$refs are untouched: a root$refto a file, a pointer into a file, and pointers below the root already got #877's message and still do.Tests
CI=true bun run test: 681 pass, 0 fail, 351 snapshots (master 5caacfc: 680 / 0 / 351). No.snapfile changes.node test/corpus/run.js --e2e --out …) on master and this head: 78 outputs byte-identical, 0 diagnostics.$refs onto non-schema values in every schema position, run on master and this head: identical on 124 rows; the one that changes is the root in-document pointer (MissingPointerError→ the message above). A 25-row two-route probe of the resolver's hook sequence: identical on 24 rows, the same one changes.minLength),null(default: null), anenumitem, an escaped key (a~1b), a two-hop chain ending on a value, atitlesibling, the$RefParserroute ($refOptions.dereference.circular), andcompileFileswith such a root: each gives the message above. Root pointer ontotrue/false, onto a schema, and onto a missing key: unchanged.Changelog
$refpointing at a keyword's value in the same document (#/definitions/unit/default) is now reported as "resolves to the string …, which is not a JSON Schema" instead of a misleadingMissingPointerError.