Skip to content

0.13.0 - BACKWARDS INCOMPATIBLE: defaults are now normalized, and `default_copy` and `metadata` are introduced

Compare
Choose a tag to compare
@radix radix released this 08 Aug 19:13

This new feature release has one important backwards incompatible change:

BACKWARDS INCOMPATIBLE: defaults are now normalized

Previously, a default value would not have any further schema applied to it. That means that the following schema would not fail when applied to {}:

type: dict
fields:
    foo:
      type: string
      default: 0

In 0.13.0, this will now raise a BadType error when applied to {}, because the default value, 0, does not match the type string.

More importantly, this allows for more easily normalizing to nested structures with defaults:

type: dict
fields:
  foo:
    type: dict
    default_setter: dict
    fields:
      bar: {type: integer, default: 0}

Previously, this schema applied to {} would result in {foo: {}}. Now, in 0.13.0, it will result in {foo: {bar: 0}}.

default_copy

The new default_copy directive allows specifying a value which will be (deeply) copied every time it is inserted into a document. This is an ergonomic improvement for when you want to specify a default value in YAML with mutable data structures, such as default_copy: {"foo": []}.

metadata

The new metadata directive is a no-op. It's meant to allow application authors to embed useful information into their Sureberus schemas to be used in an application-specific way.