How To Model A Basic Record
Use this pattern when the wire contract is a single flat object and your F# record already matches that shape.
open CodecMapper
open CodecMapper.Schema
type Person = { Id: int; Name: string }
let makePerson id name = { Id = id; Name = name }
let codec =
define<Person>
|> construct makePerson
|> field "id" _.Id
|> field "name" _.Name
|> Json.buildAndCompile
This is the smallest authored schema shape: define the record target, provide the constructor, then map each field explicitly and finish with Json.buildAndCompile.
type Person =
{
Id: int
Name: string
}
Multiple items
val int: value: 'T -> int (requires member op_Explicit)
--------------------
type int = int32
--------------------
type int<'Measure> = int
val int: value: 'T -> int (requires member op_Explicit)
--------------------
type int = int32
--------------------
type int<'Measure> = int
Multiple items
val string: value: 'T -> string
--------------------
type string = System.String
val string: value: 'T -> string
--------------------
type string = System.String
val makePerson: id: int -> name: string -> Person
val id: int
val name: string
val codec: obj
CodecMapper