Home Reference Source Test Repository
import SchemaClass from 'json-schema-class/src/SchemaClass.js'
public class | source

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
   )
 }

Test:

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

Class Validator - Instance of ajv.compile()

Method Summary

Public Methods
public

Validate data against the current schema

Public Constructors

public constructor(schema: Schema) source

Accepts a JSON Schema pattern for Model Building

Params:

NameTypeAttributeDescription
schema Schema

Schema for the new Class

Public Members

public events: * source

Event Emitter

See:

public merge: * source

A Merge utility for JavaScript Objects

See:

public abstract schema: Schema source

The Schema for this Class

See:

public abstract validator: * source

Class Validator - Instance of ajv.compile()

See:

Public Methods

public validate(data: Object): Object source

Validate data against the current schema

Params:

NameTypeAttributeDescription
data Object

Return:

Object

data