SchemaClass
Where all things good come from! This Class uses JSON Schema Draft 4 to build basic models for the rest of the application. Please See json-schema.org and also ajv validator for the basics.
Example:
import SchemaClass from 'json-schema-class';
export MyClass extends 'SchemaClass'{
constructor(){
super({
"title": "Example Schema",
"type": "object",
"properties": {
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
},
"age": {
"description": "Age in years",
"type": "integer",
"minimum": 0
}
},
"required": ["firstName", "lastName"]
});
let model = this;
model.firstName = "My"
model.lastName = "Class"
this.validate(model) //Validate model and add missing defaults
)
}
Constructor Summary
Public Constructor | ||
public |
constructor(schema: Schema) Accepts a JSON Schema pattern for Model Building |
Member Summary
Public Members | ||
public |
events: * Event Emitter |
|
public |
merge: * A Merge utility for JavaScript Objects |
|
public abstract |
The Schema for this Class |
|
public abstract |
validator: * Class Validator - Instance of ajv.compile() |
Method Summary
Public Methods | ||
public |
Validate data against the current schema |