Closed hazedav closed 3 years ago
In YAML, true
is a boolean, not a string (see the definition of bool in the YAML spec):
Regexp: y|Y|yes|Yes|YES|n|N|no|No|NO |true|True|TRUE|false|False|FALSE |on|On|ON|off|Off|OFF
All of the above will be loaded into python as a boolean and, thus, fail any sort of regex (string) test. Yamale sits behind a yaml-to-python parser (pyyaml or ruamel.yaml), and does not know what the truth-y value looked like.
Instead, you could use enum()
with a single option:
myfield: enum(True)
That should allow only documents that have myfield
set to a truth-y value.
In case it's useful in the future, you can force a bool-like string to be interpreted as a string by using single or double quotes (see 7.3. Flow Scalar Styles in the YAML spec), like so:
myfield: 'true'
I hope this helps!
Makes perfect sense.
Thanks for helping @mechie!
As a yaml schema validator I wanted to ensure that the value of
myfield
is set totrue
. I am attempting to achieve this viaregex()
and notbool()
becausebool()
allows both truth and non-truthy values.So I set up a yamale schema validation file
true_schema.yaml
:An a
true_test.yaml
:When running
yamale
:Two things seem strange:
true
asTrue
. This isn't a deal breaker as I can easily make theregex()
case insensitive with[Tt]
and/orignore_case=True
.True
as a regex match. I have even tried regex of^.*$
...Please advise.