react-jsonschema-form icon indicating copy to clipboard operation
react-jsonschema-form copied to clipboard

fix(@rjsf/core): Nested into items schema allOf blocks with multiple …

Open AlimovSV opened this issue 2 years ago • 2 comments

…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-level allOf 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
  • [X] I'm adding or updating code
    • [X] I've added and/or updated tests. I've run npm run test:update to update snapshots, if needed.
    • [ ] I've updated docs if needed
    • [ ] I've updated the changelog with a description of the PR
  • [ ] I'm adding a new feature
    • [ ] I've updated the playground with an example use of the feature

AlimovSV avatar Aug 18 '22 13:08 AlimovSV

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 avatar Aug 18 '22 13:08 AlimovSV

@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.

heath-freenome avatar Aug 19 '22 00:08 heath-freenome

Closing since #3227 was merged

nickgros avatar Dec 23 '22 15:12 nickgros