Skip to content

Convert Kuberneted Custom Resources Openapi v3.0 schema to JSON Schema Draft 4

License

Notifications You must be signed in to change notification settings

tricktron/crd2jsonschema

Repository files navigation

CI codecov licence

crd2jsonschema

Converts Kubernetes Custom Resource Definitions (CRDs) OpenAPI V3.0 schemas to JSON schema draft 4.

Usage

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

Installation

Docker

# 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

Nix Flakes

Install and run with:

nix profile install github:tricktron/crd2jsonschema
crd2jsonschema -h

or run directly with nix run github:tricktron/crd2jsonschema -- -h

Use Case

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:

Credits

About

Convert Kuberneted Custom Resources Openapi v3.0 schema to JSON Schema Draft 4

Resources

License

Stars

Watchers

Forks

Packages