JsonSchema

jsonschema. JsonSchema

Functionality related to JSON schema

Constructor

new JsonSchema()

Source:

Members

buildHook :Hook

Description:
  • Hook which invokes every time the schema is built
Source:
Hook which invokes every time the schema is built
Type:
  • Hook

built :Object

Description:
  • The raw built JSON schema
Source:
The raw built JSON schema
Type:
  • Object

compiled :function

Description:
  • The compiled schema validation function
Source:
The compiled schema validation function
Type:
  • function

enableCache :Boolean

Description:
  • Whether caching is enabled for this schema
Source:
Whether caching is enabled for this schema
Type:
  • Boolean

extensions :Array.<String>

Description:
  • List of extensions for this schema
Source:
List of extensions for this schema
Type:
  • Array.<String>

filePath :String

Description:
  • File path to the schema
Source:
File path to the schema
Type:
  • String

isBuilding :Boolean

Description:
  • Whether the schema is currently building
Source:
Whether the schema is currently building
Type:
  • Boolean

lastBuildTime :Number

Description:
  • The last build time (in milliseconds)
Source:
The last build time (in milliseconds)
Type:
  • Number

raw :Object

Description:
  • The raw schema data for this schema (with no inheritance/extensions)
Source:
The raw schema data for this schema (with no inheritance/extensions)
Type:
  • Object

validator :external:Ajv

Description:
  • Reference to the Ajv validator instance
Source:
Reference to the Ajv validator instance
Type:
  • external:Ajv

xss :Object

Description:
  • Reference to the local XSS sanitiser instance
Source:
Reference to the local XSS sanitiser instance
Type:
  • Object

Methods

addExtension(extSchemaName)

Description:
  • Adds an extension schema
Source:
Parameters:
Name Type Description
extSchemaName String

(async) build(options) → {JsonSchema}

Description:
  • Builds and compiles the schema from the $merge and $patch schemas
Source:
Parameters:
Name Type Description
options SchemaBuildOptions
Returns:
Type
JsonSchema

getObjectDefaults(schema, memo) → {Object}

Description:
  • Returns all schema defaults as a correctly structured object
Source:
Parameters:
Name Type Description
schema Object
memo Object For recursion
Returns:
The defaults object
Type
Object

(async) getParent() → {JsonSchema}

Description:
  • Returs the parent schema if $merge is defined (or the base schema if a root schema)
Source:
Returns:
Type
JsonSchema

(async) isBuildValid() → {Boolean}

Description:
  • Determines whether the current schema build is valid using last modification timestamp
Source:
Returns:
Type
Boolean

(async) load() → {JsonSchema}

Description:
  • Loads the schema file
Source:
Returns:
This instance
Type
JsonSchema

(async) patch(baseSchema, patchSchema, options) → {Object}

Description:
  • Applies a patch schema to another schema
Source:
Parameters:
Name Type Description
baseSchema Object The base schema to apply the patch
patchSchema Object The patch schema to apply to the base
options ApplyPatchOptions
Returns:
The base schema
Type
Object

(async) sanitise(dataToValidate, options) → {Object}

Description:
  • Sanitises data by removing attributes according to the context (provided by options)
Source:
Parameters:
Name Type Description
dataToValidate Object The data to be sanitised
options SchemaSanitiseOptions
Returns:
The sanitised data
Type
Object

(async) validate(dataToValidate, options) → {Promise}

Description:
  • Checks passed data against the specified schema (if it exists)
Source:
Parameters:
Name Type Description
dataToValidate Object The data to be validated
options SchemaValidateOptions
Returns:
Resolves with the validated data
Type
Promise