23andMe / Yamale

A schema and validator for YAML.
MIT License
666 stars 88 forks source link

Add none=False default to strict mode, or different option #231

Open lod opened 9 months ago

lod commented 9 months ago

The practice of accepting None as a valid value for optional keys is surprising and hard to debug. I don't feel it should be accepted in a schema managed file, particularly if the strict mode is specified. Possibly a --strict-types option (and equivalent function parameter) should be used to preserve backwards compatibility.

For example including a map doesn't require the presence of elements of that map

Include schema with optional portion:

base:
  element: include('element', required=False)
---
element:
  required_field: str()

Pass because element is None, despite missing required_field

base:
  element:

Adding the none=False field here produces the expected behaviour, it should be the default behaviour.