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

New Plugin: SortSchemas #128

Open
elbakerino opened this issue Mar 31, 2021 · 4 comments
Open

New Plugin: SortSchemas #128

elbakerino opened this issue Mar 31, 2021 · 4 comments
Labels

Comments

@elbakerino
Copy link
Member

elbakerino commented Mar 31, 2021

This plugin should be a plugin in the stack after (at least) ref and conditional plugins, as those two are responsible for generating a sometimes position-changing schema, produced from keywords default and if/else handling, with maybe changing render order, depending of the actual data / data-that was there / from-default.

The plugin must order properties inside of schemas, ?nothing else?

Rules for sorting by e.g. sortOrder: ["propA", "propB"]

  • if properties exist, it should be the keys of the properties
  • if items exist AND items is an array it should be index keys of the items-schema (array-tuple json-schema)
  • otherwise, sortOrder will be ignored
  • if items exists AND items is itself object, the order of the object must be used, not the one of the array
  • if the to-be-sorted schema-level can not be found (e.g. there is no properties.name for sortOrder: ["name"]) (typeof undefined) the sortOrder must be ignored / no empty schema added in properties

Any not sorted part should be attached after the sorted parts in the same order it was before. A null placeholder can be used to specify where the non-sorted schema parts should be added, only the first found null must "use" the non-sorted schema parts.

@hennessyevan
Copy link

This will be nice to have for our usage, when I get time allocated from my team for this I would love to help develop this plugin and contribute it back

@elbakerino
Copy link
Member Author

Sorting for object.properties was released in v0.4.5

@hennessyevan
Copy link

Is there any desire for the null placeholder feature that we're using? I'd be happy to get a PR together for that.

The difference is

"sortOrder": ["one", "three", null, "last"]

Where null represents any non-sorted items so that "one" and "three" come first and "last" comes last. Leftover properties get slotted into that null spot

@elbakerino
Copy link
Member Author

Feel free! When I've added it, I somehow forgot this issue.

Most likely you also want to change it, so there is some SortPluginMaker through which you can configure the used schema-key for the sort-order.

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

No branches or pull requests

2 participants