Header menu logo CodecMapper

Schema Module

Helpers for building explicit schemas and reusing common built-in shapes. This is the main authoring surface for `CodecMapper`. Build a `Schema<'T>` once, then compile it into JSON or XML codecs.

Functions and values

Function or value Description

array inner

Full Usage: array inner

Parameters:
Returns: Schema<'T[]>
Modifiers: inline
Type parameters: 'T

Builds a schema for an array.

inner : Schema<'T>
Returns: Schema<'T[]>

bool

Full Usage: bool

Returns: Schema<bool>

A schema for `bool`.

Returns: Schema<bool>

build builder

Full Usage: build builder

Parameters:
Returns: Schema<'T>
Modifiers: inline
Type parameters: 'T

Closes a fully-applied pipeline and returns the schema for `'T`.

builder : Builder<'T, 'T>
Returns: Schema<'T>

byte

Full Usage: byte

Returns: Schema<byte>

A schema for `byte`.

Returns: Schema<byte>

char

Full Usage: char

Returns: Schema<char>

A schema for `char` backed by a single-character string.

Returns: Schema<char>

collection inner

Full Usage: collection inner

Parameters:
Returns: Schema<ICollection<'T>>
Modifiers: inline
Type parameters: 'T

Builds a schema for `ICollection<'T>`. This preserves the normal array wire shape while interoperating with common mutable collection interfaces from .NET APIs.

inner : Schema<'T>
Returns: Schema<ICollection<'T>>

construct ctor builder

Full Usage: construct ctor builder

Parameters:
    ctor : 'Ctor
    builder : Builder<'T, unit>

Returns: Builder<'T, 'Ctor>
Modifiers: inline
Type parameters: 'Ctor, 'T

Captures the constructor used to rebuild `'T` during decoding.

ctor : 'Ctor
builder : Builder<'T, unit>
Returns: Builder<'T, 'Ctor>

create def

Full Usage: create def

Parameters:
Returns: Schema<'T>
Modifiers: inline
Type parameters: 'T

Creates a schema from a raw structural definition. This is public for advanced integrations, but most callers should prefer the higher-level helpers in this module.

def : SchemaDefinition
Returns: Schema<'T>

dateTime

Full Usage: dateTime

Returns: Schema<DateTime>

A schema for `DateTime` using the round-trippable `"O"` string format.

Returns: Schema<DateTime>

dateTimeOffset

Full Usage: dateTimeOffset

Returns: Schema<DateTimeOffset>

A schema for `DateTimeOffset` using the round-trippable `"O"` string format.

Returns: Schema<DateTimeOffset>

decimal

Full Usage: decimal

Returns: Schema<decimal>

A schema for `decimal`.

Returns: Schema<decimal>

define

Full Usage: define

Returns: Builder<'T, unit>
Modifiers: inline
Type parameters: 'T

Pipeline DSL helpers. The pipeline starts by capturing the curried constructor up front so subsequent field steps only describe the wire layout. We still ask for `'T` explicitly because relying on field-label inference alone becomes brittle as soon as multiple record types share names like `Id` or `Name`. Starts a pipeline schema definition for `'T`.

Returns: Builder<'T, unit>

emptyCollectionAsValue value inner

Full Usage: emptyCollectionAsValue value inner

Parameters:
    value : 'T
    inner : Schema<'T>

Returns: Schema<'T>
Modifiers: inline
Type parameters: 'T

Some config shapes use an explicit empty collection as "use the default collection" rather than as a meaningful distinct value.

value : 'T
inner : Schema<'T>
Returns: Schema<'T>

emptyStringAsNone inner

Full Usage: emptyStringAsNone inner

Parameters:
    inner : Schema<string option>

Returns: Schema<string option>

Empty strings are often used as a legacy stand-in for "not provided". This wrapper keeps that conversion opt-in rather than weakening string option semantics globally.

inner : Schema<string option>
Returns: Schema<string option>

field name getter builder

Full Usage: field name getter builder

Parameters:
    name : string
    getter : 'T -> 'Field
    builder : Builder<'T, ('Field -> 'Next)>

