使用默认值验证 jsonschema,其中输入可以是对象和字符串
Validate jsonschema with defaults where input can be both object and string
我正在使用 snakemake validate which is heavily based on jsonschema 来验证我的 (yaml) 配置。用户必须选择一个选项,并且可以根据需要指定更详细的参数,否则应该默认为 config.yaml.
中的默认值
# problem that bwa is string, does not default
aligner:
bwa
# defaults nicely for align
aligner:
hisat2:
index: 'parameters'
# works!
aligner:
salmon:
index: 'parameters1'
align: 'parameters2'
我的 config.yaml 现在看起来像这样:
aligner:
description: which aligner to use
properties:
bwa:
properties:
index:
default: 'def_param'
align:
default: 'def_param'
hisat2:
properties:
index:
default: 'def_param'
align:
default: 'def_param'
salmon:
properties:
index:
default: 'def_param'
align:
default: 'def_param'
minProperties: 1
additionalProperties: false
default:
bwa:
index: -a bwtsw
align: ''
如果人们只指定一个对准器,我该如何做到它也默认?
根据您的示例,您使用的库似乎采用默认值,包括对象。因此,要设置对象 bwa
的默认值,您需要在与其属性相同的级别定义默认值,如下所示...
aligner:
description: which aligner to use
properties:
bwa:
properties:
index:
default: 'def_param'
align:
default: 'def_param'
default:
index: 'def_param'
align: 'def_param'
我认为您不想再为对象的各个属性定义默认值。
很遗憾,我无法按照您的预期测试它是否有效。
我正在使用 snakemake validate which is heavily based on jsonschema 来验证我的 (yaml) 配置。用户必须选择一个选项,并且可以根据需要指定更详细的参数,否则应该默认为 config.yaml.
中的默认值# problem that bwa is string, does not default
aligner:
bwa
# defaults nicely for align
aligner:
hisat2:
index: 'parameters'
# works!
aligner:
salmon:
index: 'parameters1'
align: 'parameters2'
我的 config.yaml 现在看起来像这样:
aligner:
description: which aligner to use
properties:
bwa:
properties:
index:
default: 'def_param'
align:
default: 'def_param'
hisat2:
properties:
index:
default: 'def_param'
align:
default: 'def_param'
salmon:
properties:
index:
default: 'def_param'
align:
default: 'def_param'
minProperties: 1
additionalProperties: false
default:
bwa:
index: -a bwtsw
align: ''
如果人们只指定一个对准器,我该如何做到它也默认?
根据您的示例,您使用的库似乎采用默认值,包括对象。因此,要设置对象 bwa
的默认值,您需要在与其属性相同的级别定义默认值,如下所示...
aligner:
description: which aligner to use
properties:
bwa:
properties:
index:
default: 'def_param'
align:
default: 'def_param'
default:
index: 'def_param'
align: 'def_param'
我认为您不想再为对象的各个属性定义默认值。
很遗憾,我无法按照您的预期测试它是否有效。