如何覆盖由“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"
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
json 模式定义了两个对象:
两个对象都从定义的对象“a”继承了它们的属性,但是对象“sub”应该有属性 bc 的其他验证规则(当前它是 minLength 1 和 maxLength 100)。
所以当然下面的 json 是无效的:
{
"main" :{
"b": {
"c": "This property has a min length"
}
},"sub" : {
"b": {
"c": ""
}
}
}
Run Code Online (Sandbox Code Playgroud)
如何覆盖属性 bc 的验证规则?