Closed OmkarG1986 closed 1 year ago
Have you tried giving enum a Python Boolean? Like so:
create_iac_project : enum(False)
Right, @mechie is correct here. There are two things that were missed when trying to use the enum
validator:
ignore_case
keyword.https://github.com/23andMe/Yamale#enum---enumprimitives
Similarly, the required
keyword that was used in the bool
validator indicates that this field is required to be present in the yaml. It doesn't indicate what the value of the field is supposed to be. https://github.com/23andMe/Yamale#validators
Try the following schema:
create_iac_project: enum(True)
That should get you what you want.
Thank you @mildebrandt @mechie. That was a good catch. I can confirm by using enum(True)/enum(False), Its working as expected. Appreciate your quick response.
I will mark this issue as closed.
Boolean validator should have option to validate if set boolean value is either true or false as per the requirement.
e.g. I have one flag based boolean field "create_iac_project". This field is always required to set to true. Withe below boolean validation in schema it doesnt serve the purpose as validation passes even if the filed value is set to boolean false.
create_iac_project : bool(required=True)
As a WA i tried to use enum validator but enum treats the arguments of type string instead of boolean and i couldnt find anyways to pass type of the argument to enum.
create_iac_project : enum('false', ignore_case=True)
my Data/yaml file that I am validating looks like below: