Repository navigation
fix(openapi-parser): strip a leading UTF-8 BOM before JSON.parse in normalize - #10792
Merged
Merged
Conversation
b84330808
requested review from
amritk,
hanspagel,
hwkr and
marclave
as code owners
October 30, 2026 07:28
🦋 Changeset detectedLatest commit: a371fa1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
…ormalize JSON documents saved with a UTF-8 BOM (common on Windows) made normalize() return undefined, so validate(), dereference() and upgrade() reported "Can't find JSON, YAML or filename in data." This mirrors the fix already made in @scalar/json-magic (scalar#9107). Co-Authored-By: Claude Opus 5.5 <[email protected]>
hanspagel
force-pushed
the
fix/openapi-parser-utf8-bom
branch
from
November 2, 2026 14:38
c2f4999 to
91701a7
Compare
hanspagel
approved these changes
Nov 2, 2026
hanspagel
left a comment
Member
There was a problem hiding this comment.
thanks! I just made it use normalize from the json-magic package
hanspagel
enabled auto-merge (squash)
November 2, 2026 15:04
hanspagel
temporarily deployed
to
production-netlify
November 2, 2026 15:05 — with
GitHub Actions
Inactive
hanspagel
temporarily deployed
to
production-netlify
November 2, 2026 15:05 — with
GitHub Actions
Inactive
hanspagel
temporarily deployed
to
production-netlify
November 2, 2026 15:05 — with
GitHub Actions
Inactive
hanspagel
temporarily deployed
to
production-netlify
November 2, 2026 15:05 — with
GitHub Actions
Inactive
hanspagel
temporarily deployed
to
production-netlify
November 2, 2026 15:05 — with
GitHub Actions
Inactive
Merged
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
@scalar/openapi-parsermaintained its ownnormalize(), separate from the one in@scalar/json-magicthat #9107 fixed. JSON saved with a leading UTF-8 BOM was rejected, so an otherwise valid API description could fail invalidate(),dereference(), orupgrade().For example, save this document as UTF-8 with a BOM:
{ "openapi": "3.1.0", "info": { "title": "Example", "version": "1.0.0" }, "paths": {} }Previously,
validate(await readFile('openapi.json', 'utf8'))rejected the document. It now parses and validates successfully.Solution
Import and re-export
@scalar/json-magic/helpers/normalizedirectly, removing the parser's duplicate normalizer entirely. This keeps BOM handling and JSON/YAML parsing in one place. Objects and filesystems retain their identity.The exported helper now has the shared signature
(content: unknown) => unknown. TypeScript callers must narrow its result before accessing properties.Normalization also adopts the shared helper's handling of malformed JSON arrays: inputs such as
[{foo: "bar"}]returnundefinedinstead of falling back to YAML parsing.Ticket
See #9097