Keep the Kubernetes CustomResourceDefinitions
that you rely on day-to-day from driving you mad by generating schemas for them!
This simple library and CLI application transforms a CustomResourceDefinition
into a JSON Schema for easier editing.
$ npx crd2jsonschema crd.yaml > schema.json
Add CRD2JsonSchema
to your JavaScript/Typescript application:
$ npm i crd2jsonschema
Call the converter within your project:
...
import convertCrd, { K8sCrd } from 'crd2jsonschema';
// Load the file
const file = fs.readFileSync('crd.yaml', 'utf-8');
// For Typescript users, validate your CRDs against K8sCrd
const crd = YAML.parse<K8sCrd>(file);
const schema = convertCrd(crd);
Kubernetes CRDs currently use OpenAPIv3 to define the shape of custom objects. Thankfully OpenAPIv3 gets us 95% the way there, as it uses JSON Schema to define the shape of objects.
- Transform simple
CustomResourceDefinitions
- Handle YAML files that contain multiple documents
- Create a GitHub page to store schemas for common CRDs