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

bump overlay line width not preserved #579

Open
thim81 opened this issue Sep 10, 2024 · 2 comments
Open

bump overlay line width not preserved #579

thim81 opened this issue Sep 10, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@thim81
Copy link

thim81 commented Sep 10, 2024

Steps to reproduce

Using the bump overlay results in an unwanted line width.

Take any OpenAPI file, apply the following example overlay:

overlay: 1.0.0
info:
  title: Structured Overlay
  version: 1.0.0
actions:
  - target: "$"   # Root of document
    update:
      info:
        x-overlay-applied: structured-overlay
      paths:
        "/":
          summary: "The root resource"
          get:
            summary: "Retrieve the root resource"
            x-rate-limit: 100
        /pets:
          get:
            summary: "Retrieve a list of pets"
            x-rate-limit: 100
#      components:
#      tags:

execute: bump overlay openapi.yaml overlays.yaml > openapi.public.yaml

Expected behavior

Using the bump overlay results in the original line width being kept.

BEFORE/AFTER
IMG-2024-09-10 at 14-28-47@2x

@paulRbr paulRbr added the enhancement New feature or request label Sep 16, 2024
@paulRbr
Copy link
Member

paulRbr commented Sep 16, 2024

Hi @thim81,

Thanks for creating this issue. Indeed after applying the overlay we need to reconstruct a YAML formatted string and by doing so we impose a certain style/format for now. Not sure how we could preserve the original format and we won't be able to change that so soon (but open for contribution!).

As YAML is pretty flexible, there are many different ways of writing the exact same data.
For example both string examples below have the same data:

key: my string value

vs

key: "my string value"

In the case you present, it's the case for long text where we use “folded” style multiline strings, so both examples below have the exact same output data values:

description: This is a long line of text with a lot of description in my YAML file

is exactly the same as

description: >-
  This is a long line of text with a lot of description in 
  my YAML file

Hope this helps and sorry not to be able to give you a workaround / a solution for now. Let me know if you have other questions!

@thim81
Copy link
Author

thim81 commented Sep 17, 2024

Hi @paulRbr

I have been using https://www.npmjs.com/package/@stoplight/yaml which is optimised for handling OpenAPI files. It supports line width and has the option to preserve YAML comments.

If you would be open for a PR, I could contribute a possible implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants