我正在使用 jsonschema 来验证描述条目(给定类型)如何显示的条目类型。这些条目可以有页面并被分成多个方面。
页面和方面都可以有条件,我想重用一个基本模式,即使方面的条件可以有页面条件没有的 2 个其他属性。
这是我经常碰到的普遍问题。我想扩展架构,同时能够在所有情况下将“additionalProperties”设置为 false。
我也不认为有可能用 anyOf、allOf 修复它而没有重复。
还是我应该放弃additionalProperties或接受重复项?
{
"$comment": "page condition",
"type": "object",
"properties": {
"condition": {
"type": "object",
"properties": {
"aspect": {
"type": "string"
},
"value": {
"type": "string"
},
"compare": {
"type": "string"
}
},
"required": [
"aspect",
"value"
],
"additionalProperties": false
}
}
}
...
{
"$comment": "aspect condition",
"type": "object",
"properties": {
"condition": {
"type": "object",
"properties": {
"aspect": {
"type": "string"
},
"value": {
"type": "string"
},
"compare": …Run Code Online (Sandbox Code Playgroud)