概述
我有很多 .yaml 文件和验证它们的模式。有时,一个“不正确”的值实际上是正确的。
我需要一些方法来忽略某些字段。不应对这些字段执行任何验证。
例子
## file -- a.yaml
some_dict:
some_key: some_valid_value
## file -- b.yaml
some_dict:
some_key: some_INVALID_value # cerberus: ignore
我怎样才能做到这一点?
我有很多 .yaml 文件和验证它们的模式。有时,一个“不正确”的值实际上是正确的。
我需要一些方法来忽略某些字段。不应对这些字段执行任何验证。
## file -- a.yaml
some_dict:
some_key: some_valid_value
## file -- b.yaml
some_dict:
some_key: some_INVALID_value # cerberus: ignore
我怎样才能做到这一点?
cerberus包支持“开箱即用”的复合验证。validation-success、validation-fail或validation-skipped- rule_caption: check-required-fields
rule_vpath: "@"
validation_schema:
person_fname:
type: string
required: true
person_lname:
type: string
required: true
person_age:
type: string
required: true
- rule_caption: check-age-range
rule_vpath: '@|@.person_age'
validation_schema:
person_age:
"min": 2
"max": 120
- rule_caption: check-underage-minor
rule_vpath: '[@]|[? @.person_age < `18`]'
validation_schema:
prize_category:
type: string
allowed: ['pets','toys','candy']
prize_email:
type: string
regex: '[\w]+@.*'
rule_vpath,它告诉系统什么时候触发特定的规则,这增加了对 jmespath 的依赖。