JsonSchemaModule
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; omitted rules are not marked as enforced.
JsonSchema.generateValue runs the same lowering for a standalone value schema — a primitive, a collection, a union,
or a refined field — rather than a record model schema. It returns the same compact JSON Schema Draft 2020-12 document
string as generate; the two names exist so a call site states whether it is exporting a model or a value. Use
generateValue when you hold a value schema without a surrounding record and want its document directly.
Summary
| Name | Signature | Synopsis |
|---|---|---|
| Operations | ||
| generate | JsonSchema.generate schema | Generates a compact JSON Schema document from any completed schema declaration. |
| generateValue | JsonSchema.generateValue schema | Generates a compact JSON Schema document for a standalone value schema. |
Operations
Parameters
| Name | Type | Description |
|---|---|---|
| schema | Schema<'model> | The record, primitive, collection, union, or other completed schema to lower. |
Returns
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":[...]}