Returns: Builder<'T, 'Next>
Modifiers: inline
Type parameters: 'T, 'Field, 'Next

Adds a field that can be resolved automatically from its type.

name : string
getter : 'T -> 'Field
builder : Builder<'T, ('Field -> 'Next)>
Returns: Builder<'T, 'Next>

fieldWith name getter schema builder

Full Usage: fieldWith name getter schema builder

Parameters:
    name : string
    getter : 'T -> 'Field
    schema : Schema<'Field>
    builder : Builder<'T, ('Field -> 'Next)>

Returns: Builder<'T, 'Next>
Modifiers: inline
Type parameters: 'T, 'Field, 'Next

Adds a field with an explicit nested schema. Use this when the field type needs a custom schema or should not rely on automatic resolution.

name : string
getter : 'T -> 'Field
schema : Schema<'Field>
builder : Builder<'T, ('Field -> 'Next)>
Returns: Builder<'T, 'Next>

float

Full Usage: float

Returns: Schema<float>

A schema for `float`.

Returns: Schema<float>

formatFloat value

Full Usage: formatFloat value

Parameters:
    value : float

Returns: string

Keep the .NET path using round-trip float formatting, but let Fable use the host number string form instead of rejecting the `"R"` specifier.

value : float
Returns: string

guid

Full Usage: guid

Returns: Schema<Guid>

A schema for `Guid` using the round-trippable `"D"` string format. Common domain identity and timestamp types ride on top of the string codec so JSON and XML stay symmetric without extra parser branches.

Returns: Schema<Guid>

int

Full Usage: int

Returns: Schema<int>

A schema for `int`.

Returns: Schema<int>

int16

Full Usage: int16

Returns: Schema<int16>

A schema for `int16`.

Returns: Schema<int16>

int64

Full Usage: int64

Returns: Schema<int64>

A schema for `int64`.

Returns: Schema<int64>

jsonValue

Full Usage: jsonValue

Returns: Schema<JsonValue>

Builds a schema for arbitrary JSON values. This is the explicit fallback for imported contracts that cannot be represented as a deterministic record/array/primitive schema without a separate normalization or validation step.

Returns: Schema<JsonValue>

list inner

Full Usage: list inner

Parameters:
Returns: Schema<'T list>
Modifiers: inline
Type parameters: 'T

Builds a schema for an F# list.

inner : Schema<'T>
Returns: Schema<'T list>

map wrap unwrapFunc inner

Full Usage: map wrap unwrapFunc inner

Parameters:
    wrap : 'U -> 'T
    unwrapFunc : 'T -> 'U
    inner : Schema<'U>

Returns: Schema<'T>
Modifiers: inline
Type parameters: 'U, 'T

Projects an existing schema through total wrap and unwrap functions. Use this when the wire shape is unchanged but the in-memory model uses a wrapper type.

wrap : 'U -> 'T
unwrapFunc : 'T -> 'U
inner : Schema<'U>
Returns: Schema<'T>

missingAsNone inner

Full Usage: missingAsNone inner

Parameters:
Returns: Schema<'T option>
Modifiers: inline
Type parameters: 'T

Config-style payloads sometimes treat absent fields as "no value" instead of as a contract violation. Keep that policy explicit.

inner : Schema<'T option>
Returns: Schema<'T option>

missingAsValue value inner

Full Usage: missingAsValue value inner

Parameters:
    value : 'T
    inner : Schema<'T>

Returns: Schema<'T>
Modifiers: inline
Type parameters: 'T

Config-style payloads sometimes have explicit defaults that should be applied only when a field is absent, not when it is present-but-invalid.

value : 'T
inner : Schema<'T>
Returns: Schema<'T>

nonEmptyList inner

Full Usage: nonEmptyList inner

Parameters:
Returns: Schema<'T list>
Modifiers: inline
Type parameters: 'T

Some wire contracts require at least one item, but keeping that rule in the schema is still clearer than scattering ad hoc list checks elsewhere.

inner : Schema<'T>
Returns: Schema<'T list>

