【发布时间】:2018-12-19 05:06:03
【问题描述】:
如何覆盖由“allOf”关键字继承的 json 模式中定义的验证规则?
例子:
{
"$schema": "http://json-schema.org/draft-06/schema",
"title": "My JSON Schema",
"description": "",
"definitions": {
"a": {
"type": "object",
"properties": {
"b": {
"type": "object",
"properties": {
"c": {
"type": "string",
"minLength": 1,
"maxLength": 100
}
},
"required": [
"c"
]
}
},
"required": [
"b"
]
}
},
"properties": {
"main": {
"type": "object",
"allOf": [
{
"$ref": "#/definitions/a"
}
]
},
"sub": {
"type": "object",
"allOf": [
{
"$ref": "#/definitions/a"
}
]
}
}
}
json 模式定义了两个对象:
- 主要
- 分
两个对象都从定义的对象“a”继承它们的属性 但是对象“sub”应该有其他属性b.c的验证规则(目前是minLength 1和maxLength 100)。
所以当然下面的json是无效的:
{
"main" :{
"b": {
"c": "This property has a min length"
}
},"sub" : {
"b": {
"c": ""
}
}
}
如何覆盖属性 b.c 的验证规则?
【问题讨论】:
标签: jsonschema