I need to define a Json Schema which accepts an array. This array can have one of the following structures:
1: ["StringConstant",{someKeys:someValues},"StringConstant","StringConstant"]
2: [{someKeys:someValues},{someKeys:someValues},...]
3: ["StringConstant",{someKeys:someValues},"StringConstant","StringConstant","StringConstant",{someKeys:someValues},"StringConstant","StringConstant",...]
4: ["StringConstant",{someKeys:someValues},"StringConstant","StringConstant",{someKeys:someValues},...]
The StringConstant are all the same and the Objects {someKeys:someValues}all have the same keys.
Basically the Object {someKeys:someValues} can stand on its own or with a leading StringConstant and two trailing StringConstant
Currently I have:
{
"type": "array",
"items" : [
{
"const": "first"
},
{
"type": "object",
"properties":{...}
},
{
"const": "second"
},
{
"const": "third"
}
],
"additionalItems": false
}
But this schema requires the constants to always be present.
Is there a way to define and validate the required structure with JsonSchema?
One possible way I found is to define the array objects as anyOf and write the validation for the leading and trailing constants myself.