Skip to content

A simple utility that converts a Kubernetes CustomResourceDefinition to a JSON Schema

License

Notifications You must be signed in to change notification settings

nikitawootten/crd2jsonSchema

Repository files navigation

Logo CRD2JsonSchema

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.

Usage

As a standalone CLI application

$ npx crd2jsonschema crd.yaml > schema.json

In your project

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);

How does it work?

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.

Road-map

  • Transform simple CustomResourceDefinitions
  • Handle YAML files that contain multiple documents
  • Create a GitHub page to store schemas for common CRDs

About

A simple utility that converts a Kubernetes CustomResourceDefinition to a JSON Schema

Resources

License

Stars

Watchers

Forks

Packages

No packages published