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

oneOf not selecting correct default value for complex objects with the same property keys #4208

Closed
4 tasks done
Becaan opened this issue May 30, 2024 · 6 comments
Closed
4 tasks done
Labels
any-one-all-of Related to fixing anyOf, oneOf or allOf defaults

Comments

@Becaan
Copy link

Becaan commented May 30, 2024

Prerequisites

What theme are you using?

core

Version

5.x

Current Behavior

As you can see in this example: https://rjsf-team.github.io/react-jsonschema-form/#eyJmb3JtRGF0YSI6eyJQbGFuSWQiOiIxMjMiLCJTdW0gSW5zdXJlZCI6IjkwMDAiLCJIZWFydCBhbmQgVmFzY3VsYXIgU3lzdGVtIjp7IlN1bSBJbnN1cmVkIjoiMTIwMCJ9fSwic2NoZW1hIjp7InR5cGUiOiJvYmplY3QiLCJvbmVPZiI6W3sidGl0bGUiOiJQbGFuIiwicHJvcGVydGllcyI6eyJQbGFuSWQiOnsidHlwZSI6InN0cmluZyIsImRlZmF1bHQiOiI2MSIsInJlYWRPbmx5Ijp0cnVlfSwiU3VtIEluc3VyZWQiOnsidHlwZSI6InN0cmluZyIsImRlZmF1bHQiOiIxMjAwIiwicGF0dGVybiI6Il5bMC05XXsxLDIwMn0oXFwuWzAtOV17MSwyM30pPyQifSwiSGVhcnQgYW5kIFZhc2N1bGFyIFN5c3RlbSI6eyJwcm9wZXJ0aWVzIjp7IlN1bSBJbnN1cmVkIjp7InR5cGUiOiJzdHJpbmciLCJkZWZhdWx0IjoiMTIwMCIsInBhdHRlcm4iOiJeWzAtOV17MSwyMDJ9KFxcLlswLTldezEsMjN9KT8kIn19fX19LHsidGl0bGUiOiJOZXcgUGxhbiIsInByb3BlcnRpZXMiOnsiUGxhbklkIjp7InR5cGUiOiJzdHJpbmciLCJkZWZhdWx0IjoiMTIzIiwicmVhZE9ubHkiOnRydWV9LCJTdW0gSW5zdXJlZCI6eyJ0eXBlIjoic3RyaW5nIiwiZGVmYXVsdCI6IjkwMDAiLCJwYXR0ZXJuIjoiXlswLTldezEsMjAyfShcXC5bMC05XXsxLDIzfSk/JCJ9LCJIZWFydCBhbmQgVmFzY3VsYXIgU3lzdGVtIjp7InByb3BlcnRpZXMiOnsiU3VtIEluc3VyZWQiOnsidHlwZSI6InN0cmluZyIsImRlZmF1bHQiOiI5MDAwIiwicGF0dGVybiI6Il5bMC05XXsxLDIwMn0oXFwuWzAtOV17MSwyM30pPyQifX19fX1dfSwidWlTY2hlbWEiOnt9LCJ0aGVtZSI6Im1hdGVyaWFsLXVpLTUiLCJsaXZlU2V0dGluZ3MiOnt9fQ==

The default value for complex object is not taken into account at all as well as pattern for example which i tried also.
So basically. "Sum Insured" that is a part of "Heart and Vascular System" always has the same default value of 1200 even though in jsonSchema default value for "New Plan" is set to 9000.
The behaviour that it should follow should be like the "Sum Insured" that is outside of "Heart and Vascular System".

TLDR: "Sum Insured" inside the "Heart and Vascular System" should have default value 9000 previewed when selecting "New Plan"

Expected Behavior

"Sum Insured" inside the "Heart and Vascular System" should have default value 9000 previewed when selecting "New Plan"

Steps To Reproduce

