react-jsonschema-form
react-jsonschema-form copied to clipboard
fix(@rjsf/core): Nested into items schema allOf blocks with multiple …
…if/then/else statements fail to render correctly
When schema (or subschema) has allOf
in the root AND has an array field with a property where exists allOf
with few conditions RJSF doesn't handle this case properly. The console shows the warning could not merge subschemas in allOf
and dependent properties don't reflect the schema. This is an example - if you remove root allOf
the playground example will work.
After diving into the RJSF source code and looking around at dependent libraries, I found the solution, which makes these schemas work.
- Upgrading
[email protected]
- this version allows to resolve only the top-levelallOf
keyword in the schema; - Patch the
utils.retreiveSchema
method - pass{ deep: false }
into the merger; - Remove https://github.com/rjsf-team/react-jsonschema-form/pull/2839 change - looks like now it is redundant.
I'm not sure about any regression this change may introduce, but it works for the first look. All tests (except the fixed one that checked a nested merging allOf
blocks) pass. All my schemas (including schemas that required https://github.com/rjsf-team/react-jsonschema-form/pull/2839) works
Checklist
- [ ] I'm updating documentation
- [ ] I've checked the rendering of the Markdown text I've added
- [X] I'm adding or updating code
- [ ] I'm adding a new feature
- [ ] I've updated the playground with an example use of the feature
Btw, I didn't include updated lock files in this PR because they were totally different. The versions in the repo are using space-based indents but my npm generated tab-based indents. Also, there were a lot of other changes that upgrading of the json-schema-merge-allof
package should not add.
@AlimovSV FYI, the upcoming beta (landing in about a week) completely refactors all of this code in breaking ways. If you'd like to make the fix in a code base that is currently active (the master branch is locked until the rjsf-v5
branch merges into it), then please take a look at rjsf-v5
and make a similar change in the @rjsf/utils
package there.
Closing since #3227 was merged