-
Notifications
You must be signed in to change notification settings - Fork 4
Object
Sergej edited this page Feb 1, 2020
·
4 revisions
Auto-generated based on property expressions.
Leaf node must be non-object type, will be parsed according to its type;
const schema = new Schema<Model>()
.with(m => m.ObjProp.Lvl2ObjProp.Lvl3StrProp, /^[A-z]+\.[A-z]+$/)
.build();
Schema can be split in multiple chunks and applied on child properties.
const lvl2schema = new Schema<Model2>()
.with(m => m.Lvl2ObjProp.Lvl3StrProp, /^[A-z]+\.[A-z]+$/);
const schema = new Schema<Model>()
.with(m => m.ObjProp, lvl2schema)
.build();
Dictionaries (see additional properties)
Where an object is a dictionary (an object with arbitrary properties that are not defined as part of schema) use DictionarySchema to define the schema for child items
For example to define a schema for JSON:
export interface Model {
people: [name: string]: Person
}
{
"people": {
"john": {
"age": 20
},
"mary": {
"age": 24
}
}
}
Use DictionarySchema to validate age of each person in dictionary:
const personSchema = new Schema<Person>().with(p => p.Age, x => x >= 18;
const schema = new DictionarySchema<Model>()
.with(m => m.People, personSchema)
.build();
⚠ Not yet supported.
Proposed implementation:
const schema = new Schema<Model>()
.with(m => m.ObjProp, x => x < 3)
.build();
Supported operators: ==
, ===
, >=
, <=
, >
, <
⚠ Not yet supported.
No proposed implementation.
⚠ Not yet supported.
No proposed implementation.