JsonSchema

jsonschema. JsonSchema

Functionality related to JSON schema

Constructor

new JsonSchema()

Source:

Members

buildHook :Hook

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

built :Object

Source:
The raw built JSON schema
Type:
  • Object

compiled :function

Source:
The compiled schema validation function
Type:
  • function

enableCache :Boolean

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

extensions :Array.<String>

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

filePath :String

Source:
File path to the schema
Type:
  • String

isBuilding :Boolean

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

lastBuildTime :Number

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

raw :Object

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

validator :external:Ajv

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

xss :Object

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

Methods

addExtension(extSchemaName)

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

(async) build(options) → {JsonSchema}

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

getObjectDefaults(schema, memo) → {Object}

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

(async) getParent() → {JsonSchema}

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

(async) isBuildValid() → {Boolean}

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

(async) load() → {JsonSchema}

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

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

Source:
Applies a patch schema to another schema
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}

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

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

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