Type system
Type expressions appear in schema property definitions under the type key. Types are inferred for resource files, so explicit type annotations are only needed in schemas. This page covers every type constructor and how they compose.
Primitive types
| Type | Example value |
|---|---|
string | "hello" |
number | 42, 3.14 |
boolean | true, false |
date | "2024-01-15" |
time | "14:30:00" |
datetime | "2024-01-15T14:30" |
properties:
name:
type: string
birth_date:
type: date
active:
type: booleanNullable types
Append ? to any type to make it nullable. The field accepts either the declared type or null. Omitted nullable fields default to null.
type: string?
type: date?
type: list[string]?List types
list[T] is a list where every element has type T.
type: list[string]
type: list[number]
type: list[Task]Dict types
dict[K, V] is a homogeneous mapping from keys of type K to values of type V.
type: dict[string, number]Fixed-key object types
Inline a mapping to define a nested object type:
type:
street:
type: string
city:
type: string
zip:
type: numberUnion types
Use | to combine types. Accepts any member.
type: string | number
type: string | null
type: list[string] | nullParentheses group when needed:
type: (string | number)? # string, number, or null
type: list['a' | 'b' | 'c']A YAML list also works:
type: [string, number]Enum types
A union of string or number literals:
type: 'todo' | 'in_progress' | 'done'
type: 1 | 2 | 3List syntax also works:
type: ['todo', 'in_progress', 'done']String literals must be quoted to distinguish them from type names.
Literal types
A type with exactly one valid value:
type: 1 # must be the number 1
type: "draft" # must be the string "draft"Schema references
Use a schema name as a type to declare a link field. The field expects a fref to a resource conforming to that schema.
type: Person # link to a Person resource
type: Person? # optional link
type: list[Task] # list of links