bennycode / sort-everything

VS Code extension to sort JSON files.
https://marketplace.visualstudio.com/items?itemName=bennycode.sort-everything
MIT License
10 stars 2 forks source link

Introduce predefined sorting templates #10

Open visvital opened 1 year ago

visvital commented 1 year ago

Story:

As a user, I want to sort the .yaml file according to the OpenAPI ordering of the fields so that it is easier to read and update in the future.

Acceptance criteria:

  1. The plugin allows for specifying the predefined templates for sorting (for example, OpenAPI specification format).
  2. When the user applies the sorting with the predefined template/order of the keywords, the plugin first sorts everything according to the specified template, and then applies the default strategy of sort (by name ASC).

Alternative path:

Instead of introduction of the templates for sort, it might make sense to provide the option to exclude the indented elements from the sort. It should practically do the trick in most cases.

Dev Notes:

  1. The OpenAPI specification is usually more convenient to design in the .yaml format, since it has less noise, but when we sort it using sort-everything, it does sort everything, without accounting for the logical ordering (for example: "type: array", then "items" after the sort becomes list of "items" and then "type:array"). It doesn't break the .yaml file, but makes it harder to update/manage.
bennycode commented 1 year ago

Hi @visvital, is the ordering format of OpenAPI available as a spec that can be ready by a machine (JSON Schema or similar)?

visvital commented 1 year ago

Hi @bennycode, I did a brief search, but wasn't able to find the proper spec. Here's so far the only machine-readable reference, which I liked - https://github.com/Redocly/redoc/blob/main/src/types/open-api.ts If needed, I will spend some time and build the yaml spec, according to https://spec.openapis.org/oas/v3.1.0#schema. I think I only thought of the ordering of the fixed fields sections and applying the proper recursion. Thank you!

Also, I've found this tool, which may be handy: https://github.com/proohit/openapi-snippets/tree/master