Skip to content

fix(json-schema-ref-parser): use synthetic root path in mergeMany to avoid $ref collision#4147

Merged
mrlubos merged 2 commits into
mainfrom
pullfrog/4146-pointer-resolve-mergemany-crash
Jun 24, 2026
Merged

fix(json-schema-ref-parser): use synthetic root path in mergeMany to avoid $ref collision#4147
mrlubos merged 2 commits into
mainfrom
pullfrog/4146-pointer-resolve-mergemany-crash

Conversation

@pullfrog

@pullfrog pullfrog Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Fixes #4146 #4112.

$RefParser.mergeMany() previously stored the merged schema under the first input's path. That overwrote the $refs entry for that file, so when another input contained an external $ref back to the same file, pointer resolution ran against the merged (prefixed) schema and crashed.

This change stores the merged root under a synthetic path (/__merged__) so the original input files remain in $refs and external references are resolved from their true source.

  • Changed mergeMany() root path in packages/json-schema-ref-parser/src/index.ts
  • Added a regression test covering the cross-file $ref crash in packages/json-schema-ref-parser/src/__tests__/bundle.test.ts

Pullfrog  | View workflow run | via Pullfrog | Using openrouter/moonshotai/kimi-k2.7-code (free via Pullfrog for OSS) | 𝕏

@bolt-new-by-stackblitz

Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@pullfrog pullfrog Bot requested a review from mrlubos June 23, 2026 19:17
@vercel

vercel Bot commented Jun 23, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
web Ready Ready Preview, Comment Jun 24, 2026 7:15am

Request Review

@changeset-bot

changeset-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2953324

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@hey-api/json-schema-ref-parser Patch
@hey-api/openapi-python Patch
@hey-api/openapi-ts Patch
@hey-api/shared Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jun 23, 2026

Copy link
Copy Markdown

Open in StackBlitz

@hey-api/codegen-cli

npm i https://pkg.pr.new/@hey-api/codegen-cli@4147

@hey-api/codegen-core

npm i https://pkg.pr.new/@hey-api/codegen-core@4147

@hey-api/json-schema-ref-parser

npm i https://pkg.pr.new/@hey-api/json-schema-ref-parser@4147

@hey-api/nuxt

npm i https://pkg.pr.new/@hey-api/nuxt@4147

@hey-api/openapi-python

npm i https://pkg.pr.new/@hey-api/openapi-python@4147

@hey-api/openapi-ts

npm i https://pkg.pr.new/@hey-api/openapi-ts@4147

@hey-api/shared

npm i https://pkg.pr.new/@hey-api/shared@4147

@hey-api/spec-types

npm i https://pkg.pr.new/@hey-api/spec-types@4147

@hey-api/types

npm i https://pkg.pr.new/@hey-api/types@4147

@hey-api/vite-plugin

npm i https://pkg.pr.new/@hey-api/vite-plugin@4147

commit: 2953324

@codecov

codecov Bot commented Jun 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 37.12%. Comparing base (52f9566) to head (2953324).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4147      +/-   ##
==========================================
+ Coverage   37.00%   37.12%   +0.12%     
==========================================
  Files         679      679              
  Lines       23836    23835       -1     
  Branches     7163     7147      -16     
==========================================
+ Hits         8820     8849      +29     
+ Misses      12079    12056      -23     
+ Partials     2937     2930       -7     
Flag Coverage Δ
unittests 37.12% <100.00%> (+0.12%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…avoid $ref collision

Storing the merged schema under the first input's path overwrote that
file's $refs entry. When another input referenced the same file, pointer
resolution ran against the prefixed merged schema and crashed. Using a
synthetic root path (/__merged__) prevents the collision so external refs
are resolved from the original source.

Fixes #4146
@mrlubos mrlubos force-pushed the pullfrog/4146-pointer-resolve-mergemany-crash branch from 83902bb to 184666e Compare June 24, 2026 07:03
@mrlubos mrlubos merged commit 3830522 into main Jun 24, 2026
12 checks passed
@mrlubos mrlubos deleted the pullfrog/4146-pointer-resolve-mergemany-crash branch June 24, 2026 07:22
@hey-api hey-api Bot mentioned this pull request Jun 24, 2026
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.

Crash report: "Cannot read properties of null (reading 'properties')" - spec order dependence

1 participant