question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

oneOf dependencies result in "duplicate" validation errors

See original GitHub issue

Prerequisites

  • 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:open
  • Created 4 years ago
  • Reactions:2
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Saulzicommented, Mar 5, 2020

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)

properties: {
     keyFormat: {
         enum: ["Plain", "Encrypted"]
         default: "Plain"     // note this is important because of undefined values
    }.
   required: ["keyFormat"].
   if: {
       properties: { keyFormat: { const: "Encrypted" } 
  }.
  then: {
       properties: { 
              validation: {
                    minLength: 40
              }
       }
  },
  else: {
       properties: { 
              validation: {
                    minLength: 20
              }
       }
  }

}
0reactions
Saulzicommented, Mar 6, 2020

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Removing the duplication in a JSON schema that uses oneOf ...
I've come up with the schema below, which I think works, but I'm duplicating all of the other properties in each item of...
Read more >
Makefile Generation Fails with Duplicate References in ... - IBM
When this error is encountered, a component exists with dependencies on two or more library components which reference the same element from the...
Read more >
Detecting duplicate dependencies in Maven - Andres Almiray
The editor does show some sort of problem with the duplicate dependencies, however I must say that having an icon on the line...
Read more >
Salesforce Error: Use one of these records?
Use one of these records? Normally, this error relates to the Salesforce's Standard Duplicate rule. If you have this rule enabled, it'll be...
Read more >
How to debug the mysterious "duplicate value found ...
Deployment Error or DML Error? If you Google "duplicate value found: <unknown>...", the results you get will cover a wide variety of root ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found