thim81 / openapi-format

Format an OpenAPI document by ordering, formatting and filtering fields.
MIT License
79 stars 14 forks source link

$ref looses its quotes although the string contains a # (Which enforces the quotes in yaml) #108

Closed kurellajunior closed 1 week ago

kurellajunior commented 2 weeks ago

when having anything like

components:
  schemas:
    Case:
      description: Case file subset
      type: object
      properties:
        extern:
          $ref: "domain-types.openapi.yaml#/components/schemas/Extern"

opanapi-format will remove the quotes, leading to an invalid yaml, which in turn most Editors they fail to resolve the ref ( because everything after the # is a comment)

local references $ref: "#/components/schemas/Exetrn" keep their quotes, so i assume it is a simple oversight somewhere

thim81 commented 2 weeks ago

hi @kurellajunior

We will see where it these quotes gets removed. We are using the @stoplight/yaml package to parse and write the YAML files, so it might be related to the conversion happening.

Either way, we will look into it.

thim81 commented 2 weeks ago

hi @kurellajunior

We just released openapi-format 1.17.1, which includes an enhancement to keep the quotes for $ref elements. Try it out and feel free let me know if the issue is gone or not.

kurellajunior commented 1 week ago

Hi end wow @thim81 ! Updated and run it in our project. Works. Immediately removed my sed postprocessing command :grin:

thim81 commented 1 week ago

hi @kurellajunior

The yaml.safeStringify function from the @stoplight/yaml package removed the quotes. I had to add a specific patch to overcome it, so not all edge cases might be covered but I'll keep an eye out for any cases discovered.

Thanks for taking your time to report the issue, allowing to make openapi-format better for all users. Much appreciated 🤝