Package: effect
Module: JsonSchema
Parses a raw Draft-07 JSON Schema into a Document<"draft-2020-12">.
When to use
Use when you have a raw JSON Schema object that follows Draft-07 conventions and need the canonical Draft-2020-12 document representation.
Details
This converts Draft-07 tuple syntax (items as array plus
additionalItems) to Draft-2020-12 form (prefixItems plus items),
rewrites #/definitions/... refs to #/$defs/..., and extracts root-level
definitions into the definitions field.
Gotchas
Unsupported keywords, such as if/then/else and $id, are dropped.
Example (Parsing a Draft-07 schema)
import { JsonSchema } from "effect"
const raw: JsonSchema.JsonSchema = {
type: "object",
properties: {
tags: {
type: "array",
items: { type: "string" }
}
}
}
const doc = JsonSchema.fromSchemaDraft07(raw)
console.log(doc.dialect) // "draft-2020-12"
console.log(doc.schema.properties) // { tags: { type: "array", items: { type: "string" } } }
See
fromSchemaDraft2020_12fromSchemaOpenApi3_0toDocumentDraft07Signature
declare const fromSchemaDraft07: (js: JsonSchema) => Document<"draft-2020-12">
Since v4.0.0