svelte-jsonschema-form icon indicating copy to clipboard operation
svelte-jsonschema-form copied to clipboard

Flesh out `anyOf` support

Open romancow opened this issue 2 years ago • 1 comments
trafficstars

Currently support for anyOf is a bit limited. I believe it's just a dropdown that switches child fields based on which "anyOf" option is selected. When a new one is selected, the previous set values persist. These should probably be "cleared out" whenever a new option is selected.

Actually, this would ideally be how the "oneOf" would work and "anyOf" would allow one to select multiple options and set the values for each of these (and clear out associated values when unselected). There are a few complications here to keep in mind - like there can be values for say, an object type, that are not part of the anyOf options. Also the different options could have overlapping values, where we probably want one field for this. Likewise you could have anyOfs without actual properties like outlined in issue #6 .

Probably want to look at how other similar libraries handle this (e.g. (react-jsonschema-form)[https://rjsf-team.github.io/react-jsonschema-form/] and (JSONForms)[https://jsonforms.io/]).

romancow avatar Sep 14 '23 20:09 romancow

I think the best way to go about "full" anyOf support, would be to replace the current select dropdown with a similar "multiselect" dropdown. SMUI does not currently have a multiselect like this, so we'd have to create custom one, though I don't think this would be too hard (we're already patching the current select component). I've already created something similar for the webgme-taxonomy dashboard search filters.

I think then we could use the existing json-schema-merge-allof dependency to merge all the selected anyOfs with any properties. This would also address #6 . This "merged" schema" would only be present/referenced in the control itself, and not a change made to the schema object as a whole.

When an anyOf item is unselected, we would then recalculate the "merged" schema, then compare all the current property keys with the current data value, removing any keys in data nor present in the new schema.

romancow avatar Sep 21 '23 16:09 romancow