Converts Kubernetes Custom Resource Definitions (CRDs) OpenAPI V3.0 schemas to JSON schema draft 4.
Usage: crd2jsonschema [options] [crd]...
Convert Kubernetes Custom Resource Definitions (CRDs) OpenAPI V3.0 schemas to
JSON schema draft 4. CRDs can be specified as a file path or as a URL.
Options:
-o path Output directory for JSON schema files
-a Create all.json with all references to schemas (intended for
use with yaml language server)
-v Print the version of crd2jsonschema
-h Print this help
Examples:
# convert a single CRD file and print to stdout
crd2jsonschema your-crd.yml
# convert a single CRD from a URL and write as kind_group_version.json to output dir
crd2jsonschema -o output-dir https://example.com/your-crd.yml
# convert multiple CRDs, write kind_group_version.json files to output dir and
# create all.json with all references to schemas
crd2jsonschema -a -o ./output your-crd1.yml your-crd2.yml
crd2jsonschema -a -o ./output ./crds/*.yml
# convert a single CRD and write to output dir
docker run --rm -v $(pwd):/app ghcr.io/tricktron/crd2jsonschema -o output your-crd.yaml
# convert multiple CRDs, write kind_group_version.json files to output dir and
# create all.json with all references to schemas
docker run --rm -v $(pwd):/app ghcr.io/tricktron/crd2jsonschema -a -o output crds/*.crd.yml
Install and run with:
nix profile install github:tricktron/crd2jsonschema
crd2jsonschema -h
or run directly with nix run github:tricktron/crd2jsonschema -- -h
Catch errors in Kubernetes manifests early by validating them against the JSON schema before applying them to the cluster. This shortens the feedback loop during development and can be used in CI/CD pipelines to safeguard against invalid manifests.
The generated JSON schemas can be used with the following tools:
- yaml-language-server
by adding the
all.json
file to theyaml.schemas
setting. See also the this pull request. - datree by contributing schemas to their CRDs-catalog or by manually specifying your generated schemas.
- yq to parse YAML files.
- openapi-schema-to-json-schema to convert OpenAPI V3.0 schemas to JSON schema draft 4.