Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YAML comments are stripped #44

Closed
bbrks opened this issue Feb 11, 2022 · 3 comments
Closed

YAML comments are stripped #44

bbrks opened this issue Feb 11, 2022 · 3 comments
Assignees

Comments

@bbrks
Copy link

bbrks commented Feb 11, 2022

I have no idea if this is intentional, or just a difficult problem to solve, but comments are stripped from YAML OpenAPI specs.
This becomes a little bit problematic when the comments are meaningful to the openapi writer and help maintainability.

E.g:

# asdf
info:
  title: title
  description: description
  version: "3.1.0" # comment

Becomes

info:
  title: title
  description: description
  version: 3.1.0
@thim81
Copy link
Owner

thim81 commented Feb 11, 2022

@bbrks Sadly enough, there is no way to keep the comments.
We are using a YAML parsing library and all YAML libraries strip the comments by default as soon as they serialise the content of the YAML file.
openapi-format uses https://github.com/stoplightio/yaml for parsing the YAML file, so perhaps you can open an issue to see if they have a solution for the comments?

If you find a manner, please let me know, since I struggle with the comments being removed as well.

A possible work-around is that you format the file and write the formatted file next the original file and do a diff of both files.

Repository owner deleted a comment from a-waider Jan 24, 2023
Repository owner deleted a comment from a-waider Jan 24, 2023
@thim81 thim81 self-assigned this Aug 17, 2024
@thim81
Copy link
Owner

thim81 commented Aug 17, 2024

Update: Stoplight YAML-ast-parser introduced the option to preserve comments on YAML docs, stoplightio/yaml-ast-parser#6

Will need some more investigation

@thim81
Copy link
Owner

thim81 commented Sep 10, 2024

hi @bbrks

We just release v1.23.0 which provides the option --keepComments which keep the YAML comments in a file.

Closing this issue.
If you're still experiencing problems, please feel free to reopen this issue or create a new one. Thanks for taking the time to report it!

@thim81 thim81 closed this as completed Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants