我想基于架构中的另一个值有条件地针对$ ref进行验证。
items: {
type: 'object',
properties: {
kind: { type: 'string', enum: ['foo', 'bar'] },
//parameters: { $ref: 'foo.json#' } // This works
parameters: {
if: {
kind: 'foo'
},
then: {
$ref: 'foo.json#'
}
}
// also tried
if: {
kind: 'foo'
},
then: {
parameters: { $ref: 'foo.json#' }
}
只要parameters
的值等于foo.json
(与kind
和{{相同),我希望根据foo
引用对bar
进行验证。 1}})。但是上述方法不起作用。取消注释部分的注释是可行的,因此它们不是等效的。
如何格式化该格式,以便有条件地将$ ref应用于基于其他值的值?
对于bar.json
枚举,我实际上有大约10个不同的值,因此,如果有一种更干净的方法,比[if / else]我更开放。
答案 0 :(得分:0)
啊明白了......
items: {
type: 'object',
properties: {
kind: { type: 'string', enum: ['foo', 'bar'] }
},
required: ['parameters'],
if: {
properties: { kind: { const: 'foo' } },
required: ['kind']
},
then: {
properties: {
parameters: {
$ref: 'fpp.json#'
}
}
}
认为if
和else
中的任何内容基本上都与主架构合并对我很有帮助。