blob: 02931223aa25de7e907dcf64bcfad68f1a681c11 [file] [log] [blame]
cue export schema.cue
cmp stdout expect-stdout-cue
-- frontmatter.toml --
title = "Definitions"
description = ""
-- text.md --
In CUE, schema are typically written as Definitions,
using a `::` instead of `:`.
This tells CUE that they are to be used for validation and should
not be output as data; it is okay for them to remain unspecified.
A definition also tells CUE the full set of allowed fields.
In other words, definitions define "closed" structs.
Including a `...` in struct keeps it open.
-- schema.cue --
Conn :: {
address: string
port: int
protocol: string
// ... // uncomment this to allow any field
}
lossy: Conn & {
address: "1.2.3.4"
port: 8888
protocol: "udp"
// foo: 2 // uncomment this to get an error
}
-- expect-stdout-cue --
{
"lossy": {
"address": "1.2.3.4",
"port": 8888,
"protocol": "udp"
}
}