Repository F# setup
open Reified
open Reified.Refinements
open Reified.Result
open Reified.Schema.JsonDerivation Attributes
Open Reified.DerivedSchema to use the attributes without suffixes:
open Reified.DerivedSchema
ReifiedDerivedSchemaAttributes are read from F# source at generation time. They do not use runtime reflection. Each generated operation in the table has the same meaning as its linked handwritten Schema DSL equivalent.
Type and construction attributes
| Attribute | Applies to | Short description | Schema DSL equivalent |
|---|---|---|---|
[<DeriveSchema>] |
record | Generate a schema and companion operations for a public wire record. Chain and Version optionally identify a version series. |
schema<'model> { ... } |
[<DeriveUnion>] |
union | Derive the recommended internally tagged union with discriminator type. Fieldless and directly named payload cases may be mixed. |
Schema.union |
[<DeriveUnion "kind">] |
union | Derive the same named-field format with a custom discriminator. | Schema.unionWith |
[<DeriveUnion(Representation = UnionRepresentationKind.Adjacent, PayloadField = "Fields", PayloadStyle = UnionPayloadStyleKind.Positional)>] |
union | Keep an adjacent positional contract such as FSharp.SystemTextJson's default. | Schema.unionWith |
[<DeriveUnion(Representation = UnionRepresentationKind.External, PayloadStyle = UnionPayloadStyleKind.NamedWithUnwrappedSingle, UnwrapFieldless = true)>] |
union | Keep external tagging with named multi-field and unwrapped empty/single-field cases. | Schema.unionWith |
[<SchemaName "wire_name">] |
record field or nullary union case | Override the configured wire name or case tag. | fieldAs "wire_name" _.Field |
[<SchemaConstructor>] |
static member | Call this member with fields in declaration order instead of constructing a record literal. | construct |
Field attributes
| Attribute | Short description | Schema DSL equivalent |
|---|---|---|
[<Pattern "expr">] |
Require text to match a regular expression. | constrain (pattern "expr") |
[<Min n>] |
Set the minimum natural length of text, list, or map. | constrain (minLength n) |
[<Max n>] |
Set the maximum natural length of text, list, or map. | constrain (maxLength n) |
[<Length n>] |
Require an exact natural length. | constrain (length n) |
[<LengthBetween(min, max)>] |
Bound natural length inclusively. | constrain (lengthBetween min max) |
[<Present>] |
Require a string, collection, or optional value to be present/non-empty. | constrain present |
[<Supplied>] |
Require the input object to contain this field key. | mustSupply |
[<Format "name">] |
Attach open format metadata without adding a check. | format (SchemaFormat.create "name") |
[<AtLeast n>] |
Inclusive numeric lower bound (>=). |
constrain (atLeast n) |
[<GreaterThan n>] |
Exclusive numeric lower bound (>). |
constrain (greaterThan n) |
[<AtMost n>] |
Inclusive numeric upper bound (<=). |
constrain (atMost n) |
[<LessThan n>] |
Exclusive numeric upper bound (<). |
constrain (lessThan n) |
[<MultipleOf n>] |
Require a numeric value to be a whole multiple of n. |
constrain (multipleOf n) |
[<Distinct>] |
Require all list elements to be distinct. | constrain distinct |
[<Email>] |
Apply the built-in email constraint to text. | constrain email |
[<Default value>] |
Supply a value when the input key is omitted; invalid on option fields. |
defaultValue value |
Numeric bound and default attributes accept source literals supported by their target field. The generator reads the literal text, preserving decimal precision rather than round-tripping it through reflection.
Example
[<DeriveSchema>]
type Product =
{ [<SchemaName "product_code"; Pattern "^[A-Z0-9]+$"; Present>]
Code: string
[<AtLeast 0; LessThan 1000000>]
Price: decimal
[<Min 1; Distinct>]
Tags: string list
[<Default true>]
Active: bool }
Reified.DerivedSchema.DeriveSchemaAttributeMarks a plain record for schema derivation: schemagen generates its permissive schema. The advice is to put this on wire DTOs — records that carry no invariants of their own. The attributes in this namespace are inert metadata: they are read from source text at generation time, never by runtime reflection.
08-schema_60-derivation_20-attributes.md_page.ProductReified.DerivedSchema.SchemaNameAttributeOverrides the external name of one record field or one nullary union case. Without it, field names follow the generation run's naming policy (camelCase by default) and case tags are the camelCased case name.
Reified.DerivedSchema.PatternAttributeConstrains a text field to the given regular expression.
Reified.DerivedSchema.PresentAttributeRequires a string, collection, or optional field value to be present.
Code: stringstringAn abbreviation for the CLI type . Basic Types
Reified.DerivedSchema.AtLeastAttributeBounds a numeric field's value inclusively from below (>= in the contract grammar). The literal is read from source text, so decimal precision is preserved exactly.
Reified.DerivedSchema.LessThanAttributeBounds a numeric field's value exclusively from above (< in the contract grammar).
Price: decimaldecimalAn abbreviation for the CLI type . Basic Types
Reified.DerivedSchema.MinAttributeBounds the natural length of a text, list, or map field from below.
Reified.DerivedSchema.DistinctAttributeRequires the elements of a list field to be distinct.
Tags: string listlistThe type of immutable singly-linked lists. See the module for further operations related to lists. Use the constructors [] and :: (infix) to create values of this type, or the notation [1; 2; 3]. Use the values in the List module to manipulate values of this type, or pattern match against the values directly. See also F# Language Guide - Lists.
Reified.DerivedSchema.DefaultAttributeSupplies the field's default when the payload omits it. Not valid on optional fields — absence already parses to None.
Active: boolboolAn abbreviation for the CLI type . Basic Types
Multiple constraints are emitted in attribute order and execute like multiple constrain operations in a field block.
Doc comments on records and fields become schema descriptions and generated XML documentation.