oneOf dependencies result in "duplicate" validation errors
See original GitHub issuePrerequisites
- 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.
- I’m providing a shared playground link demonstrating the issue.
Description
We have a use case where we wish to restrict the minLength or a password based on whether the password is plain-form of encrypted. To do so we use oneOf
and dependencies to modify the pwd
property based on the keyformat
property.
Expected behavior
We would expect that when the keyformat
is set to Plain
, the minLength required during validation would be 20. When it is set to Encrypted
, the validation should check if the minLength is 40.
Actual behavior
The validation “works” in the sense that the validation errors dissapear for the Plain case when the pwd
is >20 in length and for Encrypted when it is >40 in length.
However, when selecting Plain, the validation errors will show both validation errors, i.e. the user will be told that the password must be >20 in length and >40, which is confusing (and not reflective of what the editor actually checks against in practice)
Version
Tested in the latest playground.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:5 (3 by maintainers)
I think what you are really wanting to do with your schema is use the if/then/else syntax,
unfortunately this is not supported at the moment allthough my pr https://github.com/rjsf-team/react-jsonschema-form/pull/1610 should fix this.
i.e. (the schema will be something like)
this is part of the json schema 7 spec, not all tools support it but I can confirm that it works in tools such as vscode.
please refer to
https://json-schema.org/understanding-json-schema/reference/conditionals.html