Schema

core/schema~ Schema

A class that can resolving referenced JSON schemas and create module:core/schema~DefaultValues.

Constructor

new Schema(loader, def)

Source:
Parameters:
Name Type Description
loader module:core/schema~SchemaLoader JSON schema loader.
def Object The JSON schema definition.

Methods

getArrayDefaultValue(def)

Create the module:core/schema~DefaultValue for an array-typed JSON schema.

Each possible type of the array elements defined in oneOf will be processed and a module:core/schema~DefaultValue will be added to the result array.

Source:
Parameters:
Name Type Description
def Object JSON schema definition of the array.
Returns:

getDefaultValue(def)

Create the module:core/schema~DefaultValue for any JSON schema.
Source:
Parameters:
Name Type Default Description
def Object null JSON schema definition.

getObjectDefaultValue(def)

Create the module:core/schema~DefaultValue for an object-typed JSON schema.

The first possible type of the object element defined in oneOf will be processed and its module:core/schema~DefaultValue will be merged with the module:core/schema~DefaultValue created from the properties definition.

Source:
Parameters:
Name Type Description
def Object JSON schema definition of the object.
Returns:

getReferredDefaultValue(def)

Create the module:core/schema~DefaultValue for any JSON schema that is purely defined by its $ref.
Source:
Parameters:
Name Type Description
def Object JSON schema definition.

getTypedDefaultValue(def)

Create the module:core/schema~DefaultValue for any typed JSON schema that is not purely defined by its $ref.

If the definition also contains a $ref, the module:core/schema~DefaultValue for the $ref definition will be merged to the module:core/schema~DefaultValue of the current definition.

If type of the JSON schema is of primitive types, and the nullable is set to false in the schema definition, primitive default values will be set insided the result module:core/schema~DefaultValue.

Source:
Parameters:
Name Type Description
def Object JSON schema definition.
Throws:
If type is undefined or it is 'array', 'object', or primitive types.
Type
Error

validate(obj) → {boolean|Object}

Validate an object against the JSON schema.
Source:
Parameters:
Name Type Description
obj any Object to be validated.
Returns:
Type:
boolean | Object
True if Object is valid, or validation errors.