rjsf-team / react-jsonschema-form

A React component for building Web forms from JSON Schema.
https://rjsf-team.github.io/react-jsonschema-form/
Apache License 2.0
14.1k stars 2.18k forks source link

if/then inside allOf blocks at different levels: No resolver found for key if #2927

Open dbaumgarten opened 2 years ago

dbaumgarten commented 2 years ago

Prerequisites

What theme are you using?

core

Version

4.2.0

Current Behavior

I have a schema that makes extensive use of if/then constructs (often inside allOf blocks). Unfortunately it does not work in rjsf and throws the following error in the console:

could not merge subschemas in allOf:
Error: No resolver found for key if. You can provide a resolver for this keyword in the options, or provide a default resolver.

I have prepared a shortened example of the problematic schema: catalog.txt

Using it in https://rjsf-team.github.io/react-jsonschema-form/ reproduces the issue.

When any of the two allOf blocks is deleted, the schema starts to work just fine.

I think it might be related to #2752 .

Expected Behavior

I would like rjsf to properly render the schema.

Steps To Reproduce

  1. Have a schema with if's inside allOf blocks at different levels in the schema
  2. Try to render it
  3. Observe that it doesnt work and throws an error

Environment

irrelevant (I guess)

Anything else?

No response

s1rd4v3 commented 1 year ago

We are facing the same issue. As soon as the allOf -> if/then/else is inside a "type": "array" rjsf breaks with the above mentioned error. Seems like resolveCondition (utils.js) is not executed on those allOf's, so the json-schema-merge-allof package can't handle it since there are still if keys inside of the objects of allOf which usually would be removed with resolveCondition.

Even thought this allOf then works as expected, other allOf's (at the root for example) won't work anymore.

Additionally we not only have this issue with if but with enumNames too. But this most probably is related.

Playground Link

rap1ds commented 1 year ago

We're facing exactly the same issue and exactly in the same conditions @s1rd4v3 described, i.e. allOf + if/then/else inside an array.

Here's my playground example

Steps to reproduce:

  1. Open the playground example above
  2. From "sectionType" dropdown, pick "columns"

Expected: A new field "numColumns" is shown

Actual: "numColumns" is not shown. There's a warning: could not merge subschemas in allOf: Error: No resolver found for key if. You can provide a resolver for this keyword in the options, or provide a default resolver.

rap1ds commented 1 year ago

I came back to check this issue and noticed that I couldn't reproduce it anymore with the playground link + steps to reproduce I posted earlier. Maybe this got partially fixed?

It looks to me that even though the playground example doesn't demonstrate the issue anymore, the issue hasn't been fully fixed yet. I'm developing an app where we use version 5.0.0-beta.10 and our schema produces bunch of could not merge subschemas in allOf warnings. I tried to upgrade to latest version 5.0.0-beta.17 to see if the warnings are still there, and yes, they are still there with the newest version.

rbavery commented 1 month ago

I am also still getting this error

Playground Link