Schema‑first CLI to generate config samples (with YAML comments), validate user configs, render a Go template, and patch an existing values.yaml in place using a JSON merge patch.
- Generate sample config from a JSON Schema (authored in YAML or JSON)
- Inserts each property’s
descriptionas a comment above the key - Honors
default → const → first enum → type‑based placeholder - Recurses nested objects/arrays (deterministic key order)
- Inserts each property’s
- Validate a
config.yamlagainst the schema (viagojsonschema) - Render a Go
text/templatewith the config map (helpers:csv,jsonarr) - Patch an existing
values.yamlusing an RFC 7396 JSON merge patch- Atomic, in‑place write by default (with
--backup)
- Atomic, in‑place write by default (with
go mod tidy
make build
# or run without building
go run . --help./bin/valuesctl gen-sample \
--schema ./config.schema.yaml \
--out ./config.sample.yaml./bin/valuesctl patch \
--file ./values.yaml \
--config ./config.yaml \
--template ./template.tmpl \
--schema ./config.schema.yaml \
--validateWrite to a different output file:
./bin/valuesctl patch \
-f ./values.yaml \
-c ./config.yaml \
-t ./template.tmpl \
-o ./values.new.yaml \
--backup=false \
-s ./config.schema.yaml \
--validateThe template runs against a map[string]any loaded from config.yaml with missingkey=error (referencing a missing key fails early). Helpers:
csv– join a slice intoa,b,cjsonarr– render a slice as a JSON array string like["a","b"]
Example:
envVars:
API_BASE_URL: "https://{ .host }/api"
WS_BASE_URL: "wss://{ .host }"
APP_NAME: "{ .appName }"
ENABLE_MODULES: "{ csv .enabledModules }"
ADMIN_EMAIL: "{ .adminEmail }"
- Author schemas in YAML or JSON (Draft‑07 style). The app autodetects format.
- Supported constructs:
type,properties,items,required,enum,const,default,allOf,oneOf,anyOf,additionalProperties. - Validation via
gojsonschema. - Defaults application (opt‑in): fills missing keys only; never overwrites user values.
- Objects: deep fill per property (merge object defaults if configured).
- Arrays: use schema default if array is missing; existing arrays unchanged.
allOf: apply defaults from each subschema in order;oneOf/anyOfnot guessed.
The generator uses yaml.v3 nodes so it can attach each property’s description as a comment above the key at every nesting level.
Precedence per field: default → const → enum[0] → placeholder by type.
- Objects: include all
properties(sorted keys) - Arrays: empty by default (toggle in code to emit one example item)
allOf: shallow‑merge; comments cannot be preserved across composed schemasoneOf / anyOf: first branch is used
Patching uses RFC 7396 JSON merge patch:
- Convert YAML ↔ JSON
- Compute patch from
old→desired - Apply patch
- Convert back to YAML
This preserves fields you didn’t touch.