# kctrl - generate openAPISchema for helm Chart
###### tags: `kctrl`
## Problem Statement
When a package author wants to generate Carvel package from helm Chart, `pkg release` should be able to read helm's `values.yaml` file and generate the openAPISchema for it and add to the `package.yml` file.
## Observations and findings
Helm doesn't have a very strict way to define a key's comment/description. e.g.
1. [Bitnami Charts](https://github.com/bitnami/charts/blob/master/bitnami/nginx/values.yaml) defines it as @param.<Key_NAME> as the prefix and they are generally placed at the start of each section
2. [OSS MongoDb](https://github.com/mongodb/helm-charts/blob/main/charts/enterprise-operator/values.yaml) defines without key name just before each key.
3. [Official helm documentation](https://github.com/mongodb/helm-charts/blob/main/charts/enterprise-operator/values.yaml) says it should be key name followed by documentation.
4. Some uses `# --` as the prefix.
It becomes very difficult to figure out which variation is being used to define key's comment/description in a helm chart.
## Target Scenario
We have decided to target the scenario as recommended in the official documentation of helm.
## Examples(Helm Chart and their corresponding openAPISchema)
1. Nested Obj
**Input**
```
# image Image details.
image:
# repository Image repository
repository: my-docker-image
# pullPolicy Image Pull Policy
pullPolicy: IfNotPresent
```
**Output**
```
openapi: 3.0.0
properties:
image:
type: object
description: Image details.
properties:
repository:
type: string
description: Image repository
default: my-docker-image
pullPolicy:
type: string
description: Image Pull Policy
default: IfNotPresent
```
2. Plain Obj
**Input**
```
# image Image details.
image: my-docker-image:1.0.0
# name Container name
name: test-container
# boolExample boolean example
boolExample: true
# arrExample Array Example
arrExample:
- arr1
# numExample Number Example
numExample: 2.3
# intExample Integer Example
intExample: 3
```
**Output**
```
openapi: 3.0.0
properties:
image:
type: string
description: Image details.
default: my-docker-image:1.0.0
name:
type: string
description: Container name
default: test-container
boolExample:
type: boolean
description: boolExample boolean example
default: true
arrExample:
type: array
description: arrExample Array Example
items:
type: string
default: arr1
default: []
numExample:
type: number
format: float
description: Number Example
default: 2.3
intExample:
type: integer
description: Integer Example
default: 3
```
## Finalised Approach:
**Option 1**
Use golang `v3.yaml` and `v2.yaml` library and write our own custom logic to generate this.
## Alternate approach:
**Option 2**
Try to use ytt as a library but then we have to write our own custom logic to parse the comment. As by default, ytt understand anything suffixed with these`#@schema/desc` as comments. Moreover ytt exposes a lot of options/functionality and we dont want any of them.
**Option 3**
Generate json schema from yaml something similar to this [lib](https://github.com/karuppiah7890/helm-schema-gen). In this also we have to write our own logic to get the default value and comment. No added advantage from option 2.