Skip to main content
Version: 1.2.1-beta1.0

Function: compileSchema()

compileSchema(schema): CompiledValidator

Defined in: src/Mnemonic/json-schema.ts:197

Pre-compiles a JsonSchema into a reusable validation function.

Inspects the schema once and builds a specialized closure that eliminates runtime branching for unused keywords, pre-converts required arrays to Sets, recursively pre-compiles nested property and item schemas, and pre-builds primitive Sets for O(1) enum lookups when possible.

Results are cached by schema object identity in a WeakMap, so calling compileSchema with the same schema reference is free after the first call.

Parameters

ParameterTypeDescription
schemaJsonSchemaThe JSON Schema to compile

Returns

CompiledValidator

A compiled validation function