Skip to content

select correct oneOf based on specific property #709

Open
@mbknor

Description

@mbknor

We're using json-editor in combination with schemas generated by https://github.com/mbknor/mbknor-jackson-jsonSchema which uses oneOf to enable polymorphism.

When using polymorphism in json we use a special property to show which subclass the json represents.

Each oneOf-schema has this property embeded as a hidden single enum property with the "type info".
This ensures that the json extracted from the editor has correct type info corresponding with the oneOf which is selected.

When setting data into the editor using setValue, the multiple-editor tries to select the correct oneOf to use. This is done by selecting the one that has no validation errors.

We often need to show the editor with initial data that is not yet 100% valid.
Since the data is not fully valid, the multiple-editor does not know which oneOf to select always ending up with the first one.

Since we always have this special property with the "type info", I'm proposing a new feature to optionally select oneOf based on a custom property and value.

If the (part of) schema (that is "root" for the specific oneOf) has this option:

"options": {
  "multiple_editor_select_via_property": {
     "property": "myProperty",
     "value": "myValue"
  }
}

Then the multiple-editor will look for the property 'myProperty' in the value-object we're setting using setValue. If it is pressent, and has the value 'myValue', then we select this editor.

If not, we fallback to default implementation which selects it if it has no validation errors.

Im soon going to submit a pullRequest with this feature.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions