Skip to content

Composition

Compose provides static methods for deriving new schemas from existing ones. All methods return new schema objects - input schemas are never mutated. The TypeScript types are inferred at compile time; the output is valid JSON Schema at runtime.

Methods

MethodDescription
extendAdd properties to a base schema
pick / omitKeep or remove specific properties
partial / requiredMake all properties optional or required
intersectionCombine schemas with allOf
equivalentDeclare two schemas as semantically equivalent (equivalentClass / equivalentProperty)
discriminatedUnion / narrowoneOf with type discriminator
getDefaultsExtract declared default values

All examples use the bookstore domain. Composed schemas build on each other - see Getting Started for the basics.

  • register - register composed schemas before use
  • instantiate - coerce values through composed schemas
  • materialize - fill defaults through composed schemas

See also

Released under the MIT License.