blob: 1d3ac88bfd720e7d6c189caec77e8c5e0f7ed623 [file] [log] [blame]
cue export schema.cue
cmp stdout expect-stdout-cue
-- frontmatter.toml --
title = "Definitions"
description = ""
-- text.md --
In CUE, schemas are typically written as Definitions.
A definition is a field which identifier starts with
a `#` or `_#`.
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"
}
}