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
allowEmpty✓schema allows empty container values
allowErrorsschema permits processing Error as a value
allowIncremental✓✓schema can have children assigned incrementally (.opaque() is inverse)
allowUndefinedschema permits processing undefined
container✓automatic when properties added; can be set explicitly if needed
deep✓✓walk schema children even if input defines no value
default✓✓default value schema should produce if no input is supplied
implicit✓✓output value need not be written, it is implicit in the transformed parent
reference✓schema value is derived from elsewhere in the hierarchy
required✓✓this schema describes a required value
selection✓✓schema is activated if peer selector value matches
selector✓✓schema defines a value that acts as a selector
strict✓✓schema does strict validation (.lax() for inverse)
typetype hint for how to treat values (mainly for array⇒[] vs object)⇒{})
unionKey✓✓schema defines a value corresponding to a union key
values✓✓allowed 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.