I have the following json schema for my web app.
{
"type":"object",
"properties": {
"person_identifier":{
"type":"object",
"oneOf":[
{"$ref":"#/person_identifier/rememberme_id"},
{"$ref":"#/person_identifier/email"},
{"$ref":"#/person_identifier/account_number"}
],
"email":{
"type":"string"
},
"rememberme_id":{
"type":"string"
},
"account_number":{
"type":"string"
}
}
}
}
My goal is to accept only one of the three "person_identifier"-email, rememberme_id or account_number in the api request to my application. I am not able to validate that the above schema will enforce the required constraints. I have tried validating on jsfiddle.com but it shows that my schema is not validating input correctly. Here is my code for validation on jsfiddle.com:
var data, schema;
schema = {
person_identifier:{
type:'object',
'oneOf':[
{$ref:'#/person_identifier/rememberme_id'},
{$ref:'#/person_identifier/email'},
{$ref:'#/person_identifier/buyer_account_number'}
],
'email':{
type:'string'
},
'rememberme_id':{
type:'string'
},
'account_number':{
type:'string'
}
}
};
data = {
person_identifier: {
email: 'abc@abc.com',
rememberme_id: '1345'
}
};
alert('Validation: ' + tv4.validate(data, schema, true));
For example, jsfiddle validates the data as correctly satisfying the schema when it should not. Only one input identifier should be allowed. I have referred almost all available questions and documentation on using oneOf. Any pointers as to what I am doing incorrectly? Thank you.