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