-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Omitting items
from arrays causes it to throw.
#681
Comments
n1k0
added a commit
that referenced
this issue
Aug 28, 2017
n1k0
added a commit
that referenced
this issue
Aug 28, 2017
Hi, any idea when this will be released? |
Hi, I just released v0.50.0 which should contain a fix for this. |
Thank you for the quick fix! 🎉 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Prerequisites
Description
An array without the
items
field, breaks the rendered form.I noticed some schemas I have were breaking stuff heavily in the app I'm working on. And I noticed sending invalid schemas usually results in a proper message like "the schema is invalid" or something, instead of rendering the form, but for some schemas it would just break catastrophically impacting in my whole page some times.
Upon further investigation I noticed some of my schemas had properties of type "array" with no "items" field. And I was surprised to see that in my database because I validate everything before saving. Turns out these are actually valid schemas:
I debugged react-jsonschema-form's source code a little bit and saw that it was really throwing here:
https://github.com/mozilla-services/react-jsonschema-form/blob/9d79b71f13d87831e5c9e2d8fc7ae5e5ca7865c4/src/utils.js#L398
that is a call from here:
https://github.com/mozilla-services/react-jsonschema-form/blob/d403edc20a1d839326b8f6d0a380f84697efba2b/src/components/fields/ArrayField.js#L367
And this code tells me you guys are assuming all arrays should have the
items
property and not really checking ifschema.items
is defined, causing it to throw an uncatched exception.Steps to Reproduce
Expected behavior
I know it's probably not possible to render a form for this scenario, but the tool should ignore fields like this or probably provide feedback that this type of schema is not supported.
Actual behavior
The tool just throws, and since catching rendering exceptions in React is not always simple, it can cause unexpected behavior in the whole app.
Version
0.49.0
Thanks! And let me know if I can provide more info, or if there is a workaround I can use.
The text was updated successfully, but these errors were encountered: