Types
YAML Schema supports validation for all YAML data types. This page covers number, integer, boolean, null, and array types. For strings, see Strings. For object validation, see Objects.
Number Types
Number Type
The number type validates both integers and floating-point numbers.
# Schema
type: number
Valid examples:
42
3.14
Invalid examples:
"I'm a string"
Integer Type
The integer type validates whole numbers. Note that 1.0 is considered an integer.
# Schema
type: integer
Valid examples:
42
-1
1.0
Invalid examples:
3.1415926
"42"
Number Constraints
Multiples
# Schema
type: number
multipleOf: 10
Valid examples:
0
10
20
Invalid examples:
23
Range Validation
# Schema
type: number
minimum: 0
exclusiveMaximum: 100
Valid examples:
0
10
99
Invalid examples:
-1
100
101
Note: minimum is inclusive, while exclusiveMaximum is exclusive.
Boolean Type
The boolean type validates true/false values.
# Schema
type: boolean
Valid examples:
true
false
Invalid examples:
"true"
Null Type
The null type validates only null values.
# Schema
type: null
Valid examples:
null
Invalid examples:
false
0
""
Array Type
The array type validates ordered lists of values.
Basic Array Validation
# Schema
type: array
Valid examples:
- 1
- 2
- 3
- 4
- 5
- 3
- different
- types: "of values"
Invalid examples:
Not: "an array"
Array Items
# Schema
type: array
items:
type: number
Valid examples:
- 1
- 2
- 3
- 4
- 5
[]
Invalid examples:
- 1
- 2
- "3"
- 4
- 5
Note: A single non-matching item causes the entire array to be invalid. Empty arrays are always valid.
Tuple Validation with prefixItems
# Schema
type: array
prefixItems:
- type: number
- type: string
- enum:
- Street
- Avenue
- Boulevard
- enum:
- NW
- NE
- SW
- SE
Valid examples:
- 1600
- Pennsylvania
- Avenue
- NW
- 10
- Downing
- Street
- 1600
- Pennsylvania
- Avenue
- NW
- Washington
Invalid examples:
- 24
- Sussex
- Drive
- Palais de l'Élysée
Additional Items
By default, additional items beyond prefixItems are allowed. You can restrict this:
# Schema
type: array
prefixItems:
- type: number
- type: string
items: false
Valid examples:
- 1600
- Pennsylvania
- Avenue
- NW
- 1600
- Pennsylvania
- Avenue
Invalid examples:
- 1600
- Pennsylvania
- Avenue
- NW
- Washington
You can also specify a schema for additional items:
# Schema
type: array
prefixItems:
- type: number
- type: string
items:
type: string
Valid examples:
- 1600
- Pennsylvania
- Avenue
- NW
- Washington
Invalid examples:
- 1600
- Pennsylvania
- Avenue
- NW
- 20500
Contains
The contains keyword requires that at least one item in the array matches the schema:
# Schema
type: array
contains:
type: number
Valid examples:
- life
- universe
- everything
- 42
- 1
- 2
- 3
- 4
- 5
Invalid examples:
- life
- universe
- everything
- forty-two
minItems and maxItems
# Schema
type: array
minItems: 2
Too few elements (including []) fails validation. maxItems rejects arrays longer than the limit; an empty array is always allowed when minItems is not set.
Combined with items:
type: array
minItems: 2
maxItems: 4
items:
type: number
uniqueItems
When uniqueItems is true, no two elements may be equal (including strings). false allows duplicates. Empty and single-element arrays are always valid.
type: array
uniqueItems: true
minContains and maxContains
With contains, minContains (default 1) is the minimum number of elements that must match the contains schema; maxContains caps how many may match.
type: array
contains:
type: number
minContains: 2
At least two numbers are required somewhere in the array.
type: array
contains:
type: number
maxContains: 3
At most three elements may be numbers that satisfy contains.
Setting minContains: 0 means the contains constraint is satisfied even when no element matches (the array may have zero matches).