BaseSchema()

The base schema object

new BaseSchema()

Constructs a schema object

Members

__isLocked

Indicates whether an object is locked. See lock.

__properties

Stores json schema properties, e.g. type, description, maxLength, etc...

isFluentSchema

For compatibility with fluent-schema. Indicates if an object is a fluent-schema object.

isTodeaSchema

Flag to indicate whether an object is a Todea Schema object.

JSON_SCHEMA_TYPE

The json schema type

MAX_PROP_NAME

The max* property name.

MIN_PROP_NAME

The min* property name.

required

Convenient getter indicates if the schema is required / not optional. See optional.

Methods

__setDefaultProp(name, defaultValue)

If property with name does not exist, the default value is set.
Parameters:
Name Type Description
name String
defaultValue *
Returns:
- The value associated with name.

__setProp(name, val, optionsopt)

Sets a value in __properties. Throws if object is locked (unless the property is allowed to be overridden), or property with the same name already exists and override is not allowed.
Parameters:
Name Type Attributes Default Description
name String Name of the property
val * The value for the property
options Object <optional>
{}
Properties
Name Type Attributes Default Description
allowOverride Boolean <optional>
false If true property override is allowed.

__validateRangeProperty(name, val)

Validate input to min/max.
Parameters:
Name Type Description
name String Property name
val Integer A non-negative integer for min/max.

compile(name, compileropt, returnSchemaTooopt) → {function}

Returns a validator function which throws ValidationError if the value it is asked to validate does not match the schema. Locks the current schema.
Parameters:
Name Type Attributes Description
name string the name of this schema (to distinguish errors)
compiler * <optional>
the ajv or equivalent JSON schema compiler to use
returnSchemaToo returnSchemaToo <optional>
whether to return jsonSchema as well as the validator
Returns:
function - call on a value to validate it; throws on error

copy()

Returns:
- A copy of the Todea Schema object. Locked objects become unlocked.

default(d)

Sets a default value for schema. According to JsonSchema, default value is just metadata and does not serve any validation purpose with in JsonSchema. External tools may choose to use this value to setup defaults, and implementations of JsonSchema validator may choose to validate the type of default values, but it's not required. Since when the default is used to populate the json, there will be something downstream that validates the json and catches issues, we omit schema validation for simplicity.
Parameters:
Name Type Description
d * The default value.

desc(t)

Sets a description.
Parameters:
Name Type Description
t String | Array.<String> The description of the schema. If an array of strings are passed in, they will be joined by a space to form the description.

examples(es)

Updates schemas examples.
Parameters:
Name Type Description
es Array.<(String|Array.<String>)> A list of examples. Each example may be a string, or a list of strings. In case of a list of strings, the strings will be joined by a space character and used as one example.

export(visitor)

The visitable in a visitor pattern. Used for exporting schema.
Parameters:
Name Type Description
visitor Exporter a schema exporter. @see JSONSchemaExporter

getProp(name)

Parameters:
Name Type Description
name String Name of a property
Returns:
- The value associated with name.

getValidatorAndJSONSchema() → {Object}

See compile.
Returns:
Object - contains jsonSchema and assertValid

jsonSchema()

Returns:
- JSON Schema with the schema version keyword at the root level.

lock()

Locks a Todea Schema object from modifications.

max(val)

Set a max property depending on schema type.
Parameters:
Name Type Description
val Integer A non-negative integer for min/max.

min(val)

Set a min property depending on schema type.
Parameters:
Name Type Description
val Integer A non-negative integer for min/max.

optional()

Marks a schema as optional. Schemas are required by default.

readOnly(ropt)

Sets schemas readOnly property.
Parameters:
Name Type Attributes Default Description
r Boolean <optional>
true If the schema value should be readOnly.

title(t)

Sets a title.
Parameters:
Name Type Description
t String The title of the schema.

valueOf()

Returns a JSON Schema. It exists for compatibility with fluent-schema.