Schema Definition

The schema definition is a dictionary describing the data schema.

The main entry for data validiation is the root key. It's value is the data type definition of the input data.

To make the definition of the data structure and types more easy there are other keys/features available:

  • Custom Data Types: Under the key custom_data_types you can define customized data types based on the built-in data type of the module. For more information see Custom Data Types.
  • Template: Under the key templates you can define data definition templates. For more information see Templates.
  • Short Data Type Definition: Instead of using the extended data type definition as a dictionary for a plain data type (without restritions) you can shorten this to the data type string. I.e. {"type": "str"} --> "str"

Schema Definition Syntax

Table

Key/Option Type Default Value Restrictions Description
name str Schema name
description str Schema description
root str|dict Root data type definition
custom_data_types dict Define data types on base of built-in data types
    < str > dict Mustn't match built-in data type names Custom data type name
        type str built-in data type name
        < option > value built-in data type definition option
templates dict Define data type definition options as templates
    < str > dict Template name
        < option > any data type definition option
template_merge_options dict Define schema-global template merge instructions
    recursive bool True Merge data type definition options in template options recursively.
If false, data type defintion options overwrites template options.
    list_merge bool append_rp Allowed values:
- append
- append_rp
- prepend
- prepend_rp
- replace
How lists within options data should be merged.

YAML

name: < str >
description: < str >

root: < str|dict >

custom_data_types:
  < custom data type name >:
    type: < str >
    < str >: < value >

templates:
  < template name >:
    < str >: < value >
template_merge_options:
  recursive: < bool >
  list_merge: < str >

Example

name: Data Schema
description: Example schema definition

root:
  type: dict
  keys:
    id: int_1_255
    name:
      template: min1_max1000
      type: str
      description: "Username"
    high_id:
      template: int_100_200
    int_or_str:
      template: my_multitype
      default_value: 100

custom_data_types:
  int_1_255:
    type: int
    minimum: 1
    maximum: 255

templates:
  min1_max1000:
    minimum: 1
    maximum: 1000
  int_1_1000:
    template: min100_max1000
    type: int
  int_1_200:
    template: int_100_1000
    maximum: 200
    template_merge_options:
      recursive: true
  my_multitype:
    type: multitype
    types:
      - type: str
      - template: int_100_1000
template_merge_options:
  recursive: false