nonEmptyString

Full Usage: nonEmptyString

Returns: Schema<string>

Empty strings are often accidental placeholders rather than meaningful values. This helper keeps that validation explicit and reusable.

Returns: Schema<string>

nullAsValue value inner

Full Usage: nullAsValue value inner

Parameters:
    value : 'T
    inner : Schema<'T>

Returns: Schema<'T>
Modifiers: inline
Type parameters: 'T

Config-style payloads sometimes use explicit `null` as "use the default value" for non-option fields. Keep that policy local.

value : 'T
inner : Schema<'T>
Returns: Schema<'T>

option inner

Full Usage: option inner

Parameters:
Returns: Schema<'T option>
Modifiers: inline
Type parameters: 'T

Builds a schema for an option value. The default semantics are strict: `None` is explicit on the wire, and missing fields still fail unless you add a field-policy wrapper.

inner : Schema<'T>
Returns: Schema<'T option>

positiveInt

Full Usage: positiveInt

Returns: Schema<int>

Positive identifiers and counters are a common wire-level constraint, and `tryMap` keeps that rule opt-in rather than global.

Returns: Schema<int>

readOnlyList inner

Full Usage: readOnlyList inner

Parameters:
Returns: Schema<IReadOnlyList<'T>>
Modifiers: inline
Type parameters: 'T

Builds a schema for `IReadOnlyList<'T>`. Keep the wire form identical to arrays while still allowing .NET-facing APIs to expose read-only collection interfaces.

inner : Schema<'T>
Returns: Schema<IReadOnlyList<'T>>

resizeArray inner

Full Usage: resizeArray inner

Parameters:
Returns: Schema<ResizeArray<'T>>
Modifiers: inline
Type parameters: 'T

Builds a schema for `ResizeArray<'T>` / `List`. .NET interop often surfaces mutable list shapes even when the wire contract is just a homogeneous JSON or XML array.

inner : Schema<'T>
Returns: Schema<ResizeArray<'T>>

resolveSchema t

Full Usage: resolveSchema t

Parameters:
Returns: ISchema

Resolves a built-in schema for a CLR type. This powers automatic field resolution for primitives, F# collections, selected .NET collection interfaces, options, and the common built-in wrapper types.

t : Type
Returns: ISchema

sbyte

Full Usage: sbyte

Returns: Schema<sbyte>

A schema for `sbyte`.

Returns: Schema<sbyte>

string

Full Usage: string

Returns: Schema<string>

A schema for `string`.

Returns: Schema<string>

timeSpan

Full Usage: timeSpan

Returns: Schema<TimeSpan>

A schema for `TimeSpan` using the invariant `"c"` format.

Returns: Schema<TimeSpan>

trimmedString

Full Usage: trimmedString

Returns: Schema<string>

Some contracts normalize surrounding whitespace at the boundary rather than making every caller remember to trim before encode and after decode.

Returns: Schema<string>

tryMap wrap unwrapFunc inner

Full Usage: tryMap wrap unwrapFunc inner

Parameters:
    wrap : 'U -> Result<'T, string>
    unwrapFunc : 'T -> 'U
    inner : Schema<'U>

Returns: Schema<'T>
Modifiers: inline
Type parameters: 'U, 'T

Smart constructors need a way to reject decoded values without forcing callers to smuggle exceptions through plain `map`.

wrap : 'U -> Result<'T, string>
unwrapFunc : 'T -> 'U
inner : Schema<'U>
Returns: Schema<'T>

uint16

Full Usage: uint16

Returns: Schema<uint16>

A schema for `uint16`.

Returns: Schema<uint16>

uint32

Full Usage: uint32

Returns: Schema<uint32>

A schema for `uint32`.

Returns: Schema<uint32>

uint64

Full Usage: uint64

Returns: Schema<uint64>

A schema for `uint64`.

Returns: Schema<uint64>

unwrap s

Full Usage: unwrap s

Parameters:
Returns: ISchema

Exposes the erased schema view for advanced integrations.

s : ISchema
Returns: ISchema

Type something to start searching.