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

Issues with OneOfRenderers #96

Open
Yekt opened this issue Jul 13, 2023 · 2 comments
Open

Issues with OneOfRenderers #96

Yekt opened this issue Jul 13, 2023 · 2 comments

Comments

@Yekt
Copy link

Yekt commented Jul 13, 2023

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:

  • 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.
    image

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:

  • 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)
    image
    image

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
Copy link

I can confirm that this seems to be an issue

@Yekt
Copy link
Author

Yekt commented Dec 14, 2023

This is related

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

No branches or pull requests

2 participants