JsonSchemaModule

PackageReified.Schema

JsonSchema

JsonSchema.generate publishes a schema as JSON Schema Draft 2020-12. Field names, required properties, nested shapes, union tags, and portable interpreted constraints come from the same declaration used by parsing and JSON codecs.

Only rules the target can enforce are lowered to JSON Schema keywords. Runtime-only or non-portable constraints remain visible as prose and x-reified-runtime-constraints; generation never claims that another tool enforces an omitted rule.

Summary

NameSignatureSynopsis
generateJsonSchema.generate schemaGenerates a compact JSON Schema document from any completed schema declaration.
generateValueJsonSchema.generateValue schemaGenerates a compact JSON Schema document for a standalone value schema.

generate

JsonSchema.generate schema
Member
Generates a compact JSON Schema document from any completed schema declaration.

Parameters

NameTypeDescription
schemaSchema<'model>The record, primitive, collection, union, or other completed schema to lower.

Returns

string

Verification Examples

open Reified.SchemaDSL
open Reified.ConstraintDSL

type Customer = { Name: string; Email: string }
let customerSchema =
    schema<Customer> {
        field _.Name { constrain present }
        field _.Email { constraints [ present; email ] }
        construct (fun name email -> { Name = name; Email = email })
    }

let document = JsonSchema.generate customerSchema
// {"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{...},"required":[...]}

generateValue

JsonSchema.generateValue schema
Member
Generates a compact JSON Schema document for a standalone value schema.

Parameters

NameTypeDescription
schemaSchema<'value>The value schema to lower.

Returns

string