Skip to content

refactor: replace stoplight/yaml with yaml (eemeli)#206

Merged
thim81 merged 4 commits intothim81:mainfrom
guilhas07:refactor-yaml
Apr 12, 2026
Merged

refactor: replace stoplight/yaml with yaml (eemeli)#206
thim81 merged 4 commits intothim81:mainfrom
guilhas07:refactor-yaml

Conversation

@guilhas07
Copy link
Copy Markdown
Contributor

@guilhas07 guilhas07 commented Apr 11, 2026

Important

Splitted into commits for easier review — happy to squash before merge, or keep it as is.

Fixes #149, #202

I'd like to propose replacing stoplight/yaml with https://github.com/eemeli/yaml. Open to feedback on the approach before this goes further.

Problem

stoplight/yaml has multiple unfixed bugs and limitations:

  • Block scalar chomping (|+) loses trailing blank lines
  • Explicit indent indicators (|2) produce a spurious leading newline
  • Both stoplight/yaml and its underlying parser stoplight/yaml-ast-parser (a fork of js-yaml) are effectively unmaintained
  • Unnecessarily quotes valid YAML strings and forces all double-quoted strings to single quotes (Option to control quotes & string escaping stoplightio/yaml#78)

Solution

Replace stoplight/yaml with the actively maintained https://github.com/eemeli/yaml package. Comment preservation is re-implemented using a path-based extract/inject strategy. This also unlocks greater flexibility going forward, due to the yaml package exposing a AST which give us fine-grained control. Also it provides multiple configuration options.

Problem: stoplight/yaml has unfixed bugs in block scalar chomping (|+
loses trailing blank lines, explicit indent indicators like |2 produce a
spurious leading newline). Furthermore the library is effectivelly unmaintained.

Solution: Replace stoplight/yaml with the actively maintained yaml
(eemeli) package. Comment preservation is re-implemented using a
path-based extract/inject strategy.
- yaml-default-newline: block scalar chomping (|+ keep, |- strip, |
  clip) now behaves correctly. |+ doesn't lose trailing blank lines,
  and spurious leading newlines are not created.

- yaml-no-sort-keep-comments: a valueCommentBefore (key: # comment
  above a block node) is re-emitted on its own line below the key
  rather than inline. This is a known rendering difference of the new
  path-based inject approach; the YAML is semantically equivalent.
@guilhas07 guilhas07 changed the title Title: refactor: replace @stoplight/yaml with yaml (eemeli) Title: refactor: replace stoplight/yaml with yaml (eemeli) Apr 11, 2026
@guilhas07 guilhas07 changed the title Title: refactor: replace stoplight/yaml with yaml (eemeli) refactor: replace stoplight/yaml with yaml (eemeli) Apr 11, 2026
@thim81
Copy link
Copy Markdown
Owner

thim81 commented Apr 12, 2026

hi @guilhas07

A long time ago, I did looked into using https://github.com/eemeli/yaml library but for some reason I was not able to fully migrate to it. Looking at the implementation (which opens up for AST usage if we would need it), the updated tests PLUS the required support for preserving comments; your PR looks in a very good shape.

@thim81 thim81 merged commit 692fb3f into thim81:main Apr 12, 2026
2 checks passed
@thim81
Copy link
Copy Markdown
Owner

thim81 commented Apr 12, 2026

hi @guilhas07

I just released version 1.31.0, which includes your excellent PR of the switch to yaml library by eemeli instead of @stoplight/yaml.

Thanks again for another contribution 🙌

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.

Turn off string escaping and quotes transform

2 participants