JSON schema is partially implemented in this tool. It uses line comments to add annotations for the schema because head comments are frequently used by humans and tools like helm-docs. Multiple annotations can be added to a single line sepparated by semi-colon. For example:
nameOverride: "myapp" # @schema maxLength:10;patter:^[a-z]+$
This will generate following schema:
"nameOverride": {
"maxLength": 10,
"type": "string"
}
The following annotations are supported:
The type
keyword is used to restrict a value to a specific primitive type. There are several possible values for type
:
string
number
integer
boolean
object
array
null
Default behaviour returns always a string unless annotation is used. In that case, it returns array of strings. Useful for keys without any value declared for documentation purposes. section 6.1.1
# -- (int) replica count
replicaCount: # @schema type:[integer, null]
"replicaCount": {
"type": [
"integer",
"null"
]
}
Another way to use this is to define type when using anchors and aliases in yaml. See discussion #28 for more details.
app: &app
settings:
namespace:
- *app # @schema type:[string]
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": {
"app": {
"properties": {
"settings": {
"properties": {
"namespace": {
"items": {
"type": [
"string"
]
},
"type": "array"
}
},
"type": "object"
}
},
"type": "object"
}
},
"type": "object"
}
Always returns array of strings. Special case is null
where instead of string, it is treated as valid inpput type. section 6.1.2
service: ClusterIP # @schema enum:[ClusterIP, LoadBalancer, null]
"service": {
"enum": [
"ClusterIP",
"LoadBalancer",
null
],
"type": "string"
}
Non-negative integer. section 6.3.1
nameOverride: "myapp" # @schema maxLength:10
This will generate following schema:
"nameOverride": {
"maxLength": 10,
"type": "string"
}
Non-negative integer. section 6.3.1
nameOverride: "myapp" # @schema minLength:3
This will generate following schema:
"nameOverride": {
"minLength": 3,
"type": "string"
}
String that is valid regular expression, according to the ECMA-262 regular expression dialect. section 6.3.3
nameOverride: "myapp" # @schema patter:^[a-z]+$
This will generate following schema:
"nameOverride": {
"type": "string"
}
Number greater than 0
. section 6.2.1
replicas: 2 # @schema multipleOf:2
"replicas": {
"multipleOf": 2,
"type": "integer"
}
Number. section 6.2.2
replicas: 2 # @schema maximum:10
"replicas": {
"maximum": 10,
"type": "integer"
}
Number. section 6.2.4
replicas: 5 # @schema minimum:2
"replicas": {
"minimum": 2,
"type": "integer"
}
Non-negative integer. section 6.4.1
dummyList: # @schema maxItems:5
- "item1"
- "item2"
- "item3"
"dummyList": {
"items": {
"type": "string"
},
"maxItems": 5,
"type": "array"
}
Non-negative integer. section 6.4.2
dummyList: # @schema minItems:2
- "item1"
- "item2"
- "item3"
"dummyList": {
"items": {
"type": "string"
},
"minItems": 2,
"type": "array"
}
Boolean. section 6.4.3
dummyList: # @schema uniqueItems:true
- "item1"
- "item2"
- "item3"
"dummyList": {
"items": {
"type": "string"
},
"type": "array",
"uniqueItems": true
}
Non-negative integer. section 6.5.1
nodeSelector: # @schema maxProperties:10
kubernetes.io/hostname: "my-node"
"nodeSelector": {
"maxProperties": 10,
"properties": {
"kubernetes.io/hostname": {
"type": "string"
}
},
"type": "object"
}
Non-negative integer. section 6.5.2
nodeSelector: # @schema minProperties:1
kubernetes.io/hostname: "my-node"
"nodeSelector": {
"minProperties": 1,
"properties": {
"kubernetes.io/hostname": {
"type": "string"
}
},
"type": "object"
}
Array of unique strings appened to the parent node. section 6.5.3
image:
repository: "nginx" # @schema required:true
tag: "latest" # @schema required:true
imagePullPolicy: "IfNotPresent"
"image": {
"properties": {
"imagePullPolicy": {
"type": "string"
},
"repository": {
"type": "string"
},
"tag": {
"type": "string"
}
},
"required": [
"repository",
"tag"
],
"type": "object"
}
String. section 9.1
fullnameOverride: bar # @schema title: My title
"fullnameOverride": {
"title": "My title",
"type": "string"
},
Boolean. section 9.4
image:
tag: latest # @schema readOnly: true
"image": {
"properties": {
"tag": {
"readOnly": true,
"type": "string"
}
},
"type": "object"
}