Skip to content

fix: migrate to js-yaml v5#2908

Merged
vadyvas merged 7 commits into
mainfrom
fix/migrate-to-js-yaml-v5
Jul 21, 2026
Merged

fix: migrate to js-yaml v5#2908
vadyvas merged 7 commits into
mainfrom
fix/migrate-to-js-yaml-v5

Conversation

@DmitryAnansky

@DmitryAnansky DmitryAnansky commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

What/Why/How?

Upgraded js-yaml from v4 to v5. This fixes bundling of strings that look like numbers with underscores (e.g. '12_34'): they are now kept quoted in YAML output instead of being emitted unquoted and read back as numbers by YAML 1.1 parsers.

Breaking change: js-yaml v5 parses YAML more strictly. A multi-line flow collection whose closing bracket is indented to (or below) the level of its parent key is now a parse error. For example, this no longer parses and must be reindented:

example: { 'a': 'test' } # <- move the closing brace to the right of `example:`

All other scalar resolution (hex/octal/leading-zero integers, capitalized booleans, ~ as null, dates kept as strings) and the handling of empty/comment-only documents are unchanged.

Reference

#2906

Alternative

#2907

Testing

Screenshots (optional)

Check yourself

  • This PR follows the contributing guide
  • All new/updated code is covered by tests
  • Core code changed? - Tested with other Redocly products (internal contributions only)
  • New package installed? - Tested in different environments (browser/node)
  • Documentation update has been considered

Security

  • The security impact of the change has been considered
  • Code follows company security practices and guidelines

Note

Medium Risk
Touches the central YAML parse/stringify path used for linting, resolving refs, and bundling; stricter parsing can break previously accepted OpenAPI YAML layouts.

Overview
Upgrades js-yaml from 4.2.0 to 5.2.1 in @redocly/openapi-core and adapts the internal YAML wrapper so lint, resolve, and bundle behavior stay aligned with the new API.

The wrapper now builds its schema with CORE_SCHEMA.withTags (instead of JSON_SCHEMA.extend) and parses via loadAll, enforcing a single document per stream and preserving empty vs comment-only handling. @types/js-yaml is dropped because v5 ships its own types.

Bundle output keeps quoted strings that look like underscore numbers (e.g. '12_34') instead of stripping quotes and re-emitting them as bare scalars. E2E coverage was extended for that case.

Behavior change for users: v5 parses YAML more strictly—multi-line flow collections whose closing }/] is not indented deeper than the parent key now fail to parse (tests were adjusted for valid indentation). Parse errors are reported at the offending token rather than at end-of-file.

Reviewed by Cursor Bugbot for commit 4e09911. Bugbot is set up for automated code reviews on this repo. Configure here.

@changeset-bot

changeset-bot Bot commented Jun 22, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4e09911

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

This PR includes changesets to release 3 packages
Name Type
@redocly/openapi-core Patch
@redocly/cli Patch
@redocly/respect-core 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

@DmitryAnansky DmitryAnansky changed the title Fix/migrate to js yaml v5 fix: migrate to js yaml v5 Jun 22, 2026
@DmitryAnansky DmitryAnansky changed the title fix: migrate to js yaml v5 fix: migrate to js-yaml v5 Jun 22, 2026
@github-actions

github-actions Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 71.83% (🎯 69%) 8624 / 12005
🔵 Statements 71.53% (🎯 69%) 8971 / 12541
🔵 Functions 76.47% (🎯 73%) 1707 / 2232
🔵 Branches 63.39% (🎯 61%) 5799 / 9147
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/core/src/js-yaml/index.ts 100% 100% 100% 100%
Generated in workflow #10785 for commit 4e09911 by the Vitest Coverage Report Action

@DmitryAnansky DmitryAnansky self-assigned this Jun 22, 2026
@DmitryAnansky DmitryAnansky added the snapshot Create experimental release PR label Jun 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📦 A new experimental 🧪 version v0.0.0-snapshot.1782145948 of Redocly CLI has been published for testing.

