特定の配列要素が必要です:私はsymbolic-name="displayName"
JSONスキーマは、私はJSONスキーマなどの属性のリストを定義し
と正確に一つの属性を持っているリストを要求したい
{
"$schema": "http://json-schema.org/schema#",
"type": "object",
"definitions": {
"attribute": {
"type": "object",
"properties": {
"symbolic-name": { "type":"string"},
"value": { "type":"string"}
},
"required": ["symbolic-name", "value"]
},
"displayname": {
"type": "object",
"properties": {
"symbolic-name": {"enum":["displayName"]},
"value": { "type":"string"}
},
"required": ["symbolic-name", "value"]
}
},
"properties": {
"attributes":{
"type": "array",
// This is the crucial point:
"items": {"oneOf": [
{"$ref": "#/definitions/attribute"},
{"$ref": "#/definitions/displayname"}
]},
"uniqueItems": true
}
}
}
を有効なデータオブジェクトは次のようになります:
{
"attributes":[
{"symbolic-name": "displayName", "value": "Display Name"},
{"symbolic-name": "somethingElse", "value": "value1"}
{"symbolic-name": "somethingElse", "value": "value2"}
]
}
displayName属性が "oneOf"と一致するだけでなく、両方の制限にも一致するため、これは検証できません。私はそれを "allOf"に変更することはできません。なぜなら、displayNameのそばの他のすべての属性はもはや一致しないからです。