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).
Upon choosing an object in the selector of the OneOfRenderer I would expect the following behavior:
all props of the chosen object are rendered
UI elements are updated with the defaults of the schema
validation check is preformed
validation success: onChange event with the new data is emitted
What I observed:
the props of the object are rendered as expected
defaults are filled in as expected
validation check fails (multiple times):
validation fails even tho the values inside the ui elements are correct.
apparently the validation check is performed multiple times and the error hints are concatenated.
since the validation "fails" the updated data is not emitted.
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:
a prompt to clear the form is presented ("Clear form?")
on "yes": the old object and it's UI elements are removed
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:
the prompt is displayed as expected
the ui doesn't update any key that exists in both objects (Foo and Bar both share the keys "type" and "icon")
the ui elements are not updated with the defaults of the new object
if there is a conflict between old value and new const the input field goes blank instead of updating the value ("type" in this example)
due to the issues described above the updated data isn't emitted with the correct values (because validation fails)
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).
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:
What I observed:
validation fails even tho the values inside the ui elements are correct.
apparently the validation check is performed multiple times and the error hints are concatenated.
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:
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).