Trying to build a schema using JSON.NET to validate a color provided as either RGB or CMYK
This should validate:
{
"color": {
"RGB": {
"r": 100,
"g": 100,
"b": 100
}
}
}
this should not:
{
"color": {
"RGB": {
"r": 100,
"g": 100,
"b": 100
},
"CMYK": {
"c": 5,
"m": 10,
"y": 60,
"k": 30
}
}
}
This is my schema (below), and have tried using min/max Items to do what (I think) oneOf would do. The reason I am not using "oneOf" directly is because there does not seem to be the ability to add this in code which is what I need using JSON.NET, instead of passing the schema as a string. I want to be able to use JObject.Parse(...) once I have something working and I could not find any documentation related to oneOf/anyOf in JSON.NET. Any pointers much appreciated
{
"id": "color_spec.json",
"type": "object",
"required" : true,
"properties": {
"color": {
"type": "object",
"required" : true,
"minItems" : 1,
"maxItems" : 1,
"properties":
{
"RGB": {
"type": "object",
"required" : true,
"properties":
{
"r": {
"type": "number",
"required" : true
},
"g": {
"type": "number",
"required" : true
},
"b": {
"type": "number",
"required" : true
}
}
},
"CMYK": {
"type": "object",
"properties":
{
"c": {
"type": "number",
"required" : true
},
"m": {
"type": "number",
"required" : true
},
"y": {
"type": "number",
"required" : true
},
"k": {
"type": "number",
"required" : true
}
}
}
}
}
}
}