Skip to content

fix(deps): update dependency @apidevtools/json-schema-ref-parser to v15 - #1429

Merged
pmcelhaney merged 19 commits into
mainfrom
renovate/apidevtools-json-schema-ref-parser-15.x
May 5, 2026
Merged

fix(deps): update dependency @apidevtools/json-schema-ref-parser to v15#1429
pmcelhaney merged 19 commits into
mainfrom
renovate/apidevtools-json-schema-ref-parser-15.x

Conversation

@renovate

@renovate renovate Bot commented Nov 15, 2025

Copy link
Copy Markdown
Contributor

Summary

Upgrades @apidevtools/json-schema-ref-parser from 13.0.5 to 15.1.3 and fixes two breaking changes introduced by v15:

  1. Localhost/internal URL blocking: v15 added a security fix that blocks HTTP requests to internal/localhost URLs by default (safeUrlResolver: true). Counterfact legitimately needs to load OpenAPI specs from localhost, so safeUrlResolver: false is passed to bundle() in specification.ts.

  2. Windows path handling: v15's internal isAbsoluteWin32Path regex (/^[a-zA-Z]:\\/) only matches paths with backslashes. When paths are normalized to forward slashes (e.g., C:/Users/...), the library incorrectly treats them as relative paths and prepends the CWD. Fixed by patching the library via patch-package to change the regex to /^[a-zA-Z]:[/\\]/, recognizing both C:\... and C:/... as absolute Windows paths.

Original Prompt

This PR contains the following updates:

Package Change
@apidevtools/json-schema-ref-parser 13.0.515.1.3

Change needed to fix this: APIDevTools/json-schema-ref-parser#405

Manual acceptance tests

  • Look into the patched dependency. That's probably not ideal. Open a bug on the dependency repo if it makes sense.
  • Running npx counterfact@latest https://petstore3.swagger.io/api/v3/openapi.json api generates route files without errors
  • Loading an OpenAPI spec from a localhost URL (e.g., a locally running API server) resolves correctly without throwing a SyntaxError
  • Loading an OpenAPI spec from a local file path works as before on both Windows and Unix
  • Loading an OpenAPI spec from a remote public URL works as before
  • Existing generated route files and server behavior are unchanged after upgrading the dependency
  • The /counterfact/openapi endpoint correctly serves the OpenAPI document with the injected Counterfact server entry

Tasks

  • Updated @apidevtools/json-schema-ref-parser from 13.0.5 to 15.1.3 in package.json
  • Passed { resolve: { http: { safeUrlResolver: false } } } to bundle() in src/typescript-generator/specification.ts to allow localhost URL resolution (file was converted from .js to .ts as part of a broader TypeScript migration in main)
  • Added a patch-package patch (patches/@apidevtools+json-schema-ref-parser+15.1.3.patch) to fix the isAbsoluteWin32Path regex from /^[a-zA-Z]:\\/ to /^[a-zA-Z]:[/\\]/, so forward-slash Windows paths (C:/...) are correctly detected as absolute rather than having the CWD prepended
  • Resolved merge conflicts with main, which had migrated src/typescript-generator/specification.jsspecification.ts as part of a full TypeScript conversion of the typescript-generator/ directory

@renovate
renovate Bot enabled auto-merge (squash) November 15, 2025 10:06
renovate-approve[bot]
renovate-approve Bot previously approved these changes Nov 15, 2025
@changeset-bot

changeset-bot Bot commented Nov 15, 2025

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7a666fb

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

This PR includes changesets to release 1 package
Name Type
counterfact 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

@renovate
renovate Bot force-pushed the renovate/apidevtools-json-schema-ref-parser-15.x branch from 8195bf3 to 0946f0e Compare November 15, 2025 18:49
renovate-approve[bot]
renovate-approve Bot previously approved these changes Nov 15, 2025
@renovate
renovate Bot force-pushed the renovate/apidevtools-json-schema-ref-parser-15.x branch 2 times, most recently from ab97967 to 11b2ac7 Compare November 18, 2025 10:40
@renovate
renovate Bot force-pushed the renovate/apidevtools-json-schema-ref-parser-15.x branch from 11b2ac7 to cf2f130 Compare November 19, 2025 21:52
renovate-approve[bot]
renovate-approve Bot previously approved these changes Nov 19, 2025
@renovate
renovate Bot force-pushed the renovate/apidevtools-json-schema-ref-parser-15.x branch 8 times, most recently from e27ede5 to 08299c3 Compare November 29, 2025 05:41
@renovate
renovate Bot force-pushed the renovate/apidevtools-json-schema-ref-parser-15.x branch 4 times, most recently from 1ccfbf1 to 4f67810 Compare December 2, 2025 21:56
@renovate
renovate Bot force-pushed the renovate/apidevtools-json-schema-ref-parser-15.x branch from 4f67810 to 774d6ac Compare December 3, 2025 04:07
renovate-approve[bot]
renovate-approve Bot previously approved these changes Dec 3, 2025
@renovate
renovate Bot force-pushed the renovate/apidevtools-json-schema-ref-parser-15.x branch 2 times, most recently from 64dc935 to 6add044 Compare December 4, 2025 01:49
@pmcelhaney

