Skip to content

fix: migrate to js-yaml v5#2908

Open
DmitryAnansky wants to merge 7 commits into
mainfrom
fix/migrate-to-js-yaml-v5
Open

fix: migrate to js-yaml v5#2908
DmitryAnansky wants to merge 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 core YAML parse/stringify used across lint and bundle; v5’s stricter parsing can break previously accepted OpenAPI YAML, though scalar/bundle fixes are intentional.

Overview
Upgrades js-yaml from 4.2.0 to 5.2.1 in @redocly/openapi-core and adapts the parseYaml wrapper to the v5 API: CORE_SCHEMA.withTags replaces JSON_SCHEMA.extend, parsing uses loadAll with an explicit single-document rule (multi-document streams throw), and empty vs comment-only input is handled without throwing. @types/js-yaml is dropped because v5 ships its own types.

Bundle output now keeps values like '12_34' quoted so they are not re-read as numeric literals with underscores; e2e primitive-types coverage was updated for that behavior.

Behavior change for users: YAML parsing is stricter in v5—e.g. a multi-line flow mapping whose closing } is not indented past its parent key fails to parse (tests were adjusted accordingly). Parse errors are reported at the offending token (line/column), not only at end-of-file, which updates some lint snapshot messages.

Reviewed by Cursor Bugbot for commit 5f7d2b5. 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: 5f7d2b5

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 70.42% (🎯 69%) 7786 / 11056
🔵 Statements 70.11% (🎯 69%) 8102 / 11555
🔵 Functions 74.8% (🎯 73%) 1562 / 2088
🔵 Branches 62.03% (🎯 61%) 5257 / 8474
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 #10773 for commit 5f7d2b5 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.00x (Fastest) ▓ 1.00x (Fastest)
cli-next ▓▓ 1.05x ± 0.02 ▓ 1.01x ± 0 ▓ 1.01x ± 0.02

Warning

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

  • Bundle: 5.2% 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
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