next: Definitions

Duplicates

Constraints specify what values are allowed. To CUE they are just values like anything else, but conceptually they can be explained as something in between types and concrete values.

Constraints can be used to validate values of concrete instances. They can be applied to CUE data, or directly to YAML or JSON.

But constraints can also reduce boilerplate. If a constraint defines a concrete value, there is no need to specify it in values to which this constraint applies.

check.cue

schema: {
name:  string
age:   int
human: true // always true
}

viola: schema
viola: {
name: "Viola"
age:  38
}

\$ cue eval check.cue

schema: {
name:  string
age:   int
human: true
}
viola: {
name:  "Viola"
age:   38
human: true
}