Skip to content
Sergej edited this page Feb 1, 2020 · 4 revisions

Properties & Required Properties

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();

Nested Schema

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();

Size

⚠ Not yet supported.
Proposed implementation:

const schema = new Schema<Model>()
    .with(m => m.ObjProp, x => x < 3)
    .build();

Supported operators: ==, ===, >=, <=, >, <

Dependencies

⚠ Not yet supported.
No proposed implementation.

Pattern Properties

⚠ Not yet supported.
No proposed implementation.