schema
Creates a schema wrapper that provides validation and type inference from a JSON Schema definition.Parameters
JSONSchemaDefinition
required
JSON Schema definition object with
$id propertyAjv
default:"DEFAULT_AJV"
Custom AJV validator instance. Defaults to the built-in validator with
coerceTypes: trueReturns
Returns aSchemaWrapper<S> instance with the following members:
<T>(data: T) => Promise<T>
Validates data against the schema. Returns validated (possibly coerced) data or throws
BadRequest errorRecord<string, JSONSchema>
The schema’s property definitions
readonly string[]
Array of required property names
JSONSchemaDefinition
The original schema definition
FromSchema<S>
Type inference helper (TypeScript only). Use with
Infer<typeof schema> to extract the inferred typeTypes
JSONSchemaDefinition
Extends standard JSON Schema with required$id property:
Validator
A validation function type:Infer
Extract the TypeScript type from a schema:Combine
Combine a schema type with additional properties:SchemaWrapper
The class returned byschema() that wraps a JSON Schema definition.
validate
Validates and coerces data according to the schema:any
required
Data to validate
Promise<T> - Validated and coerced data
Throws: BadRequest - If validation fails
toJSON
Returns the underlying schema definition:DEFAULT_AJV
The default AJV instance used by schemas:addFormats
Add format validators to an AJV instance:Parameters
Ajv
required
AJV instance to add formats to
FormatName[] | FormatsPluginOptions
Array of format names or configuration object