https://rjsf-team.github.io/react-jsonschema-form/#eyJmb3JtRGF0YSI6eyJQbGFuSWQiOiI2MSIsIlN1bSBJbnN1cmVkIjoiMTIwMCIsIkhlYXJ0IGFuZCBWYXNjdWxhciBTeXN0ZW0iOnsiU3VtIEluc3VyZWQiOiIxMjAwIn19LCJzY2hlbWEiOnsidHlwZSI6Im9iamVjdCIsIm9uZU9mIjpbeyJ0aXRsZSI6IlBsYW4iLCJwcm9wZXJ0aWVzIjp7IlBsYW5JZCI6eyJ0eXBlIjoic3RyaW5nIiwiZGVmYXVsdCI6IjYxIiwicmVhZE9ubHkiOnRydWV9LCJTdW0gSW5zdXJlZCI6eyJ0eXBlIjoic3RyaW5nIiwiZGVmYXVsdCI6IjEyMDAiLCJwYXR0ZXJuIjoiXlswLTldezEsMjAyfShcXC5bMC05XXsxLDIzfSk/JCJ9LCJIZWFydCBhbmQgVmFzY3VsYXIgU3lzdGVtIjp7InByb3BlcnRpZXMiOnsiU3VtIEluc3VyZWQiOnsidHlwZSI6InN0cmluZyIsImRlZmF1bHQiOiIxMjAwIiwicGF0dGVybiI6Il5bMC05XXsxLDIwMn0oXFwuWzAtOV17MSwyM30pPyQifX19fX0seyJ0aXRsZSI6Ik5ldyBQbGFuIiwicHJvcGVydGllcyI6eyJQbGFuSWQiOnsidHlwZSI6InN0cmluZyIsImRlZmF1bHQiOiIxMjMiLCJyZWFkT25seSI6dHJ1ZX0sIlN1bSBJbnN1cmVkIjp7InR5cGUiOiJzdHJpbmciLCJkZWZhdWx0IjoiOTAwMCIsInBhdHRlcm4iOiJeWzAtOV17MSwyMDJ9KFxcLlswLTldezEsMjN9KT8kIn0sIkhlYXJ0IGFuZCBWYXNjdWxhciBTeXN0ZW0iOnsicHJvcGVydGllcyI6eyJTdW0gSW5zdXJlZCI6eyJ0eXBlIjoic3RyaW5nIiwiZGVmYXVsdCI6IjkwMDAiLCJwYXR0ZXJuIjoiXlswLTldezEsMjAyfShcXC5bMC05XXsxLDIzfSk/JCJ9fX19fV19LCJ1aVNjaGVtYSI6e30sInRoZW1lIjoibWF0ZXJpYWwtdWktNSIsImxpdmVTZXR0aW5ncyI6e319

Environment

- OS:
- Node:
- npm:

Anything else?

No response

@Becaan Becaan added bug needs triage Initial label given, to be assigned correct labels and assigned labels May 30, 2024
@nickgros
Copy link
Contributor

@Becaan thanks for the report, this is definitely a bug. The regular maintainers don't have much time to fix all issues, are you interested to investigate a fix?

This looks similar to #3892, which dealt with allOfs, which was fixed by #3969, so that PR may be a good place to figure out where to start

@nickgros nickgros added help wanted defaults any-one-all-of Related to fixing anyOf, oneOf or allOf and removed needs triage Initial label given, to be assigned correct labels and assigned labels Jun 21, 2024
@Writingsinfo
Copy link

Hi @nickgros I know you have labeled it as help wanted but is it possible to escalate this to the team and see if anyone can pick it up? We are relying on oneOf and have been facing the same issue.

@Writingsinfo
Copy link

Writingsinfo commented Oct 2, 2024

The issue we are seeing is that when we switch options, the default values are restored only for the fields that are common to both the options. Eg. Link

In this example, when you switch from option-1 to option-2 and then back to option-1, default value for lorem is not restored.

@nickgros
Copy link
Contributor

nickgros commented Oct 4, 2024

@Becaan We took another look at your schema and realized that the issue is that the "Heart and Vascular System" property is missing "type": "object"`. If you add that, it works (playground link)

@nickgros
Copy link
Contributor

nickgros commented Oct 4, 2024

@Writingsinfo @heath-freenome is going to have a PR soon that will hopefully fix your issue in #4322

@Nickvajani
Copy link

Thank you @nickgros and @heath-freenome for jumping on it so quickly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
any-one-all-of Related to fixing anyOf, oneOf or allOf defaults
Projects
None yet
Development

No branches or pull requests

4 participants