(
schema: Constraint,
options?: ToJsonSchemaOptions
): JsonSchema.Document<"draft-2020-12">Returns a JSON Schema document using draft 2020-12.
Details
The options parameter controls generation details such as additional
properties and synthesized check descriptions; it does not change the draft
target.
Gotchas
JSON Schema generation is best-effort. Some Effect schema semantics cannot be represented exactly in JSON Schema, and importing an emitted JSON Schema may produce an equivalent approximation rather than the original schema shape.
export function function toJsonSchemaDocument(
schema: Constraint,
options?: ToJsonSchemaOptions
): JsonSchema.Document<"draft-2020-12">
Returns a JSON Schema document using draft 2020-12.
Details
The options parameter controls generation details such as additional
properties and synthesized check descriptions; it does not change the draft
target.
Gotchas
JSON Schema generation is best-effort. Some Effect schema semantics cannot
be represented exactly in JSON Schema, and importing an emitted JSON Schema
may produce an equivalent approximation rather than the original schema
shape.
toJsonSchemaDocument(
schema: Constraint(parameter) schema: {
ast: SchemaAST.AST;
Type: unknown;
Encoded: unknown;
DecodingServices: unknown;
EncodingServices: unknown;
Iso: unknown;
}
schema: Constraint,
options: ToJsonSchemaOptionsoptions?: ToJsonSchemaOptions
): import JsonSchemaJsonSchema.interface Document<D extends JsonSchema.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<"draft-2020-12"> {
const const sd: SchemaRepresentation.Documentconst sd: {
representation: Representation;
references: References;
}
sd = function toRepresentation(
schema: Constraint
): SchemaRepresentation.Document
Derives an intermediate SchemaRepresentation.Document from a schema. This
document is used internally by
toJsonSchemaDocument
and related
functions to produce JSON Schema output.
toRepresentation(schema: Constraint(parameter) schema: {
ast: SchemaAST.AST;
Type: unknown;
Encoded: unknown;
DecodingServices: unknown;
EncodingServices: unknown;
Iso: unknown;
}
schema)
const const jd: JsonSchema.Document<"draft-2020-12">const jd: {
dialect: D;
schema: JsonSchema;
definitions: Definitions;
}
jd = import InternalStandardInternalStandard.function toJsonSchemaDocument(
document: SchemaRepresentation.Document,
options?: Schema.ToJsonSchemaOptions
): JsonSchema.Document<"draft-2020-12">
toJsonSchemaDocument(const sd: SchemaRepresentation.Documentconst sd: {
representation: Representation;
references: References;
}
sd, options: ToJsonSchemaOptionsoptions)
return {
Document<"draft-2020-12">.dialect: "draft-2020-12"dialect: "draft-2020-12",
Document<"draft-2020-12">.schema: JsonSchema.JsonSchemaschema: const jd: JsonSchema.Document<"draft-2020-12">const jd: {
dialect: D;
schema: JsonSchema;
definitions: Definitions;
}
jd.Document<"draft-2020-12">.schema: JsonSchemaschema,
Document<"draft-2020-12">.definitions: JsonSchema.Definitionsdefinitions: const jd: JsonSchema.Document<"draft-2020-12">const jd: {
dialect: D;
schema: JsonSchema;
definitions: Definitions;
}
jd.Document<"draft-2020-12">.definitions: Definitionsdefinitions
}
}