1

I'm trying to validate that a field is not empty only when either one of two fields is NOT empty using ajv.

E.g.

{ field1: '', field2: '2', field3: '' } // Invalid 
{ field1: '', field2: '', field3: '3' } // Invalid 
{ field1: '1', field2: '2', field3: '3' } // Valid 
{ field1: '', field2: '', field3: '' } // Valid 

I'm trying to use this schema but I don't know how to specify the OR condition.

 {
  properties: {
    field1: {
      if: { properties: { field2: { minLength: 1 } },
      //or?
      then: {
          minLength: 1
        }
      }
    }
  }

How can I add an OR to this schema?

alayor
  • 4,537
  • 6
  • 27
  • 47
  • Take a look at this post, I think it may help https://stackoverflow.com/questions/38717933/jsonschema-attribute-conditionally-required specifically the `if` `then` `else` section. – Truextacy Apr 17 '18 at 22:00

0 Answers0