eclipsesource / jsonforms-vuetify-renderers

https://jsonforms-vuetify-renderers.netlify.app/
Other
25 stars 26 forks source link

Issues with OneOfRenderers #96

Open Yekt opened 11 months ago

Yekt commented 11 months ago

I've stumbled into a hand full of errors when trying to use a schema that includes the "oneOf" keyword. Since the errors seem to be related I'm going to dump all my findings in this issue. If you want me to split it up into multiple issues, let me know.

I've recreated my problems with a simple example schema (see Details). Just paste it into your online playground (make sure to delete the contents of the UI schema, data and internationalization).

{ "definitions": { "Type": { "type": "string", "title": "FooBar Type", "description": "type discriminator of FooBar object" }, "Icons": { "type": "string", "enum": [ "foo-icon", "bar-icon" ], "title": "Icon" }, "Foo": { "type": "object", "title": "Foo", "properties": { "type": { "allOf": [{ "$ref": "#/definitions/Type" }], "default": "foo", "const": "foo", "readOnly": true }, "icon": { "allOf": [{ "$ref": "#/definitions/Icons" }], "default": "foo-icon" } }, "required": [ "type", "icon" ] }, "Bar": { "type": "object", "title": "Bar", "properties": { "type": { "allOf": [{ "$ref": "#/definitions/Type" }], "default": "bar", "const": "bar", "readOnly": true }, "icon": { "allOf": [{ "$ref": "#/definitions/Icons" }], "default": "bar-icon" } }, "required": [ "type", "icon" ] } }, "type": "object", "properties": { "foobars": { "type": "array", "title": "FooBars", "items": { "oneOf": [ { "$ref": "#/definitions/Foo" }, { "$ref": "#/definitions/Bar" } ] } } } }

Issue 1 - incorrect validation errors

Upon choosing an object in the selector of the OneOfRenderer I would expect the following behavior:

  1. all props of the chosen object are rendered
  2. UI elements are updated with the defaults of the schema
  3. validation check is preformed
  4. validation success: onChange event with the new data is emitted

What I observed:

Without digging into the code I'd suspect that the validation is performed before the ui elements are filled with defaults.
Resulting in validation errors that shouldn't be there.

Issue 2 - defaults fail when switching between OneOf-objects

When using the selector of the OneOfRenderer to switch between objects I would expect the following behavior:

  1. a prompt to clear the form is presented ("Clear form?")
  2. on "yes": the old object and it's UI elements are removed
  3. after that it's the same as 1-4 from issue 1:
    new UI is rendered -> defaults of new object are filled -> validation -> data emitted

What I observed:

I can see how not removing and then recreating ui elements that share keys between the two objects is beneficial for performance. However if the prompt asks me to "Clear form" I do expect the data to be actually purged and than refilled with defaults (if defined by the schema).

VinzSpring commented 11 months ago

I can confirm that this seems to be an issue

Yekt commented 6 months ago

This is related