Goal
The built-in validate() uses a lightweight custom schema format. Many users already have JSON Schema files. We should provide a bridge that converts a (subset of) JSON Schema draft 2020-12 into our internal SchemaNode tree.
Proposed API
import { validate, fromJsonSchema } from 'jsoncraft';
const schema = fromJsonSchema(jsonSchemaDraft2020);
validate(data, schema);
Scope
Support the common keywords: type, required, properties, items, enum, minimum, maximum, minLength, maxLength, pattern, default.
Complex keywords ($ref, oneOf, allOf, conditional subschemas) can come later.
Acceptance
fromJsonSchema() converts a draft-2020-12 schema into SchemaNode
- Round-trip validation matches the behavior of Ajv for the supported subset
Goal
The built-in
validate()uses a lightweight custom schema format. Many users already have JSON Schema files. We should provide a bridge that converts a (subset of) JSON Schema draft 2020-12 into our internalSchemaNodetree.Proposed API
Scope
Support the common keywords:
type,required,properties,items,enum,minimum,maximum,minLength,maxLength,pattern,default.Complex keywords (
$ref,oneOf,allOf, conditional subschemas) can come later.Acceptance
fromJsonSchema()converts a draft-2020-12 schema intoSchemaNode