Skip to content

fix: accumulate remote schema diagnostics instead of overwriting (#116) - #119

Open
Adityakumar37 wants to merge 1 commit into
sagold:mainfrom
Adityakumar37:fix/116-remote-schema-diagnostics
Open

fix: accumulate remote schema diagnostics instead of overwriting (#116)#119
Adityakumar37 wants to merge 1 commit into
sagold:mainfrom
Adityakumar37:fix/116-remote-schema-diagnostics

Conversation

@Adityakumar37

Copy link
Copy Markdown
Contributor

Fixes #116

Problem

compileSchema's main compilation path accumulates schemaErrors / schemaAnnotations
correctly, but addRemoteSchema (called once per entry in options.remotes) overwrote
node.schemaErrors / node.schemaAnnotations on every call instead of appending to them.
It also never set error.data.schemaId, unlike the root compilation path.

As a result, registering multiple remotes only kept the last remote's diagnostics, and any
surviving error had schemaId: undefined — losing provenance and potentially letting invalid
remotes slip past throwOnInvalidSchema.

Fix

In SchemaNode.tsaddRemoteSchema:

  • Each error/annotation is now tagged with error.data.schemaId, resolved from the remote's
    own $id (falling back to the resolved url), matching how compileSchema tags root
    schema errors.
  • node.schemaErrors / node.schemaAnnotations are now accumulated via .concat(...)
    instead of being reassigned, so registering multiple remotes retains all of their
    diagnostics.

Tests

Added src/tests/issues/issue116.remoteSchema.diagnostics.test.ts:

  • Regression test: two invalid remotes → both errors are retained, with correct pointers
    and schemaIds.
  • Control test: a single invalid remote still reports correctly (same as before the fix).

Verification

  • Reproduced the exact repro script from the issue now returns both errors with correct
    schemaIds instead of just the last one.
  • Full test suite passes with no new failures introduced (verified against a clean baseline
    with the fix stashed out).

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

Successfully merging this pull request may close these issues.

Adding a remote overwrites earlier remote schema diagnostics

1 participant