Install with NPM:

npm install @redocly/cli@0.0.0-snapshot.1782145948

⚠️ Note: This is a development build and may contain unstable features.

},
],
"message": "Can't resolve $ref: unexpected end of the stream within a single quoted scalar in "fixtures/invalid-yaml.yaml" (2:1)",
"message": "Can't resolve $ref: unexpected end of the stream within a single quoted scalar in "fixtures/invalid-yaml.yaml" (1:8)",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please test this in the VSCE.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vadyvas please take a look.

@DmitryAnansky
DmitryAnansky force-pushed the fix/migrate-to-js-yaml-v5 branch from 2639e3f to 8ed7d77 Compare June 23, 2026 08:48
@DmitryAnansky

Copy link
Copy Markdown
Contributor Author

Performance Benchmark fails due to indentation, already notified the OAS description owners.

@DmitryAnansky DmitryAnansky added snapshot Create experimental release PR and removed snapshot Create experimental release PR labels Jun 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📦 A new experimental 🧪 version v0.0.0-snapshot.1782209756 of Redocly CLI has been published for testing.

Install with NPM:

npm install @redocly/cli@0.0.0-snapshot.1782209756

⚠️ Note: This is a development build and may contain unstable features.

@DmitryAnansky
DmitryAnansky requested a review from vadyvas June 23, 2026 10:16
@vadyvas
vadyvas force-pushed the fix/migrate-to-js-yaml-v5 branch from a078710 to e777d9d Compare July 17, 2026 09:23
@github-actions

github-actions Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Performance Benchmark (Lower is Faster)

CLI Version Bundle Lint Check Config
cli-latest ▓ 1.00x (Fastest) ▓ 1.01x ± 0.03 ▓ 1.00x (Fastest)
cli-next ▓▓▓▓ 1.12x ± 0.03 ▓ 1.00x (Fastest) ▓▓ 1.05x ± 0.02

Warning

This PR may introduce a performance regression vs the latest released version:

  • Bundle: 12.1% slower

@vadyvas vadyvas added snapshot Create experimental release PR and removed snapshot Create experimental release PR labels Jul 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📦 A new experimental 🧪 version v0.0.0-snapshot.1784280563 of Redocly CLI has been published for testing.

Install with NPM:

npm install @redocly/cli@0.0.0-snapshot.1784280563

⚠️ Note: This is a development build and may contain unstable features.

@vadyvas

vadyvas commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

internal: e2e, vs-code

@vadyvas
vadyvas marked this pull request as ready for review July 17, 2026 13:34
@vadyvas
vadyvas requested review from a team as code owners July 17, 2026 13:34
Comment thread .changeset/lazy-trees-cheer.md Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit e4aecb4. Configure here.

return str.trim() === '' ? undefined : null;
}
if (documents.length > 1) {
throw new YAMLException('expected a single document in the stream, but found more');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multi-doc YAML loses error location

Low Severity

When parseYaml sees more than one YAML document, it throws a hand-written YAMLException without a (line:col) suffix. YamlParseError parses location from that suffix, so unresolved-ref and parse diagnostics for multi-document streams get NaN line/column instead of pointing at the extra --- separator.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit e4aecb4. Configure here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a regression: js-yaml v4 load() threw the same exception
per the oas/AsyncAPI specs a description is a single document

@vadyvas
vadyvas force-pushed the fix/migrate-to-js-yaml-v5 branch from e4aecb4 to 5f7d2b5 Compare July 20, 2026 16:50
@vadyvas
vadyvas force-pushed the fix/migrate-to-js-yaml-v5 branch from 5f7d2b5 to 4e09911 Compare July 21, 2026 09:47
@vadyvas
vadyvas merged commit ae86ec8 into main Jul 21, 2026
45 checks passed
@vadyvas
vadyvas deleted the fix/migrate-to-js-yaml-v5 branch July 21, 2026 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

snapshot Create experimental release PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants