...
1exec cue export schema.cue
2cmp stdout expect-stdout-cue
3
4-- frontmatter.toml --
5title = "Definitions"
6description = ""
7
8-- text.md --
9In CUE, schemas are typically written as Definitions.
10A definition is a field which identifier starts with
11`#` or `_#`.
12This tells CUE that they are to be used for validation and should
13not be output as data; it is okay for them to remain unspecified.
14
15A definition also tells CUE the full set of allowed fields.
16In other words, definitions define "closed" structs.
17Including a `...` in struct keeps it open.
18
19-- schema.cue --
20#Conn: {
21 address: string
22 port: int
23 protocol: string
24 // ... // uncomment this to allow any field
25}
26
27lossy: #Conn & {
28 address: "1.2.3.4"
29 port: 8888
30 protocol: "udp"
31 // foo: 2 // uncomment this to get an error
32}
33
34-- expect-stdout-cue --
35{
36 "lossy": {
37 "address": "1.2.3.4",
38 "port": 8888,
39 "protocol": "udp"
40 }
41}
View as plain text