Skip to content

Commit

Permalink
Added usage to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitawootten committed Apr 23, 2023
1 parent f977fc7 commit 83408d5
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,36 @@ Keep the Kubernetes `CustomResourceDefinitions` that you rely on day-to-day from

This simple library and CLI application transforms a [`CustomResourceDefinition`](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/) into a [JSON Schema](https://json-schema.org/) for easier editing.

## Usage

### As a standalone CLI application

```bash
$ npx crd2jsonschema crd.yaml > schema.json
```

### In your project

Add `CRD2JsonSchema` to your JavaScript/Typescript application:

```bash
$ npm i crd2jsonschema
```

Call the converter within your project:

```typescript
...
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](https://swagger.io/specification/) to define [the shape of custom objects](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#create-a-customresourcedefinition).
Expand Down

0 comments on commit 83408d5

Please sign in to comment.