Use this pattern when one field is itself another authored schema and you want that boundary to stay explicit.
open CodecMapper
type Address = { Street: string; City: string }
let makeAddress street city = { Street = street; City = city }
type Person = { Id: int; Name: string; Home: Address }
let makePerson id name home = { Id = id; Name = name; Home = home }
let addressSchema =
Schema.record makeAddress
|> Schema.field "street" _.Street
|> Schema.field "city" _.City
|> Schema.build
let personSchema =
Schema.record makePerson
|> Schema.field "id" _.Id
|> Schema.field "name" _.Name
|> Schema.fieldWith "home" _.Home addressSchema
|> Schema.buildUse Schema.fieldWith when the child value has its own explicit schema boundary instead of relying on the built-in auto-resolved cases.