A command-line tool to generate a JSON Schema from a YAML values.yaml file, optionally merging an overrides file. Useful for Helm chart values and other YAML-based configurations.
- Go 1.23 or later
Clone the repository and build:
git clone https://github.com/mkm29/schemagen.git
cd schemagen
go build -o bin/schemagen main.goAlternatively, install it directly (requires Go modules support):
go install github.com/mkm29/schemagen@latestA Makefile is provided with common development tasks:
make help: Show available commands (default when runningmake).make build: Build the CLI (outputsbin/schemagen).make test: Run tests, generatecover.outandcover.html.make check-coverage: Install and rungo-test-coverageto enforce coverage thresholds defined in.testcoverage.yml.make clean: Remove build artifacts (bin/andschemagen).
Make sure you have GNU Make installed.
Generate a JSON Schema from a values.yaml in the given <context-dir>:
schemagen [flags] <context-dir>
Flags:
-overrides string
path (relative to the context directory) to an overrides YAML file (optional)
-version
print version informationThe tool writes a values.schema.json file in the <context-dir>.
Generate schema from a directory containing values.yaml:
./bin/schemagen charts/mychartGenerate schema merging an override file:
./schemagen -overrides override.yaml charts/mychart- Print version/build information:
./schemagen -versionOutput format:
github.com/mkm29/schemagen@v0.1.1 (commit 9153c14b9ffddeaccba93268a0851d5da0ae8cbf)
Given a values.yaml:
replicaCount: 3
image:
repository: nginx
tag: stable
env:
- name: LOG_LEVEL
value: debugRun:
./bin/schemagen .Produces values.schema.json with contents:
{
"$schema": "http://json-schema.org/schema#",
"type": "object",
"properties": {
"replicaCount": {
"type": "integer",
"default": 3
},
"image": {
"type": "object",
"properties": {
"repository": {
"type": "string",
"default": "nginx"
},
"tag": {
"type": "string",
"default": "stable"
}
},
"default": {}
},
"env": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string",
"default": "LOG_LEVEL"
},
"value": {
"type": "string",
"default": "debug"
}
},
"default": {}
},
"default": []
}
},
"required": ["replicaCount", "image", "env"]
}- Load
values.yamlin the specified directory - Merge an overrides YAML if
-overridesis provided - Recursively infer JSON Schema types and defaults
- Write
values.schema.jsonin the same directory
This project uses GoReleaser to automate builds and releases. Binaries for Linux and macOS (amd64 and arm64) are built when tags (e.g., v0.1.0) are pushed.
-
A GitHub Actions workflow (
.github/workflows/release.yml) runs GoReleaser on push tags and via manual dispatch. -
Note: The release workflow sets
permissions.contents: writeso that theGITHUB_TOKENhas sufficient permissions to create releases. -
To run a local release:
go install github.com/goreleaser/goreleaser@latest goreleaser release --rm-dist
You can also use the Makefile to run tests and check coverage:
make test
make check-coverageTo run the test suite:
go test ./...To generate a coverage report:
go test -coverprofile=coverage.out ./...
go tool cover -func=coverage.outTo view an HTML coverage report:
go tool cover -html=coverage.outContributions are welcome! Feel free to open issues and submit pull requests.