Copy link
Copy Markdown
Collaborator

@copilot fix this issue per APIDevTools/json-schema-ref-parser#405

Copilot AI commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

@copilot fix this issue per APIDevTools/json-schema-ref-parser#405

Fixed in b72346a. The security fix in json-schema-ref-parser v15 (the commit referenced in issue #405) blocks localhost URLs by default via safeUrlResolver: true. Since Counterfact legitimately needs to load OpenAPI specs from localhost, I passed { resolve: { http: { safeUrlResolver: false } } } to bundle() in specification.js. All 38 test suites now pass.

@coveralls

coveralls commented Mar 30, 2026

Copy link
Copy Markdown
Collaborator

Pull Request Test Coverage Report for Build 23771126199

Details

  • 3 of 3 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.004%) to 86.089%

Totals Coverage Status
Change from base Build 23770053332: 0.004%
Covered Lines: 5041
Relevant Lines: 5916

💛 - Coveralls

pmcelhaney
pmcelhaney previously approved these changes Mar 30, 2026
@pmcelhaney

Copy link
Copy Markdown
Collaborator

@copilot CI is failing on Windows. Probably because \s didn't get changed to /s somewhere. Look for exiting replaceAll() functions that fix that issue and add replaceAll()s where they're missing.

Copilot AI commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

@copilot CI is failing on Windows. Probably because \s didn't get changed to /s somewhere. Look for exiting replaceAll() functions that fix that issue and add replaceAll()s where they're missing.

Fixed in 109494b. The issue was that json-schema-ref-parser v15's internal isAbsoluteWin32Path regex (/^[a-zA-Z]:\\/) only matches paths with backslashes (e.g., C:\Users\...), but the withTemporaryFiles helper normalizes paths to forward slashes (C:/Users/...), causing the library to treat them as relative paths and prepend the CWD.

The fix converts filesystem paths to proper file:// URLs using Node's pathToFileURL() before passing to bundle() in both specification.js and openapi-middleware.ts. This handles both forward and backward slash variants correctly on all platforms.

pmcelhaney
pmcelhaney previously approved these changes Mar 30, 2026
@pmcelhaney

Copy link
Copy Markdown
Collaborator

@copilot some tests are failing now

Copilot AI commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

@copilot some tests are failing now

Fixed in 161ad32. The issue was that pathToFileURL (my previous fix) encodes ~ as %7E, and then fromFileSystemPath in v15 runs encodeURI on the result, double-encoding it to %257E. This only partially decodes back to %7E, leaving the path unresolvable.

The root cause is v15's isAbsoluteWin32Path regex (/^[a-zA-Z]:\\/) only recognizes backslash-style Windows paths — when paths are normalized to forward slashes (C:/Users/...), v15 doesn't detect them as absolute and incorrectly prepends the CWD.

The fix adds a patch-package patch for @apidevtools/json-schema-ref-parser@15.1.3 changing the regex from /^[a-zA-Z]:\\/ to /^[a-zA-Z]:[/\\]/ so it recognizes both C:\... and C:/... as absolute Windows paths.

@pmcelhaney

Copy link
Copy Markdown
Collaborator

@copilot resolve conflicts

Copilot AI commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve conflicts

Resolved in 7a666fb. Merged latest main into this branch — the main conflict was that main had converted specification.js to specification.ts. Applied the safeUrlResolver: false fix to the new TypeScript file and removed the old JS file. All 43 tests pass.

@pmcelhaney

Copy link
Copy Markdown
Collaborator

@copilot fork the json-schema-ref-parser repo, fix the issue there, and open a pull request

Copilot AI commented May 5, 2026

Copy link
Copy Markdown
Contributor

@pmcelhaney I've opened a new pull request, #1992, to work on those changes. Once the pull request is ready, I'll request review from you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants