Dictionary Data Type

A dict data type tests data for being an instance of python's built-in class dict.

Features/Limitations

  • Check data type of key values.
  • Regex Mode matches keys based on regex patterns.
  • Advanced data key validation:
  • Check data for required keys
  • Validate restrictions among data keys like requires, excludes or xor
  • Supports Referencing Feature. Adds an option to filter key/value pairs used as reference value

Dictionary Definition Syntax

Table

Key/Option Type Default Value Restrictions Description
type str 'dict'
description str Data type description
default_value Must match data type's type(s) Value used to set as default value
convert_to str Allowed values:
- str
regex_mode bool False Enable testing strings against regex strings
regex_fullmatch bool True Full string must match
regex_multiline bool False Regex ^ and $ matches to newline character
replace_empty_to any An empty input value will be replaced by this data
keys dict[dict|str]
  < key_name > dict|str
    option 1 str Data type str (short definition)
    option 2 dict/code> Data type definition
restrictions dict/code>
  required list[str]|str
    option 1 str Allowed_value: all
    option 2 list[str]
    - < key_name > str
  keys dict/code>
    < key_name > dict/code>
      excludes list[str]/code>
        < key_name > str
      requires list[str]/code>
        < key_name > str
  xor_required list[list]/code>
    - list[str]/code> Min length: 2 Data's keys must match one and only one of these
      - < key_name > str
ignore_unknown_keys bool False
True, if 'keys' is not defined
template str must be definded in schema Merge options from this template
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 str append_rp Allowed values:
- append
- append_rp
- prepend
- prepend_rp
- replace
How lists within options data should be merged.
reference dict|str
  option 1 str Reference keys (implies unique global mode)
  option 2 dict
  key str required
  mode str Allowed values:
- unique
- producer
- consumer
  unique_scope str Allowed values:
- global
- namespace
  producer_scope str Allowed values:
- global
- namespace
  consumer_scope str Allowed values:
- global
- namespace
  allow_orphan_producer bool True
  credit int 1 (if mode consumer) min: 0
references list[dict|str]
  - dict|str
    option 1 str Reference keys (implies unique global mode)
    option 2 dict
    key str required
    mode str Allowed values:
- unique
- producer
- consumer
    unique_scope str Allowed values:
- global
- namespace
    producer_scope str Allowed values:
- global
- namespace
    consumer_scope str Allowed values:
- global
- namespace
    allow_orphan_producer bool True
    credit int 1 (if mode consumer) min: 0
doc_value_name str Set value name for documentation

YAML

type: dict
description: <str>
default_value: <default_value>

convert_to: <str>
regex_mode: <true|false>
regex_fullmatch: <true|false>
regex_multiline: <true|false>
replace_empty_to: <any>

keys:
  <key_name>:
    # Multitype!!!
    <str>
    # or
    <dict>
restrictions:
  required:
    # Multitype!!!
    'all'
    # or
    - <str>
  keys:
    excludes:
      - <key_name>
    requires:
      - <key_name>
  xor_required:
    -
      - <key_name>
ignore_unknown_keys: <true|false

template: <str>
template_merge_options:
  recursive: <true|false>
  list_merge: <append|append_rp|prepend|prepend_rp|replace>

reference: <reference_definition>
  # Multitype!!!
  <str>
  # or:
  key: <str>
  mode: <unique|producer|consumer>
  unique_scope: <global|namespace>
  producer_scope: <global|namespace>
  consumer_scope: <global|namespace>
  allow_orphan_producer: <true|false>
  credits: <int>
references:
  - <reference_definition>
    # Multitype!!!
    <str>
    # or
    key: <str>
    mode: <unique|producer|consumer>
    unique_scope: <global|namespace>
    producer_scope: <global|namespace>
    consumer_scope: <global|namespace>
    allow_orphan_producer: <true|false>
    credits: <int>

doc_value_name: <str>

Example

type: dict
description: "Example dict definition with regex mode enabled and some key restrictions in place"
default_value:
  a11: 1
reference:
references:
  - 'unique_key'
  - key: 'consumer_key'
    mode: consumer
    keys:
      - b11  # If key b11 is in data it is included in reference data
      - 12  # If key 12 is in data it is included in reference data

keys:
  11: str
  a11: int
  a12: int
  12: str
  b11: float
  b12: float

restrictions:
  keys:
    b11:
      requires:
        - a11  # If key b11 in data key a11 must be in data, too
      excludes:
        - b12  # If key b11 in data key b12 mustn't be in data
  required:
    - a11  # Key 'a11' must be in data
  xor_required:
    -  # If key 11 is in data key 12 mustn't be in data - and vice-versa
      - 11
      - 11