Skip to main content

Schema Options

Options are used to customize schema behavior during traversal and data processing. For example, the required option marks whether a value is required to show up in the output data.

The Schema API provides a general approach to setting options:


const schema = new Schema('object')
.property('field1', new Schema('string').option('required', true))

but in almost all cases, there is also "dedicated" setter:


const schema = new Schema('object')
.property('field', new Schema('string').required())

const compiledSchema = resolver.compile(schema);

In general, it is better to use the dedicated setters, as they may do extra work such as consistency checking.

A list of key options follows, see the Schema and CompiledSchema API documentation. (Options without documented getters/setters tend to be set automatically or as a side effect of other actions.)

S = Setter(s) in Schema, G = Getter(s) in CompiledSchema

Option NameSGDescription
allowEmptyschema allows empty container values
allowErrorsschema permits processing Error as a value
allowIncrementalschema can have children assigned incrementally (.opaque() is inverse)
allowUndefinedschema permits processing undefined
containerautomatic when properties added; can be set explicitly if needed
deepwalk schema children even if input defines no value
defaultdefault value schema should produce if no input is supplied
implicitoutput value need not be written, it is implicit in the transformed parent
referenceschema value is derived from elsewhere in the hierarchy
requiredthis schema describes a required value
selectionschema is activated if peer selector value matches
selectorschema defines a value that acts as a selector
strictschema does strict validation (.lax() for inverse)
typetype hint for how to treat values (mainly for array[] vs object)⇒{})
unionKeyschema defines a value corresponding to a union key
valuesallowed values this schema accepts (array)

If an option is assigned without a value, it generally implies the value of true. There may be symmetric setters (or getters) that specify the opposite for clarity, e.g. .lax() is the same as .strict(false).

Note: getters that do extra work beyond returning the backing option value typically have a different name. For example, isContainer checks both the option as well as the size of the property map, in case properties were synthesized rather than created using fluent API.

See the CompiledSchema API docs for details.

note

Consider using metadata if you want to add additional data to the schema. The options set is intended for internal use, and should only be extended with new keys if extending the schema system itself.