Skip to content

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

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

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

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 APIDevTools#440

This branch has not been deployed

No deployments
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

1 participant