Skip to content

fix: don't remap refs onto an extended ref's sibling keys when bundling - #441

Closed
bardrop wants to merge 1 commit into
APIDevTools:mainfrom
bardrop-oss:fix/bundle-extended-ref-sibling-leak
Closed

bardrop wants to merge 1 commit into
APIDevTools:mainfrom
bardrop-oss:fix/bundle-extended-ref-sibling-leak

Conversation

@bardrop

@bardrop bardrop commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Fixes #440.

Problem. In remap(), the first $ref to a target is inlined and every later $ref to the same target (or to a path inside it) is pointed at that spot. When the first one is an extended $ref, it is inlined merged with its siblings, so:

  • a second extended $ref to the same target resolves to the target plus the first ref's siblings (the issue's repro: B.properties.status gets description: "A status" from A);
  • a $ref to a sub-path under one of those sibling keys (e.g. person.json#/properties/name when the first ref has its own properties.name) resolves to the merged value, not the target's.

The sort already puts plain refs before extended ones, so this only happens when every ref to that target is extended (or the sub-path one is the only other).

Change. remap() now keeps the sibling keys of the inlined $ref. If it has any:

  • a later $ref with the same target is inlined too (it becomes the next head);
  • a later sub-path $ref whose first token is one of those keys is inlined too.

Sub-paths under keys the extended ref doesn't touch are still remapped as before, so bundles don't grow in the normal case.

Tests. New test/specs/bundle-regressions/extended-ref-siblings.spec.ts (in-memory resolver):

  • the issue's two extended refs to status.json
  • a sub-path $ref beneath a key the extended $ref overrides
  • a sub-path $ref beneath an untouched key is still remapped to #/$defs/A/properties/name

Each checks that dereference(bundle) equals dereference(files). The first two fail on main and pass now. Full vitest run (91 files, 746 passed), pnpm lint, pnpm typecheck and oxfmt --check pass.

An extended $ref is inlined merged with its siblings, so another $ref to
the same target (or to a path under one of those sibling keys) can't
be pointed at it. Inline those refs instead.

Fixes #440
@bardrop

bardrop commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Friendly ping on this one. It still merges cleanly; the workflow needs an approval to run.

@jonluca

jonluca commented Nov 24, 2026

Copy link
Copy Markdown
Member

Thanks for the fix and regression tests. We used them in 66148af on our local main branch and added coverage for recursive references and shared schema IDs. Each reference keeps its own sibling properties, and the recursive bundle can be serialized and reopened without the source files. Closing this PR in favor of that commit.

@jonluca jonluca closed this Nov 24, 2026
jonluca added a commit that referenced this pull request Nov 24, 2026
Preserve the unmodified target when extended references are recursive or share a schema identifier. Keep each caller’s sibling properties local and retain a serializable bundle that can be dereferenced offline.

Refs #440, #441

Co-authored-by: Mradul Singh <msingh@dealmeridian.com>
@bardrop

bardrop commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, good to see it covers recursive references too.

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.

bundle() points an extended $ref at another extended $ref, so sibling keys leak between them

2 participants