Document<D>A structured container for a single JSON Schema and its associated definitions.
When to use
Use when you need to carry a root schema together with its shared
definitions, or when converting between dialects with the from* and to*
functions.
Details
The schema field holds the root schema without the definitions
collection. Root definitions are stored separately in definitions and
referenced via #/$defs/<name> for Draft-2020-12, #/definitions/<name>
for Draft-07, and #/components/schemas/<name> for OpenAPI 3.1 and
OpenAPI 3.0.
Example (Inspecting a parsed document)
import { JsonSchema } from "effect"
const raw: JsonSchema.JsonSchema = {
type: "string",
$defs: { Trimmed: { type: "string", minLength: 1 } }
}
const doc = JsonSchema.fromSchemaDraft2020_12(raw)
console.log(doc.dialect) // "draft-2020-12"
console.log(doc.schema) // { type: "string" }
console.log(doc.definitions) // { Trimmed: { type: "string", minLength: 1 } }export interface interface Document<D extends Dialect>A structured container for a single JSON Schema and its associated
definitions.
When to use
Use when you need to carry a root schema together with its shared
definitions, or when converting between dialects with the from* and to*
functions.
Details
The schema field holds the root schema without the definitions
collection. Root definitions are stored separately in definitions and
referenced via #/$defs/<name> for Draft-2020-12, #/definitions/<name>
for Draft-07, and #/components/schemas/<name> for OpenAPI 3.1 and
OpenAPI 3.0.
Example (Inspecting a parsed document)
import { JsonSchema } from "effect"
const raw: JsonSchema.JsonSchema = {
type: "string",
$defs: { Trimmed: { type: "string", minLength: 1 } }
}
const doc = JsonSchema.fromSchemaDraft2020_12(raw)
console.log(doc.dialect) // "draft-2020-12"
console.log(doc.schema) // { type: "string" }
console.log(doc.definitions) // { Trimmed: { type: "string", minLength: 1 } }
Document<function (type parameter) D in Document<D extends Dialect>D extends type Dialect =
| "draft-07"
| "draft-2020-12"
| "openapi-3.1"
| "openapi-3.0"
The set of JSON Schema dialects supported by this module.
When to use
Use as the dialect marker for JsonSchema documents when parsing,
converting, or emitting schemas across the supported formats.
Details
Supported values are "draft-07" for JSON Schema Draft-07,
"draft-2020-12" for JSON Schema Draft 2020-12 and the canonical internal
form, "openapi-3.1" for OpenAPI 3.1, and "openapi-3.0" for OpenAPI 3.0.
Dialect> {
readonly Document<D extends Dialect>.dialect: D extends Dialectdialect: function (type parameter) D in Document<D extends Dialect>D
readonly Document<D extends Dialect>.schema: JsonSchemaschema: JsonSchema
readonly Document<D extends Dialect>.definitions: Definitionsdefinitions: Definitions
}