Home > Software design >  How to add invalid values enum in json schema
How to add invalid values enum in json schema

Time:11-21

If we want to add valid values for particular field in json schema, we will add like this,

"Car_Color" :{ "type":"string", "enum" :["blue", "red"] }

I want user to enter any value for this field but Orange.

I am expecting something like this,

"Car_Color" :{

"type":"string",

"Not-contain" : "orange"

}

Since there are many possibilities we can't do it using "enum". Is there anything opposite to enum. So that value can't be entered.

I want user to enter any value for this field but Orange.

I am expecting something like this,

"Car_Color" :{

"type":"string",

"Not-contain" : "orange"

}

I tried with "not" but it is not working. If any solution for this one please provide.

CodePudding user response:

You are quite close. You can use the not keyword to express what you want like this:

"Car_Color" : { 
    "type":"string", 
    "not": { "enum" :["orange", "..."] } }
}
  • Related