如何基于JSON值移除JSON Schema中的allOf属性
基于JSON值简化带
allOf的JSON Schema 原JSON Schema的工作逻辑
- 当
switch字段值为true时,objectDependingOnSwitch对象必须包含一个名为switchIsTrue的字符串类型属性 - 当
switch字段值为false时,objectDependingOnSwitch对象必须包含一个名为switchIsFalse的字符串类型属性
原JSON Schema代码
{ "type": "object", "properties": { "switch": { "type": "boolean" }, "objectDependingOnSwitch": { "type": "object" } }, "allOf": [ { "if": { "properties": { "switch": { "const": true } } }, "then": { "properties": { "objectDependingOnSwitch": { "type": "object", "properties": { "switchIsTrue": { "type": "string" } } } } } }, { "if": { "properties": { "switch": { "const": false } } }, "then": { "properties": { "objectDependingOnSwitch": { "type": "object", "properties": { "switchIsFalse": { "type": "string" } } } } } } ] }
问题
是否可以基于给定的JSON值移除allOf属性?
举个例子,给定如下JSON值:
{ "switch": true }
期望得到简化后的差异化JSON Schema:
{ "type": "object", "properties": { "switch": { "type": "boolean" }, "objectDependingOnSwitch": { "type": "object", "properties": { "switchIsTrue": { "type": "string" } } } } }
内容的提问来源于stack exchange,提问作者Rashomon
相关产品推荐
相关产品推荐

