Child Properties
You can define a schema hierarchy by adding child properties using the .property() method. Each child
property is itself a schema that can have its own properties, allowing an arbitrarily deep tree structure.
In most cases, it is best1 to extend a schema based on one of the prebuilt object or array schemas
registered with SchemaResolver:
new Schema('object')
.property('database', new Schema('object')
.property('host', new Schema('string').default('localhost'))
.property('port', new Schema('number').default(5432))
)
.property('server', new Schema('object')
.property('port', new Schema('number').default(3000))
);
Arrays
You can also define child properties of array schemas. The wildcard property can be used to substitute for any array index:
new Schema('array')
.property('*', new Schema('string').validator('$alpha'))
but you can also define tuples explicitly:
new Schema('object')
.property('xyz', new Schema('array')
.property('0', new Schema('number').validator('$positive'))
.property('1', new Schema('number').validator('$positive'))
.property('2', new Schema('number').validator('$positive'))
)