Skip to content

fix: point repeat refs under a nested $id from that resource - #437

Closed
azyl20 wants to merge 3 commits into
APIDevTools:mainfrom
azyl20:fix/bundle-nested-id-local-root
Closed

azyl20 wants to merge 3 commits into
APIDevTools:mainfrom
azyl20:fix/bundle-nested-id-local-root

Conversation

@azyl20

@azyl20 azyl20 commented Nov 12, 2026 •

Copy link
Copy Markdown

closes #438

Summary

If an external file has a $id and refers to the same schema twice, bundle() writes the second ref with the root's local file path in front, so the bundle breaks anywhere else. When the target is inside the same $id resource as the ref, this writes it as a pointer from that resource instead (for example #/properties/test1), which needs no URI and keeps the $id. Refs whose target is outside the resource are qualified as before.

Not covered

A ref inside a nested $id whose target was inlined outside that resource, with no root $id, still gets the root's file path. Nothing portable can point there without removing the nested $id, so that's left for a separate, opt-in change if it's wanted.

Verification

  • pnpm build, pnpm typecheck, pnpm lint
  • Node suite: 715 passed, 6 skipped
  • Browser suite: 645 passed, 51 skipped
  • New bundle-id-refs-no-root-id spec: repeat refs under one $id and under a $id nested in another, a URI ref to the resource, and a target outside the resource. The portable cases also dereference without the source files.
  • Bundled ~640 OpenAPI and JSON Schema documents before and after; only ones with this shape changed

🤖 Generated with Claude Code

azyl20 and others added 2 commits November 12, 2026 12:25
…d `$id`

When the root has no `$id`, repeat refs under an external file's `$id` were
qualified with the root's local file path, so the bundle only resolved on the
machine that made it. Rewrite those refs, and fragment refs under the same
`$id`, as pointers from the document root and remove that `$id`. Groups that
use a URI or anchor ref, or whose `$id` a URI ref may target, are left as is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Instead of rewriting refs and removing the nested $id after bundling, record
where each nested $id resource sits and, when a repeat ref's target is inside
that resource, write it as a pointer from the resource. That needs no URI, so
the bundle no longer carries the root's local file path and keeps its $ids.
Targets outside the resource are still qualified as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@azyl20 azyl20 changed the title fix: keep bundled refs portable when the root has no $id fix: point repeat refs under a nested $id from that resource Nov 12, 2026
@azyl20

azyl20 commented Nov 12, 2026 •

Copy link
Copy Markdown
Author

@jonluca any feedback on closing this? Have also created the issue #438, my bad for not doing that earlier.

EDIT: Saw your recent commit and have updated that issue

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() writes the root's local file path into repeat refs under a nested $id

2 participants