我希望在certificate
标志设置为true时定义privateKey
和secure
。这有可能实现吗?
{
type: 'object',
properties: {
'secure': {
title: 'Serve files over HTTPS',
description: 'Flag telling whether to serve contents over HTTPS and WSS',
type: 'boolean',
default: false
},
'certificate': {
title: 'Certificate file',
description: 'Location of the certificate file',
type: 'string'
},
'privateKey': {
title: 'Private key file',
description: 'Location of the private key file',
type: 'string'
}
}
答案 0 :(得分:1)
您可以使用'dependencies'关键字。
{
dependencies: {
secure: ['certificate', 'privateKey']
}
}
您甚至可以指定在存在安全时数据应该匹配的架构:
{
dependencies: {
secure: {
properties: {
certificate: {
type: 'string'
}
privateKey: {
type: 'string'
}
},
required: ['certificate', 'privateKey']
}
}
}
答案 1 :(得分:0)
您是否要求依赖于架构内容?我的意思是“模式允许的内容取决于目标(json)内容中的内容”?
你做不到。
答案 2 :(得分:0)
有一种方法,但它不漂亮。您需要使用anyOf
关键字来定义在secure
true
时您希望如何进行验证,以及secure
false
时您希望如何进行验证
{
"type": "object",
"properties": {
"secure": {
"title": "Serve files over HTTPS",
"description": "Flag telling whether to serve contents over HTTPS and WSS",
"type": "boolean"
}
},
"anyOf": [
{
"type": "object",
"properties": {
"secure": {
"enum": [true]
},
"certificate": {
"title": "Certificate file",
"description": "Location of the certificate file",
"type": "string"
},
"privateKey": {
"title": "Private key file",
"description": "Location of the private key file",
"type": "string"
}
},
"required": ["certificate", "privateKey"]
},
{
"type": "object",
"properties": {
"secure": {
"enum": [false]
}
}
}
]
}