json - json 模式验证:对值的条件依赖
问题描述
我有以下 json 文件:
{
"REFERENCE": "genome",
"END": "pair",
"INPUT1": "in1.fq",
"INPUT2": "in2.fq",
"INPUT": "in.fq",
"GENOME": "genome_file.fa",
"ANNOTATION": "annotation_file.gff",
"TRANS" : "trans_file.txt"
}
条件依赖如下:
- 如果 REFERENCE == "genome" 则需要 "GENOME" 和 "ANNOTATION"
- 如果 REFERENCE == "transcriptome" 那么 "TRANS" 是必需的
- 如果 END == "pair" : 那么 "INPUT1" 和 "INPUT2" 是必需的
- 如果 END == "single" : 那么 "INPUT" 是必需的
这是架构,但它不起作用(我尝试过 allOf、anyOf 但它不起作用)。没有设法使用如果,那么,否则。
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "title",
"description": "description",
"type": "object",
"properties": {
"END": {
"type": "string",
"enum": [
"pair",
"single",
]
},
"REFERENCE": {
"type": "string",
"enum": [
"genome",
"transcriptome",
],
},
"GENOME": {
"type": "string"
},
"ANNOTATION": {
"type": "string"
},
"TRANS": {
"type": "string"
},
"INPUT1": {
"type": "string"
},
"INPUT2": {
"type": "string"
},
"INPUT": {
"type": "string"
}
},
"allOf": [
{
"properties": {
"REFERENCE": {
"const": "genome"
}
},
"required": ["GENOME", "ANNOTATION"]
},
{
"properties": {
"REFERENCE": {
"const": "transcriptome"
}
},
"required": ["TRANS"]
},
{
"properties": {
"END": {
"const": "pair"
}
},
"required": ["INPUT1", "INPUT2"]
},
{
"properties": {
"END": {
"const": "single"
}
},
"required": ["INPUT"]
}
]
}
解决方案
推荐阅读
- java - 无效的 splitapkbundle。捆绑目标未知语言:[gr]
- java - 当其中一个抛出异常时如何防止执行runnables
- c++ - std::hardware_ destroyer_interference_size 的可靠性
- docker - Docker ADD 不会复制子文件夹的内容
- r - 错误:外部实体错误,getURl 错误
- css - 导航栏链接边距类在 Tailwind CSS 中似乎重复,有更好的方法吗?
- azure - 尝试使用 Azure Pipelines 自动部署,但由于未使用 Windows 而发出警告?
- angular - 无法从 Angular 中的子模块访问自定义模块
- django - 使用 CheckboxSelectMultiple 保存 Django ModelForm,不选中任何框
- javascript - 如何在 getElementById 引号 + 字符串周围加上引号?