0
我想在我的模式中使用数组(项目)。数组中的每个对象可以是架构中概述的“帧类型”之一。JSON模式 - 在项目数组中使用oneOf
我开发的模式下面给出:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"required": [
"Campaign_name",
"Legals"
],
"properties": {
"Campaign_name": {
"type": "string",
"minLength": 3
},
"Legals": {
"type": "object",
"properties": {
"legal-button-label": {
"type": "string",
"minLength": 6
},
"legal-text": {
"type": "string",
"minLength": 15
}
}
},
"Banner_120x600": {
"type": "object",
"properties": {
"serve-backup": {
"type": "object",
"properties": {
"choice": {
"type": "string",
"enum": [
"yes",
"no"
]
},
"image": {
"type": "string",
"pattern": "^([a-zA-Z|-]+)([.])(gif|jpeg|jpg|png)$"
}
}
},
"background": {
"type": "string",
"pattern": "^([a-zA-Z|-]+)([.])(gif|jpeg|jpg|png)$"
},
"logo": {
"type": "string",
"pattern": "^([a-zA-Z|-]+)([.])(gif|jpeg|jpg|png)$"
},
"loop": {
"type": "integer",
"enum": [
0,
1,
2
]
},
"frames": {
"type": "array",
"minItems": 1,
"maxItems": 6,
"items": {
"oneOf": [
{
"$ref": "#/frame-type/INTRO-FRAME"
},
{
"$ref": "#/frame-type/OFFER-FRAME-TYPE-1"
}
]
}
}
}
}
},
"frame-type": {
"INTRO-FRAME": {},
"OFFER-FRAME-TYPE-1": {}
}
}
然而,JSON没有根据模式验证。我正在开发的JSON是如下:
{
"Campaign_name": "OSM DT DATA",
"Legals": {
"legal-button-label": "Click for Legals",
"legal-text": "Requires 3G/Wi-Fi. Content depends..."
},
"Banner_120x600": {
"serve-backup": {
"choice": "no",
"image": "backup.jpg"
},
"background": "background.png",
"logo": "sky-logo.png",
"loop": 2,
"frames": [
{
"type": "INTRO-FRAME"
},
{
"type": "OFFER-FRAME-TYPE-1"
}
]
}
}
我填充了模式,它仍然无法验证。 – Berni
你是如何填充它们的?你如何验证它? –
嗨,我发现了一个不使用oneOf的解决方案。我会更新问题并回答它。感谢您的时间和建议。 – Berni