Documentation
¶
Overview ¶
Command schemagen is the dev-time companion code generator for the `spec` package. It is invoked ONLY at development time — by `charly task cue-gen` here, and by a CONSUMER repo's own generator task that runs it by module ref (`go run github.com/opencharly/spec/schemagen@<tag> -mode=params -schema=<dir> -pkg=<pkg> -out=<file>`), which is why it lives at the module root rather than under internal/ — one generator, no copied script per repo (opencharly/plugin-builder#10). It never runs at runtime and has two modes:
-mode=params -out=<file> Concatenate schema/*.cue into one file
headed `package spec` + the file-level `@go(spec)`
attribute, and generate the Go types in-process
through schemaparams (CUE Go API).
-mode=vocab -out=<file> Compile the concatenation via the embedded
cuelang.org/go API and emit spec/vocab_gen.go
— the single-source vocabulary lists (kind keywords,
document directives, step keywords, contexts, the
flat #Op verb/modifier field set, and the live-verb
method allowlists).
CONCATENATION CONTRACT (R3): concatSchema replicates EXACTLY the mechanism the runtime uses in charly core (cue_schema.go) `sharedCueSchema` — every schema/*.cue file (its `package schema` clause normalized away by `schemaconcat`), sorted by name, joined with a trailing newline. The runtime reads the files from `//go:embed`; this tool reads them from disk (it runs at dev time with the working tree present). If you change the runtime concatenation order, change it here too — the two MUST stay byte-identical or the generated Go types drift from what the runtime validates.
PARAM-GEN SCOPE (the two modes diverge by INPUT, not by mechanism): the `vocab` mode reads the FULL schema (every schema/*.cue) — it needs #Node's arms (node.cue) to derive KindWords, so its concatenation stays byte-identical to the runtime `sharedCueSchema`. The `params` mode (which feeds the in-process Go generator → the Go param structs) reads the schema MINUS node.cue: it defines the node-disjunction wrappers (#Node/#NodeDoc/#*Arm/#*Value), which the generator degrades to `map[string]any` and which are NOT charly param structs. (The egress validation schemas moved to candy/plugin-egress in M16, so they no longer live here to exclude.) The entity defs (#Box/#Deploy/#Op/#Vm/…) do not reference node.cue, so the exclusion is compile-clean. Both modes share the ONE concatSchema helper (R3); only the file filter differs.