H<-:
foo:
type: str
default: bar
validator:
# fields:
# v: Any
# info: FieldValidationInfo
fields: ['v', 'info']
mode:
enum: ['before', 'after', 'wrap', 'plain']
default: after
body:
assert->: "{{isinstance(v, 'str')}}"
return->: v
H<-:
foo:
type: str
default: bar
validators:
foo:
assert->: "{{isinstance(v, 'str')}}"
return->: v
validator:
return->: v --if type(v) == 'str' --else raise Wrong type
FieldValidationInfo<-:
data:
type: Context
default->: var public_context
context:
type: union[Context]
default->: var public_context
Config<-:
args: ['data', 'context']
Old
H<-:
foo:
type: str
default: bar
validators:
- if: foo is None
return: ''
- if: not type(foo, 'str')
return: ''
- if: not regex_match(foo, '^[a-zA-Z]')
return: ''
validator:
if: foo is None
return: ''
H<-:
type:
enum:
- int32
- int64
validator:
validator:
if:
return:
validator:
field:
type: str
default: v
info:
type: FieldValidationInfo
default: info
init:
<-:
exec:
var: var var --if var!='item'
values: var var --if values!='values'
exec:
Hook Field Validators
Validate fields with custom logic similar to pydantic's validation
Proposal Status: implemented
Issue Number: 241
Proposal Doc: hook-field-validators.md
Overview
Examples
Simple example where we have an if and return.
Old