2015-10-02 27 views
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" 
    } 
] 
} 
} 

回答

0
"oneOf": [ 
     { 
     "$ref": "#/frame-type/INTRO-FRAME" 
     }, 
     { 
     "$ref": "#/frame-type/OFFER-FRAME-TYPE-1" 
     } 
    ] 

两个achemas是空的,oneOf失败,如果一个对象,因为任何文件的空模式匹配匹配多个模式,这将永远是这样。您可以将oneOf更改为anyOf。

+0

我填充了模式,它仍然无法验证。 – Berni

+0

你是如何填充它们的?你如何验证它? –

+0

嗨,我发现了一个不使用oneOf的解决方案。我会更新问题并回答它。感谢您的时间和建议。 – Berni

0
"frames": { 
     "type": "array", 
     "minItems": 1, 
     "items": [ 
      { 
       "type" : "object", 
       "properties" : { 
        "type" : { "enum" : ["INTRO-FRAME"] } 
       } 
      }, 
      { 
       "type" : "object", 
       "properties" : { 
        "type" : { "enum" : ["OFFER-FRAME-TYPE-1"] }  
       } 
      }, 
      { 
       "type" : "object", 
       "properties" : { 
        "type" : { "enum" : ["OFFER-FRAME-TYPE-2"] }  
       } 
      }, 
      { 
       "type" : "object", 
       "properties" : { 
        "type" : { "enum" : ["CONTENT-FRAME"] } 
       } 
      } 
     ] 
    } 

我删除了“oneOf”的使用并提供了一个要验证的对象数组。

相关问题