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

Omitting items from arrays causes it to throw. #681

Closed
2 tasks done
gtrindade opened this issue Aug 25, 2017 · 3 comments
Closed
2 tasks done

Omitting items from arrays causes it to throw. #681

gtrindade opened this issue Aug 25, 2017 · 3 comments

Comments

@gtrindade
Copy link

Prerequisites

  • I have read the documentation;
  • In the case of a bug report, I understand that providing a SSCCE example is tremendously useful to the maintainers.

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:

"Omitting this keyword has the same behavior as an empty schema."
http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.9

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 if schema.items is defined, causing it to throw an uncatched exception.

Steps to Reproduce

  1. Just run this fiddle https://jsfiddle.net/h6fsjLhj/

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.

@n1k0 n1k0 closed this as completed in #684 Aug 28, 2017
n1k0 added a commit that referenced this issue Aug 28, 2017
* Warn on invalid array schema provided.
* Improve UnsupportedField to provide more details.
@llamamoray
Copy link
Collaborator

Hi, any idea when this will be released?

@glasserc
Copy link
Contributor

glasserc commented Sep 6, 2017

Hi, I just released v0.50.0 which should contain a fix for this.

@gtrindade
Copy link
Author

Thank you for the quick fix! 🎉

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

3 participants