2016-07-18 66 views
0

我试图创建一个JSON模式为现有的JSON文件看起来是这样的一个名为“类型”的属性类型定义:创建使用JSON模式

{ 
    "variable": { 
    "name": "age", 
    "type": "integer" 
    } 
} 

在架构,我想为确保type属性的值为stringinteger

{ 
    "variable": { 
    "name": "string", 
    "type": { 
     "type": "string", 
     "enum": ["string", "integer"] 
    } 
    } 
} 

不幸的是它吹了消息:ValidationError {is not any of [subschema 0]...

我读过JSON模式中有“无保留字”,所以我假设一种类型是有效的,假设我正确地声明它?

回答

1

根据the specification,在Valid typestype

该关键字的值必须是字符串或数组。如果它是一个数组,则数组的元素必须是字符串,并且必须是唯一的。 字符串值必须是核心规范定义的七种基本类型之一。

后来,在Conditions for successful validation

实例成功匹配,如果它的原语类型是关键字定义的类型之一。回想一下:“数字”包含“整数”。

你的情况:

{ 
    "variable": { 
    "name": "string", 
    "type": ["string", "integer"] 
    } 
}